2012-09-24 3 views
0

Rails 3.1 엔진을 개발하고 테스트하고 싶습니다. 나는 이것을 위해 RSpec을 사용하고 모든 것이 훌륭하게 작동하지만 Spork를 사용할 때 제 도우미가 올바르게 다시로드되지 않는 문제가 있습니다. Spork & Rails 3.1 엔진 : 도우미가 다시로드되지 않습니다.

내가 모델과 유사한 문제에 대해 많이 읽고, 나는 다음과 같은 가능한 수정 함께했다 : 이것은 확실히 이제까지 도우미 파일을 다시로드 될 때까지 작동

# my_engine/spec/spec_helper.rb 

ActiveSupport::Dependencies.clear 
ActiveRecord::Base.instantiate_observers 

Dir[File.join(File.dirname(__FILE__), '..', 'app', 'helpers', '*.rb')].each do |file| 
    require file 
end 

# my_engine/spec/dummy/config/environments/test.rb 
Dummy::Application.configure do 
    # ... 
    config.cache_classes = !(ENV['DRB'] == 'true') # Ensure that classes aren't cached when using Spork. 
    # ... 
end 

(I는 중단 점을 추가 이것을 확인하십시오), 변경 사항은 테스트 내에 반영되지 않으며, 단지 Spork가 다시 시작됩니다. 어쩌면 헬퍼가 모듈이기 때문에 테스트가 모듈에 의존하지 않고 모듈을 구현하는 클래스에 의존하기 때문에 모듈은 제대로로드되지만 제대로 혼합되지 않습니다. 시

내가 그냥 each_run 블록에 모든 intitializer 코드를 가하고있어, 인 :이 주제에 대해 많은 연구를 수행 한

# Configure Rails Environment 
ENV["RAILS_ENV"] = "test" 

require File.expand_path("../dummy/config/environment.rb", __FILE__) 
require 'rspec/rails' 

Rails.backtrace_cleaner.remove_silencers! 

# Load support files 
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 

RSpec.configure do |config| 
    config.use_transactional_fixtures = true 

    config.treat_symbols_as_metadata_keys_with_true_values = true 
    config.filter_run :focus => true 
    config.run_all_when_everything_filtered = true 
end 

답변

0

, 나는이 두 블로그에 대해 서면으로 작성했습니다 게시물 :

특히 위 질문에 대한 답변 : 나는 Spork.prefork 블록에 require 'rspec/autorun' 블록이 없기 때문에 작동하지 않는다고 생각할 수 있습니다. 그러나 완전히 확신 할 수는 없습니다.

require 'rubygems' 
require 'spork' 

Spork.prefork do 
    ENV["RAILS_ENV"] ||= 'test' 
    require File.expand_path("../dummy/config/environment", __FILE__) 
    require 'rspec/rails' 
    require 'rspec/autorun' 

    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

    RSpec.configure do |config| 
    config.use_transactional_fixtures = true 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 
    config.infer_base_class_for_anonymous_controllers = false 
    config.treat_symbols_as_metadata_keys_with_true_values = true 
    config.filter_run :focus => true 
    config.run_all_when_everything_filtered = true 
    end 
end 

Spork.each_run do 
    # This code will be run each time you run your specs. 
end 
: 여기

은 (성공적으로 필요에 따라 모든 것을 다시로드) 내 현재 엔진의 spec_helper.rb이다
관련 문제