我正在使用 rspec 来验证页面中是否存在字符串。我是 Rails 的新手并遵循教程http://ruby.railstutorial.org/chapters/static-pages#top 有什么我遗漏的吗?
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
page.should have_content('Sample App')
end
end
end
在我的主页 app/views/static_pages/home.html.erb 我有以下代码。
<h1>Sample App</h1>
我用来验证条件的命令。
bundle exec rspec spec/requests/static_pages_spec.rb
测试失败不知道为什么。
←[31mF←[0m
Failures:
1) Static pages Home page should have the content 'Sample App'
←[31mFailure/Error:←[0m ←[31mvisit '/static_pages/home'←[0m
←[31mNoMethodError←[0m:
←[31mundefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::
Nested_1:0x4067a60>←[0m
←[36m # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top(required)>'←[0m
Finished in 0.023 seconds
←[31m1 example, 1 failure←[0m
Failed examples:
←[31mrspec ./spec/requests/static_pages_spec.rb:7←[0m ←[36m# Static pages Home page should have the content 'Sample App'←[0m
Randomized with seed 44188