2012-10-27 2 views
3

약간의 검색을했지만 좋은 설명을 찾을 수 없으므로 여기에 내 질문이 있습니다.rspec을 사용한 레일 엔진 도우미

저는 헬퍼 만 추가하는 레일스 엔진을 작성하고 있습니다.

구조는이 (중요한 부분)과 같다 :

# Configure Rails Envinronment 
ENV['RAILS_ENV'] = 'test' 
require File.expand_path('../dummy/config/environment.rb', __FILE__) 

require 'rspec/rails' 

ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') 

# Requires supporting ruby files with custom matchers and macros, etc, 
# in spec/support/ and its subdirectories. 
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each { |f| require f } 

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

를 지금까지 너무 좋아,하지만 난 테스트하는 방법에 대한 확실하지 않다 :

my_engine/ 
    -- app/ 
    -- helpers/ 
     -- my_engine/ 
      -- my_engine_helper.rb 
    -- spec/ 
    -- dummy/ 
    -- spec_helper.rb 

spec_helper.rb 다음이다 내 도우미.

  • 테스트 파일을 더미 응용 프로그램이 지금은 도우미
  • 테스트 도우미 자체

를 사용할 수있는

  • 테스트 구성 : 내가하는 가장 좋은 방법은 무엇인지 알고 싶습니다 사양을 실행할 때 다음과 같은 오류가 발생합니다.

    undefined local variable or method `helper' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fcee8b0f4a0> 
    

    다음 테스트 :

    require 'spec_helper' 
    
    module MyEngine 
        describe MyEngineHelper do 
        describe '#something' do 
         it "does something" do 
         helper.something.should be_true 
         end 
        end 
        end 
    end 
    

    고맙습니다!

  • +0

    어디 상대적있는 사양이다 (나는 그것에 기여) 사용자의 spec 디렉토리? –

    +0

    또,'require 'spec_helper' 만하면됩니다. –

    +0

    Ok 사양을 업데이트했습니다. spec/my_engine/my_engine_helper_spec.rb에 스펙을 배치했지만 올바른 장소인지 여부는 알 수 없습니다. – Happynoff

    답변

    2

    spec/helpers/my_engine_helper_spec.rb으로 이동하십시오. rspec-rails에는 spec/helpers의 내용을 연결하여 helper 메서드를 추가합니다.