views:

31

answers:

0

I'm building an app in rails 3 using rspec 2 for specs. All my specs are working fine, except my request spec (only have one at the moment, as I'm building specs as I work):

def mock_account(stubs = {})
  @mock_account ||= mock_model(Account, stubs).as_null_object
end

before (:each) do
  Account.stub(:find_by_id).with(1) { mock_account }
end

describe "GET /account/1/users" do
  it "get" do
    get account_user_account_relationships_path(1)
  end
end

When I execute this spec, it fails:

1) UserAccountRelationships GET /account/1/users get
   Failure/Error: get account_user_account_relationships_path(1)
   undefined method `abstract_class?' for Object:Class

Looking at the stack trace, the test is calling 'find_by_id' as I'd expect, and then invoking the rpec mock framework, but then eventually making its way into active record and ultimately failing. Top few lines of the stack trace follow:

 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1208:in `class_of_active_record_descendant'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:824:in `base_class'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:964:in `compute_table_name'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:601:in `reset_table_name'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:591:in `table_name'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:679:in `columns'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:692:in `column_names'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:705:in `column_methods_hash'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1043:in `all_attributes_exists?'
 # /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/callbacks.rb:427:in `all?'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1043:in `each'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1043:in `all?'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1043:in `all_attributes_exists?'
 # /opt/local/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:991:in `method_missing'
 # /opt/local/lib/ruby/gems/1.8/gems/rspec-mocks-2.0.0.beta.22/lib/rspec/mocks/proxy.rb:109:in `send'
 # /opt/local/lib/ruby/gems/1.8/gems/rspec-mocks-2.0.0.beta.22/lib/rspec/mocks/proxy.rb:109:in `message_received'
 # /opt/local/lib/ruby/gems/1.8/gems/rspec-mocks-2.0.0.beta.22/lib/rspec/mocks/method_double.rb:79:in `find_by_id'

What confuses me is that this same mocking approach is working fine in all the other specs, so what's so different about request specs that is causing this to fail, or have I made some subtle error somewhere?

Thanks :)