Fabrication - wrong number of arguments (given 2, expected 0..1)

298 views
Skip to first unread message

Wellington DC

unread,
Sep 14, 2018, 6:42:05 AM9/14/18
to fabrication
Hy Guys!

This is the first time I'm using Fabrication and I'm getting an error that I've been struggling a lot. If someone could help, I'd appreciate a lot.

The error message is this one:

 1) Person is valid

     Failure/Error: Fabricate(:person)

     

     ArgumentError:

       wrong number of arguments (given 2, expected 0..1)

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/active_record.rb:8:in `build_instance'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:13:in `build'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:22:in `create'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:65:in `block in fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:64:in `instance_eval'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:64:in `fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/fabricator.rb:8:in `fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication.rb:49:in `Fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:144:in `block in generate_value'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:97:in `assign_field'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:92:in `assign'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:70:in `method_missing'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:112:in `block in process_attributes'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:109:in `each'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:109:in `process_attributes'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:6:in `build'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:22:in `create'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:65:in `block in fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:64:in `instance_eval'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:64:in `fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/fabricator.rb:8:in `fabricate'

     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication.rb:49:in `Fabricate'

     # ./spec/models/person_spec.rb:8:in `block (2 levels) in <top (required)>'

     # ./spec/models/person_spec.rb:12:in `block (2 levels) in <top (required)>'




The file spec/models/person_spec.rb is like that:

require 'rails_helper'

RSpec.describe Person, type: :model do

  let(:person) do    
    Fabricate(:person)
  end
end



In the file spec/fabricators/person_fabricator.rb is like that:

Fabricator(:person) do
  first_name "Alice"
  last_name "Smith"
  user
end


If I comment the field lines in this file, nothing changes on the error message that continues the same.

I'm using Rails 5.2.1,   Ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]   and fabrication 2.2.3

In addition, I tried to generate a new person in the console and it is running ok:

2.5.0 :020 > p = Person.new(first_name: "Alice", last_name: "Smith", user_id: 1)

 => #<Person id: nil, first_name: "Alice", last_name: "Smith", created_at: nil, updated_at: nil, user_id: 1> 



Paul Elliott

unread,
Sep 14, 2018, 6:45:00 AM9/14/18
to fabrica...@googlegroups.com
Hey there!

What happens if you try to Fabricate(:person) in the console?

I assume user is a belongs_to relationship on the Person model?

--
You received this message because you are subscribed to the Google Groups "fabrication" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabricationge...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

-- Paul

Wellington DC

unread,
Sep 14, 2018, 10:48:03 AM9/14/18
to fabrication
Hi Paul!

Thanks for replying first of all.

When I try it in the console, it gives almost the same error message:

2.5.0 :030 > Fabricate(:person)

Traceback (most recent call last):

        1: from (irb):30

ArgumentError (wrong number of arguments (given 2, expected 0..1))



About relationship, it is the opposite, user has_many and person belongs_to user. It is developed like that because an user needs to be the owner of contacts that it creates, that's why the relationship is not the contrary.

Paul Elliott

unread,
Sep 14, 2018, 10:54:53 AM9/14/18
to fabrica...@googlegroups.com
Oh, my bad. I read it then reversed it in my head. Are you using the `protected_attributes` gem in a Rails 5 project by any chance?


-- Paul

To unsubscribe from this group and stop receiving emails from it, send an email to fabricationgem+unsubscribe@googlegroups.com.

Wellington DC

unread,
Sep 14, 2018, 11:27:51 AM9/14/18
to fabrication
No Paul, there's no gem like that, see gemfile:

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

gem 'unicorn'

# gem 'omniauth'
gem 'omniauth-twitter'

group :development, :test do
  gem 'rspec-rails'
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'capybara'
  gem 'fabrication'
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end


# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Wellington DC

unread,
Sep 14, 2018, 11:42:26 AM9/14/18
to fabrication
The same happens with user_spec.rb:

~/Development/JumpStartLab/contact_manager $ rspec spec/models/user_spec.rb

User
  has associated people (FAILED - 1)

Failures:

  1) User has associated people
     Failure/Error: let(:user) { Fabricate(:user) }
     
     ArgumentError:
       wrong number of arguments (given 2, expected 0..1)
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/active_record.rb:8:in `build_instance'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:13:in `build'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/generator/base.rb:22:in `create'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:65:in `block in fabricate'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:64:in `instance_eval'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/schematic/definition.rb:64:in `fabricate'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication/fabricator.rb:8:in `fabricate'
     # /Users/wdcunha/.rvm/gems/ruby-2.5.0/gems/fabrication-2.2.3/lib/fabrication.rb:49:in `Fabricate'
     # ./spec/models/user_spec.rb:6:in `block (2 levels) in <top (required)>'
     # ./spec/models/user_spec.rb:10:in `block (2 levels) in <top (required)>'

Finished in 0.00831 seconds (files took 1.08 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/models/user_spec.rb:9 # User has associated people




On Friday, 14 September 2018 15:54:53 UTC+1, Paul Elliott wrote:

Paul Elliott

unread,
Sep 14, 2018, 12:13:57 PM9/14/18
to fabrica...@googlegroups.com
Oh, I just noticed your fabrication version is way out of date. Mind updating it to the latest and see if that fixes it?


-- Paul

To unsubscribe from this group and stop receiving emails from it, send an email to fabricationgem+unsubscribe@googlegroups.com.

Wellington DC

unread,
Sep 14, 2018, 2:12:52 PM9/14/18
to fabrication
Owwww bad.....updated my friend:

Fetching fabrication 2.20.1 (was 2.2.3)

Installing fabrication 2.20.1 (was 2.2.3)



Thanks a lot for your help. I was almost crazy!!!  Everything fine finally!!!!

Now I got an error, but I think it's not related to Fabricator, but if you have some clue about it, I'll appreciate a lot, however don't mind because I took too many time of you.

The error message is that:

~/Development/JumpStartLab/contact_manager $ rspec spec/models/user_spec.rb


User

  has associated people (FAILED - 1)

  builds associated people


Failures:


  1) User has associated people

     Failure/Error: expect(user.people).to be_instance_of(Array)

       expected #<ActiveRecord::Associations::CollectionProxy []> to be an instance of Array

     # ./spec/models/user_spec.rb:10:in `block (2 levels) in <top (required)>'


Finished in 0.31834 seconds (files took 2.05 seconds to load)

2 examples, 1 failure


Failed examples:


rspec ./spec/models/user_spec.rb:9 # User has associated people


Paul Elliott

unread,
Sep 14, 2018, 2:44:07 PM9/14/18
to fabrica...@googlegroups.com
Looks to me like your test is incorrect. I think you probably want to verify the contents of the association as opposed to the type of response. Maybe try this matcher?



-- Paul

To unsubscribe from this group and stop receiving emails from it, send an email to fabricationgem+unsubscribe@googlegroups.com.

Wellington DC

unread,
Sep 14, 2018, 3:09:26 PM9/14/18
to fabrication
Thanks a lot for helping me. Someone told me to change for be_empty instead and it got green and thanks for sharing this link, it'll be useful a lot!

Best wishes buddy!!!
Reply all
Reply to author
Forward
0 new messages