我有这个文件,我想测试。“无法自动加载常量”使用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