我有這個文件,我想測試。「無法自動加載常量」使用rspec而不是rails
app/workers/station/http.rb
module Worker
module Station
class HTTP
# ...
end
end
end
這是我的規格文件。
spec/workers/station/http_spec.rb
describe Worker::Station::HTTP do
it "should do something" do
end
end
現在的問題是使用RSpec的運行規範文件時,我發現了以下錯誤。
rspec spec/workers/station/http_spec.rb
/Users/linus/.rvm/gems/[email protected]/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:464:in `load_missing_constant': Unable to autoload constant Station::HTTP, expected app/workers/station/http.rb to define it (LoadError)
from /Users/linus/.rvm/gems/[email protected]/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:184:in `const_missing'
from spec/workers/station/http_spec.rb:3:in `<top (required)>'
from /Users/linus/.rvm/gems/[email protected]/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `load'
from /Users/linus/.rvm/gems/[email protected]/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `block in load'
from /Users/linus/.rvm/gems/[email protected]/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/linus/.rvm/gems/[email protected]/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `load'
from /Users/linus/.rvm/gems/[email protected]/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/linus/.rvm/gems/[email protected]/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
from /Users/linus/.rvm/gems/[email protected]/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/linus/.rvm/gems/[email protected]/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
from /Users/linus/.rvm/gems/[email protected]/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
from /Users/linus/.rvm/gems/[email protected]/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
from /Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
奇怪的是,everyting在控制檯工作。
$ rails c [1] pry(main)> Worker::Station::HTTP => Worker::Station::HTTP
爲什麼使用這個RSpec的發生,而不是在鐵軌和我將如何解決?
我使用
- 軌(4.0.4)
- rspec的(2.14.1)
我收到了同樣的錯誤。你有沒有想過如何解決這個問題? –
由於rspec沒有自動加載app/workers路徑,因爲它不是標準導軌佈局,您可以將autoload行添加到spec_helper或直接在規範中要求該文件! – jfornoff
@jfornoff請插入您的評論作爲答案。這將有助於其他人員遇到這個問題。謝謝您的幫助! – avital