我正在使用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