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 6573161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:05:52+00:00 2026-05-25T15:05:52+00:00

Capybara is confusing me. If I use Capybara in combination with Ruby on Rails

  • 0

Capybara is confusing me. If I use Capybara in combination with Ruby on Rails 3 and RSpec 2, then in RSpec request tests, the following matcher works:

response.body.should have_selector "div.some_class"

The response object has the class ActionDispatch::TestResponse. But the following line, which should work officially, does not work:

page.should have_selector "div.some_class"

The page object has the class Capybara::Session. In which cases do you have to use the response.body object and when do you have to use a page object ?

  • 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-05-25T15:05:53+00:00Added an answer on May 25, 2026 at 3:05 pm

    So I just ran into similar, and this is I think what’s going on:

    It depends on code you didn’t include here of how you visit the page. I’m writing an rspec request spec.

    If I retrieve the page with rspec’s own:

    get '/some/path'
    

    then response.body.should have_selector works as you say, but page.should does not.

    To make Capybara ‘page’ work (and to make Capybara interactions like click_button or fill_in work), instead of retrieving with rspec’s ‘get’, you need to retrieve with Capybara’s ‘visit’:

    visit '/some/path'
    page.should have_selector("works")
    

    ‘page’, a capybara method, only gets set when using ‘visit’, a capybara method.

    This does get confusing, all the mixing and matching of different libraries involved in rails testing.

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

Sidebar

Related Questions

I am using Capybara in combination with rspec for integration testing of rails apps.
Using Capybara with Rails 3, Rspec and Cucumber, When I use the select statement,
I am using Ruby on Rails with Cucumber and Capybara. How would I go
I am currently trying to use cucumber together with capybara for some integration tests
I'm writing some automated tests using Capybara/RSpec, I choose/configure the driver by using this
I am using Capybara for rails integration tests. When it comes to AJAX requests,
In using capybara and selenium to run integration tests in rails, if an exception
Normally I use the rails dev server at port 3000. Capybara/Cucumber uses Capybara.server_port =
I'm trying to use Capybara + Rspec to test a Sinatra app, and I'm
I'm currently building tests using Capybara/Rails, and want to know the most reliable/standard way

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.