1
votes

I'm currently writing fairly simple test case(still learning). I'm asserting whether about page has about h1.

This is my test :

describe "about verification page" do
  before { visit about_path }
  it { should have_selector('h1', text: 'About') }
end

My test fails with this reason :

Failure/Error: it { should have_selector('h1', text: 'About') }
expected #has_selector?("h1", {:text=>"About"}) to return true, got false

But when I go to my about page and type $('h1') I get About and I can see the text in browser.

What am I doing wrong with this? Or how can I get a value of h1 so I can print it and see what am I actually getting?

2
Could you post your view code?kddeisz

2 Answers

2
votes

When you use it in one line flavor, you need to have a subject otherwise Rspec won't know what is the assertion.

Either of the following will work.

One line style

describe "about verification page" do
  before { visit about_path }
  subject { page }
  it { should have_selector('h1', text: 'About') }
end

Normal style

describe "about verification page" do
  before { visit about_path }

  it "should have selector h1" do
    expect(page).to have_selector('h1', text: 'about')
  end
end
0
votes

or

describe "about verification page" do
  before { visit about_path }
  it 'works' do
    page.should have_selector('h1', text: 'About') 
  end
end