Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve factory_girl wrong number of arguments error

#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)

like image 597
Arun Avatar asked Jul 26 '11 23:07

Arun


1 Answers

Now it does. Tested on version 4.1:

FactoryGirl.define do

  factory :room do
    length 10
    width 20
    initialize_with { new(length, width) }
  end

end

Reference: documentation

like image 186
B Seven Avatar answered Sep 28 '22 06:09

B Seven