2012-04-21 76 views
1

我正在使用rails。我使用以下命令执行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 

回答

3

我已经解决了这个问题。如果我使用webrat和水豚,那么我看不到适当的结果。因此,我必须从Gemfile中删除gem'webrat',并输入捆绑包更新并使用以下命令并解决问题!

bundle exec rspec spec/requests/test_pages_spec.rb 
相关问题