我的班级被定义为:
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 as:
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 :(得分:0)
尝试以这种方式定义您的工厂:
## spec/factories/schedules.rb
FactoryGirl.define do
factory :base_schedule, class: 'ScheduleKaya' do
bot_client_id "test-client-id"
end
end
将class
名称放在引号内。看看是否能解决您的问题。