찾다

 >  Q&A  >  본문

ruby - Rails Rspec测试报WrongScopeError错误

最近在跟着Ruby on Rails教程一书学习,在书中第三章建立第一个测试的部分遇到了问题,无法解决,求指点.

describe "Static pages" do
 context "Home page" do
    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(response).to have_content('Sample App')
    end
  end
end

运行

bundle exec rspec spec/requests/static_pages_spec.rb

后出现提示

 1) Static pages Home page should have the content 'Sample App'
     Failure/Error:
       raise WrongScopeError,
             "`#{name}` is not available from within an example (e.g. an " \
             "`it` block) or from constructs that run in the scope of an " \
             "example (e.g. `before`, `let`, etc). It is only available " \
             "on an example group (e.g. a `describe` or `context` block)."
     
       `example` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
     # /home/xiao/.rvm/gems/ruby-2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'

Finished in 0.00071 seconds (files took 0.4267 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:15 # Static pages Home page should have the content 'Sample App'

而无法通过测试,请问报错的提示该如何解决,使测试通过?

世界只因有你世界只因有你2771일 전710

모든 응답(0)나는 대답할 것이다

답장 없음
  • 취소회신하다