gpt4 book ai didi

ruby - 如何解决 factory_girl wrong number of arguments 错误

转载 作者:数据小太阳 更新时间:2023-10-29 06:45:05 24 4
gpt4 key购买 nike

#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

结束

引用:documentation

关于ruby - 如何解决 factory_girl wrong number of arguments 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6837761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com