Rspec test should pass but fails

前端 未结 4 1303
独厮守ぢ
独厮守ぢ 2021-01-14 16:59

I have this test from michael hartl book:

require \'spec_helper\'
  describe \"Static pages\" do
    let(:base_title) { \"Ruby on Rails Tutorial Sample App\"         


        
相关标签:
4条回答
  • 2021-01-14 17:06

    Using capubara 2.0 you should use

    page.should have_title("The title")
    

    But in aint work if you dont add

    <style type="text/css">head, head title { display: block }</style>
    

    To your application.html

    page.title # => "The title"
    page.has_title?("The title") # => true
    page.should have_title("The title")
    
    0 讨论(0)
  • 2021-01-14 17:10

    I've been using the following and they have been posting green. I dropped have_selector and went with have_title.

    it { should have_title( full_title('Sign up') ) }

    -- and --

    it { should have_title(user.name) }

    This is with capybara 2.2.0.

    0 讨论(0)
  • 2021-01-14 17:19

    For the time being, you should do what @dimuch suggests and make sure you specify the same Capybara version Michael Hartl uses in the tutorial (1.1.2).

    If you want to upgrade to Capybara 2.0 in the future and keep your tests for titles, have a look at this StackOverflow answer for a guide to creating a RSpec matcher that will do what you're expecting.

    0 讨论(0)
  • 2021-01-14 17:28

    Make sure you're using capybara 1.1.2 in your Gemfile. Starting from 2.0 capybara does not works for title testing (https://github.com/jnicklas/capybara/issues/844)

    ...
    group :test do
      gem 'capybara', '1.1.2'
    end
    
    0 讨论(0)
提交回复
热议问题