How to resolve factory_girl wrong number of arguments error

Viewed 6631
#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

Running rspec results in this error when trying to build the @room

ArgumentError: wrong number of arguments (0 for 2)

3 Answers

What was useful for me, was enabling debug output for FactoryBot linting:

FactoryBot.lint verbose: true

see the documentation for the details

Related