我目前正在编写相当简单的测试用例(仍在学习)。我断言关于页面是否有关于h1。
这是我的测试:
describe "about verification page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
end
我的测试因此而失败:
Failure/Error: it { should have_selector('h1', text: 'About') }
expected #has_selector?("h1", {:text=>"About"}) to return true, got false
但是当我转到我的关于页面并输入$('h1')
时,我得到了About
,我可以在浏览器中看到该文字。
我做错了什么?或者我如何获得h1
的值,以便我可以打印它,看看我到底得到了什么?
答案 0 :(得分:2)
当你在一行品味中使用it
时,你需要有一个主题,否则Rspec将不知道什么是断言。
以下任何一种都可以使用。
一种线型
describe "about verification page" do
before { visit about_path }
subject { page }
it { should have_selector('h1', text: 'About') }
end
正常风格
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
答案 1 :(得分:0)
或
describe "about verification page" do
before { visit about_path }
it 'works' do
page.should have_selector('h1', text: 'About')
end
end