로드 오류와 관련된 일련의 두통을 일으킨 새로운 파일을 'lib'에 방금 만들었습니다.'lib'네임 스페이스/자동 로딩과 일치하지 않는 "LoadError"동작이 발생했습니다.
/lib/response_set.rb : 그것은 처음에 도달 할 때
module MyCompany
class ResponseSet < Array
...
end
end
/spec/lib/response_set_spec.rb
require 'spec_helper'
describe MyCompany::ResponseSet do
describe "..." do
...
end
end
은 RSpec에이 스펙을 실행하면 '우리에게 다음과 같은 오류를 제공합니다 설명 : '
/Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:492:in `load_missing_constant': Expected /Users/my_stuff/projects/my_project/lib/response_set.rb to define ResponseSet (LoadError)
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:181:in `each'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:181:in `const_missing'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-expectations-2.5.0/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
from /Users/my_stuff/projects/my_project/spec/lib/response_set_spec.rb:4:in `<top (required)>'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
우리는 동일한 구조를 가진 오랜 시간 동안 많은 다른 파일을 사용 해왔다.
/lib/smart_set.rb
module MyCompany
class SmartSet < Array
...
end
end
그리고이
require 'spec_helper'
describe MyCompany::SmartSet do
describe "..." do
...
end
end
이를 /spec/lib/smart_set_spec.rb 예를 들어, 여기이 생성 된 이후 잘 작동 된 또 다른 하나 파일은 구조가 동일하지만 전혀 문제가 없습니다.
ResponseSet (문제 클래스)은 식별 할 수없는 이유로로드 문제가있는 것 같습니다. response_set_spec의 상단에
require 'response_set'
를 추가, 또한
Loading development environment (Rails 3.0.4)
ruby-1.9.2-p136 :001 > rs = MyCompany::ResponseSet.new
LoadError: Expected /Users/my_stuff/projects/my_project/lib/response_set.rb to define ResponseSet
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:492:in `load_missing_constant'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:181:in `each'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:181:in `const_missing'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:503:in `load_missing_constant'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:181:in `each'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/activesupport-3.0.4/lib/active_support/dependencies.rb:181:in `const_missing'
from (irb):1
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/railties-3.0.4/lib/rails/commands/console.rb:44:in `start'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/railties-3.0.4/lib/rails/commands/console.rb:8:in `start'
from /Users/my_stuff/.rvm/gems/[email protected]_project/gems/railties-3.0.4/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ruby-1.9.2-p136 :002 > rs = MyCompany::ResponseSet.new
=> []
을 : 레일 콘솔에서 처음 난 오류가 하나를 만들려고하지만, 나는 나중에 만들 수 있습니다. rb를 사용하면 해당 테스트를 실행할 수 있습니다. 그러나 smart_set_spec.rb에는 그런 것이 필요하지 않습니다. 나는 레일이 파일 구조 사물의 이러한 종류의 네임 스페이스 구조와 일치하는 방법에 대한 의견의 어떤 종류가 있는지 이해, 이제
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.autoload_paths += Dir["#{config.root}/app/models/**/"]
을, 우리는 구조 조정 한 다음
는application.rb에 자리에 우리의 모듈과 파일을 그것은 문제를 해결 한 것으로 보입니다. (우리가 전체 테스트를 실행할 때 이상한로드 오류를 잠시 보았지만, 이것들은 신비하게 사라졌습니다.) 그럼에도 불구하고 여기있는 모든 사람들은 당혹스러워하며 Rails가 너무 모순되어서 왜 우리가 그 이유를 알고 싶어하는지 조금도 짜증을 내지 않습니다. 보시다시피 네임 스페이스와 파일 구조가 완전히 다른 방식으로 처리되는 한 동일한 두 개의 파일이 있습니다. 실제로 우리는 전혀 문제를 일으키지 않은 유사한 네임 스페이스를 가진 'lib'의 최상위 레벨에 약 12 개의 다른 파일을 가지고 있습니다. 아무도 여기 무슨 일이 일어 났는지 설명 할 수 있니?
감사합니다. 의심스러워. Exception을 높이는 것이 날씨에 의존해야한다고 생각합니다. 'require_or_load'가 성공했습니다. 그러나 그때 다시 레일스 배짱이있는 미궁에 익숙하지 않습니다. –
@Nick, 파일을로드 한 후 상수가 아직 정의되지 않은 경우 예외가 발생합니다. 귀하의 경우에는 파일이'MyCompany :: ResponseSet'을 정의하는 동안 파일이'ResponseSet'을 정의하는 것으로 보입니다 (이것은 나에게 보이는 방식이지만 전문가는 아닙니다). 불일치는 가장 이상한 것입니다. 원래의 문제를 단순화하지 않았습니까? 어쩌면'MyCompany :: SmartSet'은'/ lib/smart_set.rb'뿐 아니라'/ lib/my_company/smart_set.rb'에 있을까요? 비슷한 문제에 대해 [GitHub의 버그 보고서] (https://github.com/rails/rails/issues/2572)를 제출했습니다. – Alexey
Nope. 파일 구조는 동일했습니다. 우리는 생각할 수있는 모든 가능한 차이를 확인하는 데 두 시간을 보냈습니다. 유일한 차이점은 각 클래스 (즉, 속성 및 메서드)의 실제 구현이지만 파일로드 방식에 영향을주지 않는 것은 아닙니다! –