Hi,
First things first: Thanks for the GREAT gem and all of the work that
I read on David C.'s blog that Rails 3.2 broke “stub_model” and
I have a bunch of specs that ran fine using rspec-rails-2.8.1 and
Code:
Error: ArgumentError: wrong number of arguments (0 for 2)
Has anyone else seen this? Is there a fix? Am I barking up the wrong
Thanks,
             
            
              
            
                
           
          
            
              
                larry  
              
                  
                    January 28, 2012, 11:45pm
                   
                  2 
               
             
            
              On Sat, Jan 28, 2012 at 8:14 AM, Larry [email protected] 
I have a bunch of specs that ran fine using rspec-rails-2.8.1 and
Code:
Error: ArgumentError: wrong number of arguments (0 for 2)
 
Please run with the --backtrace flag and post the backtrace so we can
             
            
              
            
                
           
          
            
              
                larry  
              
                  
                    January 29, 2012,  3:23pm
                   
                  3 
               
             
            
              Hi David,
The trace is below.
Like I said, the line in the spec that causes the error (at least I
act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError)
The line in the controller that bombs out (about 7 lines down in the
if @act.update_attributes params[:act]
  flash.now.notice = "Act was updated. (Refresh the list to see
changes in the table.)"
Thanks,
ArgumentError: wrong number of arguments (0 for 2)
/home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/activerecord-3.2.1/initialize' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/message_expectation.rb:181:inexception’raise' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/message_expectation.rb:181:ininvoke’message_received' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-mocks-2.8.0/ lib/rspec/mocks/method_double.rb:92:inupdate_attributes’update' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/implicit_render.rb:4:insend_action’process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/rendering.rb:10:inprocess_action’block in process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/activesupport-3.2.1/ lib/active_support/callbacks.rb:458:in_run__4120759382721975549__process_action__1657552574701998049__callbacks’__run_callback' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/activesupport-3.2.1/ lib/active_support/callbacks.rb:385:in_run_process_action_callbacks’run_callbacks' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/callbacks.rb:17:inprocess_action’process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/instrumentation.rb:30:inblock inblock in instrument' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/activesupport-3.2.1/ lib/active_support/notifications/instrumenter.rb:20:ininstrument’instrument' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ action_controller/metal/instrumentation.rb:29:inprocess_action’process_action' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/activerecord-3.2.1/ lib/active_record/railties/controller_runtime.rb:18:inprocess_action’process' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ abstract_controller/rendering.rb:45:inprocess’process_with_new_base_test' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ action_controller/test_case.rb:464:inprocess’process' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/devise-2.0.0/lib/ devise/test_helpers.rb:19:inblock in process’catch' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/devise-2.0.0/lib/ devise/test_helpers.rb:70:in_catch_warden’process' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/actionpack-3.2.1/lib/ action_controller/test_case.rb:390:input’block (3 levels) in <top (required)>' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example.rb:80:ininstance_eval’block in run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example.rb:173:inwith_around_hooks’run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:355:inblock in run_examples’map' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:351:inrun_examples’run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:338:inblock in run’map' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/example_group.rb:338:inrun’block (2 levels) in run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/command_line.rb:28:inmap’block in run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/reporter.rb:34:inreport’run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/runner.rb:80:inrun_in_process’run' /home/larry/.rvm/gems/ruby-1.9.3-p0@stuptues/gems/rspec-core-2.8.0/lib/ rspec/core/runner.rb:10:inblock in autorun’
             
            
              
            
                
           
          
            
              
                larry  
              
                  
                    January 29, 2012,  4:04pm
                   
                  4 
               
             
            
              On Jan 29, 2012, at 7:53 AM, Larry wrote:
Hi David,
The trace is below.
Like I said, the line in the spec that causes the error (at least I
act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError)
 
I didn’t notice this before, but the first two lines of the backtrace
The and_raise method only works with an error class if that class has
I added a placeholder for a feature request to improve the error
To fix the problem (with or without helpful error messages from rspec),
act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError)
to something like
act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError.new(act,
HTH,
[1]http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#and_raise-instance_method 
  
  
    
    
      
          # Raised when connection to the database could not been established because it was not 
          # able to connect to the host or when the authorization failed. 
          class DatabaseConnectionError < ConnectionNotEstablished 
            def initialize(message = nil) 
              super(message || "Database connection error") 
            end 
          
             class << self 
              def hostname_error(hostname) 
                DatabaseConnectionError.new(<<~MSG) 
                  There is an issue connecting with your hostname: #{hostname}.\n 
                  Please check your database configuration and ensure there is a valid connection to your database. 
                MSG 
              end 
          
               def username_error(username) 
                DatabaseConnectionError.new(<<~MSG) 
                  There is an issue connecting to your database with your username/password, username: #{username}.\n 
                  Please check your database configuration to ensure the username/password are valid. 
                MSG 
              end 
       
     
  
    
    
  
  
 
[3] Includes stale record in StaleObjectError · rails/rails@410fa4c · GitHub Consider attempted action in exception message of ActiveRecord::Stale… · rails/rails@c6f0461 · GitHub Add a helpful message when an error class passed to `and_raise` requires 1 or more initialization arguments · Issue #99 · rspec/rspec-mocks · GitHub