Ruby on rails 卫兵通过了我的RSpec测试
我已经设置了guard following,并有意编写了一个测试(在联系人页面标题上),所以它失败了。但警卫/RSpec告诉我它通过了,我不知道发生了什么。这是我的Ruby on rails 卫兵通过了我的RSpec测试,ruby-on-rails,ruby,rspec,tdd,guard,Ruby On Rails,Ruby,Rspec,Tdd,Guard,我已经设置了guard following,并有意编写了一个测试(在联系人页面标题上),所以它失败了。但警卫/RSpec告诉我它通过了,我不知道发生了什么。这是我的静态页面\u spec.rb文件: require 'spec_helper' describe "Static pages" do describe "Home page" do it "should have the content 'Welcome to the PWr App'" do visit
静态页面\u spec.rb
文件:
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Welcome to the PWr App'" do
visit '/static_pages/home'
expect(page).to have_content('Welcome to the PWr App')
end
it "should have the title 'Home'" do
visit '/static_pages/home'
expect(page).to have_title("PWr | Home")
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have title 'Help'" do
visit '/static_pages/help'
expect(page).to have_title("PWr | Help")
end
end
describe "About page" do
it "should have the content 'About me'" do
visit '/static_pages/about'
expect(page).to have_content('About Me')
end
it "should have title 'About Me'" do
visit '/static_pages/about'
expect(page).to have_title("PWr | About")
end
end
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
end
it "should have title 'Contact'" do
visit '/static_pages/contact' do
expect(page).to have_title("FAIL")
end
end
end
end
这是我的contact.html.erb
:
<% provide(:title, 'Contact') %>
<h1>Contact</h1>
<p1>
If you need to contact me just call the number below: </br>
+48 737823884
</p>
如您所见,在靠近末尾的spec文件中,我有
expect(第页)。要有标题(“FAIL”)
,在联系人页面html/erb中,我显然有
,但测试通过了。为什么会这样?我做错了什么 问题在于,您正在将您的期望作为一个块传递给访问方法-即注意额外的do end
。我不相信visit
会使用块,所以基本上会忽略一点代码
it "should have title 'Contact'" do
visit '/static_pages/contact' do
expect(page).to have_title("FAIL")
end
end
如果删除块,则等级库的行为应符合预期
it "should have title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("FAIL")
end
问题是,您正在将期望作为一个块传递给visit方法,即注意额外的
do end
。我不相信visit
会使用块,所以基本上会忽略一点代码
it "should have title 'Contact'" do
visit '/static_pages/contact' do
expect(page).to have_title("FAIL")
end
end
如果删除块,则等级库的行为应符合预期
it "should have title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("FAIL")
end
问题是,您正在将期望作为一个块传递给visit方法,即注意额外的
do end
。我不相信visit
会使用块,所以基本上会忽略一点代码
it "should have title 'Contact'" do
visit '/static_pages/contact' do
expect(page).to have_title("FAIL")
end
end
如果删除块,则等级库的行为应符合预期
it "should have title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("FAIL")
end
问题是,您正在将期望作为一个块传递给visit方法,即注意额外的
do end
。我不相信visit
会使用块,所以基本上会忽略一点代码
it "should have title 'Contact'" do
visit '/static_pages/contact' do
expect(page).to have_title("FAIL")
end
end
如果删除块,则等级库的行为应符合预期
it "should have title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("FAIL")
end