1

我正在使用导轨。我使用以下命令执行 ruby​​ 脚本。它给出了一个错误。会有什么问题?如果我删除“page.should have_content('Demo App')”,那么它可以正常工作!

 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
4

1 回答 1

3

我已经解决了这个问题。如果我同时使用 webrat 和 capybara,那么我看不到正确的结果。所以我必须从 Gemfile 中删除gem 'webrat'并输入bundle update并使用以下命令,问题就解决了!

bundle exec rspec spec/requests/test_pages_spec.rb
于 2012-04-22T08:52:47.383 回答