#rspec test code
@room = FactoryGirl.build(:room)
#factory definition
factory :room do
length {10}
width {20}
end
#code implementation
class Room
attr_accessor :length, :width
def initialize(length,width)
@length = length
@width = width
end
end
在尝试构建@room 时运行 rspec 会导致此错误
ArgumentError: wrong number of arguments (0 for 2)
最佳答案
现在可以了。在 4.1 版上测试:
FactoryGirl.define do
factory :room do
length 10
width 20
initialize_with { new(length, width) }
end
结束
关于ruby - 如何解决 factory_girl wrong number of arguments 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6837761/