title: Why does upgrading to Rails 3.2.1 cause multiple Rspec tests to fail?
body: <p>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.</p>
  
  <p><strong>Example #1:</strong></p>
  
  <pre><code>class DocumentLibrary &lt; ActiveRecord::Base
    extend FriendlyId
    friendly_id :title, :use =&gt; :slugged
    has_many :shelves, :dependent =&gt; :destroy
    has_many :documents, :through =&gt; :shelves
    validates :title, :presence =&gt; true, :uniqueness =&gt; true
  
    default_scope :order =&gt; :title
  end
  </code></pre>
  
  <p>Spec: </p>
  
  <pre><code>  it "can be shown on the company menu" do
      dl = FactoryGirl.create(:document_library, :title =&gt; 'Test', :menu =&gt; false, :company =&gt; true)
      dl.should be_valid
    end
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>   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 &lt;top (required)&gt;'
  </code></pre>
  
  <p>If I place a call to the debugger before the the FactoryGirl.create line, I get:</p>
  
  <pre><code>/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 `&lt;top (required)&gt;'
      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:
  </code></pre>
  
  <p><strong>Example #2</strong></p>
  
  <pre><code>class Album &lt; ActiveRecord::Base
    belongs_to :photo_library
  
    validates :title, :presence =&gt; true
    validates :title, :uniqueness =&gt; {scope: :photo_library_id}
  end
  
  class PhotoLibrary &lt; ActiveRecord::Base
    default_scope :order =&gt; :title
    has_many :albums, :dependent =&gt; :destroy
  
    validates :title, :presence =&gt; true
    validates :title, :uniqueness =&gt; true
  end
  </code></pre>
  
  <p>Spec:</p>
  
  <pre><code>  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
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>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 &lt;top (required)&gt;'
  </code></pre>
  
  <p>Line 8 in my sessions_controller is:</p>
  
  <pre><code>user = User.find_by_email(params[:email])
  </code></pre>
  
  <p>Inspecting the params at this point shows everything (including :email) is present as it should be.</p>
  
  <p><strong>Contrasting Example #3</strong></p>
  
  <p>This spec with FactoryGirl passes fine:</p>
  
  <pre><code>  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
  </code></pre>
  
  <p>The factories are defined as follows:</p>
  
  <pre><code>  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
  </code></pre>
  
  <p>If I comment out the FriendlyId lines from the DocumentLibrary model, Example #1 passes.  I have no idea why that makes a difference.</p>
  
  <p>However, some specs still don't pass.  Consider the following model (which doesn't use FriendlyId) and spec that flunks in 3.2.1:</p>
  
  <pre><code>class DrawingLibrary &lt; ActiveRecord::Base
    validates :title, :presence =&gt; true
    default_scope order: :title 
    has_many :drawings, :dependent =&gt; :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 &lt;top (required)&gt;'
  </code></pre>
  
  <p>Results of: rspec spec/models/document_library_spec.rb --backtrace</p>
  
  <pre><code> 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 &lt;top (required)&gt;'
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>Here's what I know so far:</strong></p>
  
  <ul>
  <li>Downgrading back to Rails 3.2.0 makes everything work again</li>
  <li>Upgrading to Edge Rails does not fix the problem</li>
  <li>Running edge versions of the rspec gems doesn't fix the problem</li>
  <li>The app runs properly and as expected in development mode.  Only tests seem to be affected.</li>
  <li>Downgrading to ruby 1.9.2 doesn't fix the problem</li>
  <li>Upgrading to ruby 1.9.3-p125 doesn't fix the problem</li>
  <li>Changing from MySQL to SQLite for the test environment doesn't fix the problem</li>
  <li>Downgrading factory_girl_rails to 1.6.0 or even 1.5.0 doesn't fix the problem</li>
  <li>Using Factory.create(...)  instead of Factory(...) doesn't fix the problem</li>
  <li>Using FactoryGirl.define() and FactoryGirl.create() doesn't fix the problem</li>
  <li>Commenting out the FriendlyId stuff makes some of the specs pass (see below)</li>
  <li>Running db:test:prepare (or db:reset, db:migrate) does not fix the problem</li>
  <li>Changing all FactoryGirl definitions/creations to be consistent doesn't fix the problem</li>
  <li>Reinstalling gems under a new rvm gemset (or even reinstalling rvm entirely) doesn't fix the problem</li>
  <li>Rewriting these tests in Test/Unit and FactoryGirl produces no errors.  So FactoryGirl might not be the problem</li>
  </ul>
  
  <p><strong>Can anyone point me in a direction on this?  Or offer troubleshooting advice?</strong></p>
  
  <p>Here's my Gemfile:</p>
  
  <pre><code>source 'http://rubygems.org'
  
  gem 'rails', '3.2.1'
  
  gem 'mysql2'
  gem 'dynamic_form'
  gem 'friendly_id'
  
  group :assets do
    gem 'sass-rails', "  ~&gt; 3.2.3"
    gem 'coffee-rails', "~&gt; 3.2.1"
    gem 'uglifier', '&gt;= 1.0.3'
  end
  
  gem 'jquery-rails'
  gem 'therubyracer'
  gem 'bcrypt-ruby'
  gem 'capistrano'
  gem "paperclip", :git =&gt; "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', '~&gt; 0.9.0.rc'
    gem 'guard-spork'
  end
  
  group :development do
    gem 'fuubar'
    gem 'powder'
  end
  
  group :test do
    gem 'turn', :require =&gt; false
    gem 'capybara'
    gem 'factory_girl_rails'
    gem 'guard-rspec'
  end
  </code></pre>
  
  <p>The only differences in Gemfile.lock after upgrading to Rails 3.2.1 are with the Rails core libraries (no testing gems changed).</p>