2017-09-28 110 views
2

我有一個Rails項目並使用RSpec進行測試。最近,我在spec_helper.rb添加了這個:TypeError:類的超類不匹配任務

config.before(:suite) do 
    Rails.application.load_tasks 
end 

如果我bundle exec rspec在本地運行測試,一切都很好。但是,當我試圖做同樣的事情上特拉維斯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>' 

,如果我調試特拉維斯建立和手動啓動bundle exec rails c,做一個Rails.application.load_tasks同樣的事情發生。

這裏可能是什麼問題?任何線索將不勝感激!

回答

1

TypeError: superclass mismatch發生在重新打開某個類時,嘗試重新定義它的超類。這是一種強制此錯誤:

class A; end 
class B < A; end 
class C; end 
class B < C; end # raises erorr 

由於這只是發生在特拉維斯環境,我調試它右邊有可能的話:

  • 打開/home/travis/build/my_application/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb用vim納米或類似的CLI編輯
  • require 'pry'; binding.pry,導致錯誤
  • bundle install
  • 重新運行測試代碼
  • 線之上
  • 進入調試器並檢查來自哪裏的Task。由於您正在獲得TypeError: superclass mismatch,因此必須在此行之前定義Task以重新打開它。 show-source Task應該告訴你它在哪裏定義。
+0

這真的很有幫助!管理追查問題到一個初始化,修補了一些行爲。非常感謝! – linkyndy

+0

很高興幫助:) – nicooga