我正在使用rails。我使用以下命令执行ruby脚本。它给出了一个错误。什么会有问题?如果我删除“page.should have_content('演示应用')”,那么它可以正常工作!
bundle exec rspec spec/requests/test_pages_spec.rb
Failures:
1) Test pages Home page should have the content 'Demo App'
Failure/Error: page.should have_content('Demo App')
NameError:
undefined local variable or method `page' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa60d538>
# ./spec/requests/test_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.27788 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/requests/test_pages_spec.rb:7 # Test pages Home page should have the content 'Demo App'
test_pages_spec.rb如下:
require 'spec_helper'
describe "Test pages" do
describe "Home page" do
it "should have the content 'Demo App'" do
visit '/test_pages/home'
page.should have_content('Demo App')
end
end
end
答案 0 :(得分:3)
我已经解决了这个问题。如果我使用webrat和capybara,那么我看不到结果。所以我必须从Gemfile中删除 gem'webrat'并输入 bundle update 并使用以下命令解决问题!
bundle exec rspec spec/requests/test_pages_spec.rb