我有一个Rails项目并使用RSpec进行测试。最近,我在spec_helper.rb
:
config.before(:suite) do
Rails.application.load_tasks
end
如果我使用bundle exec rspec
在本地运行测试,一切都很好。但是当我尝试在Travis CI上做同样的事情时,命令崩溃了:
TypeError: superclass mismatch for class Task
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:9:in `<module:Rails>'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:8:in `<module:Sprockets>'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:7:in `<top (required)>'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb:163:in `block in <class:Railtie>'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:237:in `instance_exec'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:237:in `block in run_tasks_blocks'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:245:in `each'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:245:in `each_registered_block'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:237:in `run_tasks_blocks'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/application.rb:451:in `block in run_tasks_blocks'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine/railties.rb:13:in `each'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine/railties.rb:13:in `each'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/application.rb:451:in `run_tasks_blocks'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/engine.rb:453:in `load_tasks'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:194:in `public_send'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/railtie.rb:194:in `method_missing'
from (irb):25
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/commands/console.rb:110:in `start'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/commands/console.rb:9:in `start'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/railties-4.2.9/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
如果我调试Travis构建并手动启动bundle exec rails c
并执行Rails.application.load_tasks
,则会发生同样的事情。
这可能是什么问题?任何线索都将受到高度赞赏!
答案 0 :(得分:2)
TypeError: superclass mismatch
。这是一种强制此错误的方法:
class A; end
class B < A; end
class C; end
class B < C; end # raises erorr
由于这只发生在Travis环境中,如果可能的话我会在那里进行调试:
/home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb
require 'pry'; binding.pry
放在导致错误的行上方bundle install
Task
的位置。由于您收到TypeError: superclass mismatch
,因此必须在此行之前定义Task
才重新打开它。 show-source Task
应该显示定义的位置。