[rspec-users] mocking an AR: ActiveRecord::AssociationTypeMismatch error
lists at ruby-forum.com
Fri Feb 11 22:10:30 EST 2011
I have a Premise model with lots of validations and somewhat complex
callbacks. I've already written tests for those (and they pass).
I also have a MeteredService model for which premise :has_many
metered_services and (of course) metered_service :belongs_to premise.
Testing MeteredService doesn't require a real Premise -- all it needs is
a premise_id -- so for my MeteredService tests I tried a simple mock
premise = double("premise", :id => 1)
But this fails with:
Failure/Error: MeteredService.create(:premise => @premise)
Premise(#2202729700) expected, got RSpec::Mocks::Mock(#2154067120)
I *really* don't want to create a real Premise object unless there's a
way to inhibit all the validations and callbacks. (FWIW, I use
FactoryGirl for other test, but it evidently triggers validations and
callbacks just like an ordinary .create())
What are my options?
Posted via http://www.ruby-forum.com/.
More information about the rspec-users