2015-10-18 47 views
1

我的類定義爲:ruby​​的factory_girl正在返回參數錯誤 - 爲什麼?

class ScheduleKaya < OrchestrateIo 
    def initialize(bot_client_id) 
    @bot_client_id = bot_client_id 
    @collection = :schedules 
    @client = Orchestrate::Client.new(ENV['ORCHESTRATE_API']) 
    end 
end 

廠如:

## spec/factories/schedules.rb 

FactoryGirl.define do 

    factory :base_schedule, class: ScheduleKaya do 

     bot_client_id "test-client-id" 

    end 

end 

Rspec的爲:

context "when creating a new reminder for test-client-id on Feburary 1st 2015" do 

     let(:schedule) { FactoryGirl.build(:base_schedule)} 
     Timecop.freeze(Chronic.parse("february 14, 2014 at 10am")) 

     it "creates an instance of ScheduleKaya" do 

     expect(schedule).to be_a ScheduleKaya 

     end 

我也得到一個參數錯誤:

Failure/Error: let(:schedule) { FactoryGirl.build(:base_schedule)} 
    ArgumentError: 
     wrong number of arguments (0 for 1) 

問題:爲什麼參數是錯誤的,因爲在類中,它只需要一個參數來初始化,並且我在工廠中提供了一個參數。

+0

參數錯誤可能發生在頂層'let'塊的執行過程中的任何地方(例如在'Orchestrate :: Client.new'的中間) –

回答

0

嘗試定義你的工廠是這樣的:

## spec/factories/schedules.rb 
FactoryGirl.define do 
    factory :base_schedule, class: 'ScheduleKaya' do 
    bot_client_id "test-client-id" 
    end 
end 

class名內報價。看看是否解決了你的問題。

+0

好的,謝謝。 – Angela

相關問題