This is from the Ruby on Rails tutorial by Michael Hartl 2nd edition. The third (and currently latest) version is not tested with RSpec, so I decided to use this book.
I read the user workarounds and know that there are different ways to write a test so that it works, but I want to use has_selector so that the code is consistent. Any explanation / advice would be very helpful. I do not understand why below the test passes for the h1 element and not the title element:
spec.rb:
describe "Static pages" do describe "Home page" do it "should have the h1 'Sample App'" do visit '/static_pages/home' expect(page).to have_selector('h1', :text => 'Sample App') end it "should have the title 'Home'" do visit '/static_pages/home' expect(page).to have_selector('title', :text => "Ruby on Rails Tutorial Sample App | Home") end end
home.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Ruby on Rails Tutorial Sample App | Home</title> </head> <body> <h1>Sample App</h1> </body> </html>
source share