我正在使用rspec来验证页面中是否存在字符串。我是新来的铁轨和以下教程http://ruby.railstutorial.org/chapters/static-pages#top 有什么我失踪?即使条件满足,rspec也会显示失败
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
看起来像'visit'是未定义的。你在你的gemfile中使用Rspec和Capybara? – Michal