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)
問題:爲什麼參數是錯誤的,因爲在類中,它只需要一個參數來初始化,並且我在工廠中提供了一個參數。
參數錯誤可能發生在頂層'let'塊的執行過程中的任何地方(例如在'Orchestrate :: Client.new'的中間) –