首页 文章

Rails:为什么RSpec会崩溃我的被覆盖的Devise控制器请求规范?

提问于
浏览
0

Update: 哦,好悲伤,这是一个糟糕的合并之后的红鲱鱼 . 在某个地方,以下内容从清除spec / spechelper.rb中删除

Dir["#{Rails.root}/app/**/*.rb"].each {|f| load f}

现在这已经恢复,一切都在恢复 . 我怀疑它只是加载平面目录,而不是嵌套目录,使它看起来像命名空间问题 .

(我不能回答我自己的问题,因为这是一个新帐户,我没有代表)


原始问题:

我的大多数RSpec / Capybara测试工作正常,但我有一个测试只是试图访问一个路径爆炸,我坚持调试 . 我怀疑它知道如何解决这个问题;任何帮助感激不尽 .

整个测试是:

require 'spec_helper'
describe 'Registrations' do
  context 'when debugging the blocking issue' do
    it 'this minimal test should pass' do
      visit new_user_registration_path
    end
  end
end

错误消息是:

$ bin / rspec spec / requests / users / registrations_spec.rb失败:1)用户::调试阻塞问题时注册此最小测试应通过失败/错误:访问new_user_registration_path LoadError:预期的app / controllers / users / registrations_controller.rb定义Users :: RegistrationsController# . / spec / requests / users / registrations_spec.rb:10:in`block(3 levels)in'

所以错误是 Expected users/registrations_controller.rb to define Users::RegistrationsController ,这没什么帮助!

控制器是一个重写的Devise控制器,它看起来像:

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    super
    # My extra code here
  end
end

我的路线重定向设计了一点:

devise_for :users, :controllers => { :registrations => 'users/registrations' } do
  get '/users/sign_out' => 'devise/sessions#destroy'
end

我完全坚持试图找到'预期的foo.rb定义Foo'错误的根本原因';我无法深入了解导致我的问题的原因 .

你接下来要做什么调试呢?


大卫建议回溯可能会有所帮助;据我所见,我没有阻止加载的错误,看起来对我(但我是一个rails noob)像所有ActiveSupport块一样 . 这是感兴趣的:

1) Users::Registrations when debugging the blocking issue this minimal test should pass
     Failure/Error: visit new_user_registration_path

     LoadError:
       Expected app/controllers/users/registrations_controller.rb to define Users::RegistrationsController
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:490:in `load_missing_constant'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:181:in `block in const_missing'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `each'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `const_missing'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/inflector/methods.rb:124:in `block in constantize'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/inflector/methods.rb:123:in `each'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/inflector/methods.rb:123:in `constantize'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:528:in `block in initialize'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:550:in `yield'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:550:in `default'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:550:in `[]'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:61:in `controller_reference'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:46:in `controller'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:25:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/routing/mapper.rb:41:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:110:in `optimized_each'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:531:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/sass-3.1.12/lib/sass/plugin/rack.rb:54:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/warden-1.1.0/lib/warden/manager.rb:35:in `block in call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/warden-1.1.0/lib/warden/manager.rb:34:in `catch'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/warden-1.1.0/lib/warden/manager.rb:34:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/etag.rb:23:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/conditionalget.rb:25:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/head.rb:14:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/flash.rb:243:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:195:in `context'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:190:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/cookies.rb:326:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activerecord-3.1.0/lib/active_record/query_cache.rb:62:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/callbacks.rb:28:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/sendfile.rb:101:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/railties-3.1.0/lib/rails/rack/logger.rb:13:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/methodoverride.rb:24:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/runtime.rb:17:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/activesupport-3.1.0/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/lock.rb:15:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/actionpack-3.1.0/lib/action_dispatch/middleware/static.rb:53:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/railties-3.1.0/lib/rails/engine.rb:455:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/urlmap.rb:52:in `block in call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/urlmap.rb:46:in `each'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-1.3.5/lib/rack/urlmap.rb:46:in `call'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-test-0.6.1/lib/rack/mock_session.rb:30:in `request'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-test-0.6.1/lib/rack/test.rb:219:in `process_request'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rack-test-0.6.1/lib/rack/test.rb:57:in `get'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/capybara-1.1.2/lib/capybara/rack_test/browser.rb:62:in `process'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/capybara-1.1.2/lib/capybara/rack_test/browser.rb:21:in `visit'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/capybara-1.1.2/lib/capybara/rack_test/driver.rb:32:in `visit'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/capybara-1.1.2/lib/capybara/session.rb:157:in `visit'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in `visit'
     # ./spec/requests/users/registrations_spec.rb:10:in `block (3 levels) in '
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example.rb:51:in `instance_eval'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example.rb:51:in `block in run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example.rb:110:in `with_around_hooks'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example.rb:48:in `run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:306:in `block in run_examples'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:302:in `map'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:302:in `run_examples'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:274:in `run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:275:in `block in run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:275:in `map'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:275:in `run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:24:in `map'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:24:in `block in run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/reporter.rb:12:in `report'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:21:in `run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_in_process'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:66:in `rescue in run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:62:in `run'
     # .rvm/gems/ruby-1.9.3-p0@foo/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'

2 回答

  • 0

    如果键入 bin/rspec --help ,您将看到可以添加到命令的选项和开关列表,包括 --backtrace 开关,它告诉RSpec显示完整的回溯 . 如果您运行 bin/rspec spec/requests/users/registrations_spec.rb --backtrace ,您应该准确地看到错误的来源 .

    HTH,大卫

  • 0

    更新:哦,好悲伤,这是一个糟糕的合并之后的红鲱鱼 . 在某个地方,以下内容从清除spec / spechelper.rb中删除

    Dir["#{Rails.root}/app/**/*.rb"].each {|f| load f}
    

    现在这已经恢复,一切都在恢复 . 我怀疑它只是加载平面目录,而不是嵌套目录,使它看起来像命名空间问题 .

相关问题