All 211 specs in my test suite were passing fine...until I upgraded from rails 3.2 to rails 3.2.1. Now 197 of my specs fail with errors. Most of these error have the "wrong number of arguments (0 for 1)" error described below.
Example #1:
class DocumentLibrary < ActiveRecord::Base
extend FriendlyId
friendly_id :title, :use => :slugged
has_many :shelves, :dependent => :destroy
has_many :documents, :through => :shelves
validates :title, :presence => true, :uniqueness => true
default_scope :order => :title
end
Spec:
it "can be shown on the company menu" do
dl = FactoryGirl.create(:document_library, :title => 'Test', :menu => false, :company => true)
dl.should be_valid
end
Fails with:
1) DocumentLibrary can be shown on the company menu
Failure/Error: dl = FactoryGirl.create(:document_library, title: 'Test', menu: false, company: true)
ArgumentError:
wrong number of arguments (0 for 1)
# ./spec/models/document_library_spec.rb:6:in `block (2 levels) in <top (required)>'
If I place a call to the debugger before the the FactoryGirl.create line, I get:
/Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:252:
(rdb:1) c
/Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/core_ext/module/remove_method.rb:4: `' (NilClass)
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:249:in `set_it_up'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:200:in `subclass'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in `describe'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/dsl.rb:18:in `describe'
from /Users/Jason/code/rails/teamsite/spec/models/document_library_spec.rb:4:in `<top (required)>'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
/Users/Jason/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/core_ext/module/remove_method.rb:4:
Example #2
class Album < ActiveRecord::Base
belongs_to :photo_library
validates :title, :presence => true
validates :title, :uniqueness => {scope: :photo_library_id}
end
class PhotoLibrary < ActiveRecord::Base
default_scope :order => :title
has_many :albums, :dependent => :destroy
validates :title, :presence => true
validates :title, :uniqueness => true
end
Spec:
before :each do
@photo_library = FactoryGirl.create(:photo_library, title: 'Products')
login_admin
end
it "destroys an album" do
3.times { FactoryGirl.create(:album, photo_library: @photo_library) }
visit photo_library_path(@photo_library)
find("h3").click_link 'Delete'
find("#notice").should have_content("Album deleted successfully")
Album.count.should eq 2
end
Fails with:
1) Albums destroys an album
Failure/Error: login_admin
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `click_button'
# ./spec/requests/albums_spec.rb:7:in `block (2 levels) in <top (required)>'
Line 8 in my sessions_controller is:
user = User.find_by_email(params[:email])
Inspecting the params at this point shows everything (including :email) is present as it should be.
Contrasting Example #3
This spec with FactoryGirl passes fine:
it "is unique within a library" do
pl = FactoryGirl.create(:photo_library, title: 'Products')
pl2 = FactoryGirl.create(:photo_library, title: 'Competitors')
a = FactoryGirl.create(:album, title: 'Gold Series', photo_library: pl)
na = Album.create(photo_library_id: pl.id, title: 'Gold Series')
na.should_not be_valid
na.title = 'Cyclone'
na.should be_valid
na = Album.create(photo_library_id: pl2.id, title: 'Gold Series')
na.should be_valid
end
The factories are defined as follows:
factory :document_library do
sequence(:title) { |n| "Library Title#{n}" }
end
factory :photo_library do
sequence(:title) { |n| "Photo Library Title#{n}" }
end
factory :album do
sequence(:title) {|n| "Album#{n}"}
end
If I comment out the FriendlyId lines from the DocumentLibrary model, Example #1 passes. I have no idea why that makes a difference.
However, some specs still don't pass. Consider the following model (which doesn't use FriendlyId) and spec that flunks in 3.2.1:
class DrawingLibrary < ActiveRecord::Base
validates :title, :presence => true
default_scope order: :title
has_many :drawings, :dependent => :destroy
end
it "displays in alpha order" do
FactoryGirl.create(:drawing_library, title: 'C')
FactoryGirl.create(:drawing_library, title: 'B')
FactoryGirl.create(:drawing_library, title: 'A')
ts = ''
DrawingLibrary.all.each do |draw_lib|
ts += draw_lib.title
end
ts.should eq 'ABC'
end
1) DrawingLibrary displays in alpha order
Failure/Error: DrawingLibrary.all.each do |draw_lib|
ArgumentError:
wrong number of arguments (0 for 1)
# ./spec/models/drawing_library_spec.rb:19:in `block (2 levels) in <top (required)>'
Results of: rspec spec/models/document_library_spec.rb --backtrace
1) DocumentLibrary can be shown on the company menu
Failure/Error: dl = FactoryGirl.create(:document_library, title: 'Test', menu: false, company: true)
ArgumentError:
wrong number of arguments (0 for 1)
# ./spec/models/document_library_spec.rb:6:in `block (2 levels) in <top (required)>'
I'm using rvm with ruby 1.9.3, with Rubygems at 1.8.16. Factory Girl is at 2.6.0, with factory_girl_rails at 1.7.0. rspec-rails is at 2.8.1.
Here's what I know so far:
- Downgrading back to Rails 3.2.0 makes everything work again
- Upgrading to Edge Rails does not fix the problem
- Running edge versions of the rspec gems doesn't fix the problem
- The app runs properly and as expected in development mode. Only tests seem to be affected.
- Downgrading to ruby 1.9.2 doesn't fix the problem
- Upgrading to ruby 1.9.3-p125 doesn't fix the problem
- Changing from MySQL to SQLite for the test environment doesn't fix the problem
- Downgrading factory_girl_rails to 1.6.0 or even 1.5.0 doesn't fix the problem
- Using Factory.create(...) instead of Factory(...) doesn't fix the problem
- Using FactoryGirl.define() and FactoryGirl.create() doesn't fix the problem
- Commenting out the FriendlyId stuff makes some of the specs pass (see below)
- Running db:test:prepare (or db:reset, db:migrate) does not fix the problem
- Changing all FactoryGirl definitions/creations to be consistent doesn't fix the problem
- Reinstalling gems under a new rvm gemset (or even reinstalling rvm entirely) doesn't fix the problem
- Rewriting these tests in Test/Unit and FactoryGirl produces no errors. So FactoryGirl might not be the problem
Can anyone point me in a direction on this? Or offer troubleshooting advice?
Here's my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.2.1'
gem 'mysql2'
gem 'dynamic_form'
gem 'friendly_id'
group :assets do
gem 'sass-rails', " ~> 3.2.3"
gem 'coffee-rails', "~> 3.2.1"
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'therubyracer'
gem 'bcrypt-ruby'
gem 'capistrano'
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
group :test, :development do
gem 'rspec-rails'
gem 'launchy'
gem 'ruby-debug19'
gem 'database_cleaner'
gem 'capybara-webkit'
gem 'spork', '~> 0.9.0.rc'
gem 'guard-spork'
end
group :development do
gem 'fuubar'
gem 'powder'
end
group :test do
gem 'turn', :require => false
gem 'capybara'
gem 'factory_girl_rails'
gem 'guard-rspec'
end
The only differences in Gemfile.lock after upgrading to Rails 3.2.1 are with the Rails core libraries (no testing gems changed).