RSpec2 and Capybara

后端 未结 2 1331
长发绾君心
长发绾君心 2020-12-09 12:21

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:

respon         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-09 12:39

    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.

提交回复
热议问题