Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:21:01+00:00 2026-06-13T12:21:01+00:00

I want to write a test using Rspec and Capybara . I have a

  • 0

I want to write a test using Rspec and Capybara.

I have a Post model and I want to add a draft attribute to it. If the user checks that field the post is saved as draft (draft = true). Only posts that have he attribute draft = false will show in the post index page. Posts with draft = true will only show in the page of the user who created that post.

I’ve never made a Rspec + Capybara test in my life. So I was wondering if someone could tell me how to start or give me an example.
Thanks in advance!

schema.rb:

 create_table "posts", :force => true do |t|
    t.string   "title"
    t.string   "content"
    t.integer  "user_id"
    t.datetime "created_at",                               :null => false
    t.datetime "updated_at",                               :null => false
    t.integer  "comments_count",        :default => 0,     :null => false
    t.datetime "published_at"
    t.boolean  "draft",                 :default => false
  end

(By the way, do I need to post the model, controller or view pages?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:21:02+00:00Added an answer on June 13, 2026 at 12:21 pm

    To add on to new2ruby’s answer you can also use the Feature/Scenario aliases provided by capybara in your integration tests.

    I find it reads nicely:

    require 'spec_helper'
    
    feature 'Visitor views posts' do
        scenario 'shows completed posts' do 
            post = FactoryGirl.create(post)
            visit posts_path
    
            page.should have_content(post.title)
        end
    
        scenario 'does not show drafts' do
            draft = FactoryGirl.create(draft)
            visit posts_path
    
            page.should_not have_content(draft.title)
        end
    end
    

    I recently wrote a “getting started” blog post on using RSpec with Capybara for integration tests. Let me know if you have any questions on getting your codebase set up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using RSpec/Capybara as my test suite. I have some javascript that dynamically appends
Using Nunit, I want to be able to write a test fixture that will
I have a set of Happstack.State MACID methods that I want to test using
I want to write test that verifies mappings in castle windsor. I am using
How can I write an Rspec test for the following? Using TDD, I want
I want to write a unit test for a Django manage.py command that does
I want to write an integration test for a library that handles streamed http
This is a function that I want to write a unit test for: public
Greetings, I want to write a unit test to make sure that our web
I want to write a unit test that performs HTTP requests directly (instead of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.