2016-08-09 2 views
0

다음 테스트 클래스를 사용할 때 다음 프록시 클래스가 있습니다. 이 Rspec 테스트를 어떻게 구성하든 상관없이 simplecov는 klass_constructor 메서드가 적용되지 않았 음을보고합니다.프록시 클래스의 이니셜 라이저 개인 메소드에 대한 Rspec 테스트 적용 범위

이 사양이 어떻게 적용되는지 확인하려면 어떻게 변경해야합니까? 이니셜 라이저가 구조에서 값 또는 거짓을 반환하지는 않지만 이상한 이벤트는 이러한 Rspec 스텁에서 발생합니다.

프록시 클래스 코드

class IntegrationProvider 
    include IntegrationError 
    include IntegrationSettings 

    def initialize(provider) 
    @provider = provider 
    return false unless valid_provider?(@provider) 
    return false unless valid_klass_constructor? 
    klass_constructor 
    end 

    def proxy_to 
    @provider_klass 
    end 

    private 

    def klass_constructor 
    @provider_klass = "#{@provider.capitalize}::#{@provider.capitalize}Provider".safe_constantize 
    end 
end 

포함 설정 모듈

module IntegrationSettings 
    def valid_provider?(provider) 
    supported_providers.include?(provider) 
    end 

    def valid_klass_constructor? 
    klass_constructor 
    end 

    private 

    def supported_providers 
    Rails.cache.fetch('supported_providers', expires_in: 10.days) do 
     Provider.where(active: true).pluck(:slug) 
    end 
    end 
end 

사양

RSpec.describe IntegrationProvider, type: :integration do 
    let!(:provider) { FactoryGirl.create(:provider, :active) } 
    let!(:klass) { Provider } 

    describe '#initialize' do 
    it 'initializes' do 
     stub_const("#{provider.slug.capitalize}::#{provider.slug.capitalize}Provider", klass) 
     expect(IntegrationProvider.new(provider.slug)).to be_truthy 
    end 
    end 

    describe '#proxy_to' do 
    subject { described_class.new(provider.slug) } 

    it 'is a proxy' do 
     subject.instance_variable_set(:@provider_klass, klass) 
     expect(subject.proxy_to).to eq(klass) 
    end 

    it 'inherits active record' do 
     subject.instance_variable_set(:@provider_klass, klass) 
     expect(subject.proxy_to.ancestors.include?(ActiveRecord::Base)).to be_truthy 
    end 
    end 

    describe '#klass_constructor' do 
    subject { described_class.new(provider.slug) } 

    it 'true' do 
     stub_const("#{provider.slug.capitalize}::#{provider.slug.capitalize}Provider", klass) 
     expect(subject.send(:klass_constructor)).to be_truthy 
    end 

    it 'assignment' do 
     stub_const("#{provider.slug.capitalize}::#{provider.slug.capitalize}Provider", klass) 
     subject.send(:klass_constructor) 
     expect(subject.instance_variable_get(:@provider_klass)).to eq(klass) 
    end 
    end 
end 

답변

0

이하지 않습니다 문제를 해결하지만

"#{@provider.capitalize}::Events::#{@provider.capitalize}Queue".safe_constantize 

이 더 깨끗합니다.

+0

실제로 보고서를 실행 한 후 simplecov를 다시 검토하고 다시 실행 한 후에 문제를 해결하고 100 % –

+0

으로 업데이트하는 것으로 보입니다. 아직 다루지 않은 'klass_constructor'가 표시됩니다. 생각? –

+0

이 팝업 백업 :( –