2012-04-21 56 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 
相關問題