简体   繁体   中英

Test title with rspec in rails

Starting up with this:

it "doit avoir le bon titre" do
  get 'home'
  response.should have_selector("title", :content => "Simple App du Tutoriel Ruby on Rails | Accueil")
end

I ended up with that because I'm not on the same version of rspec or rails than the tutorial I'm following:

it "doit avoir le bon titre" do
    get 'home'
    expect(response).to have_selector("title", :text => "Simple App du Tutoriel Ruby on Rails | Accueil")
end

And now it's telling me this

Failure/Error: expect(response).to have_selector("title", :text => "Simple App du Tutoriel Ruby on Rails | Accueil")
       expected to find css "title" with text "Simple App du Tutoriel Ruby on Rails | Accueil" but there were no matches

Why is it talking about CSS when all I want to do is validate the title? Am I doing it right considering I wanna do what the first sample of code is doing?

Obviously not because I have an error but what am I doing wrong?

Thanks.

The right syntax was:

it "doit avoir le bon titre" do
  get :home
  expect(response.body).to have_title('Simple App du Tutoriel Ruby on Rails | Accueil')
end

Partly solved thanks to Siekfried and his link: How can I test the page title with Capybara 2.0?

Have you tryed :

    it "doit avoir le bon titre" do
      get :home
      expect(response.body).to include('<title>My Title</title>')
    end
  end

??

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM