I have an odd situation whereby if I run an individual rspec model spec file all examples are green, if I test my entire spec/models folder all my examples are green. If I test the controllers they all pass green. If I test the entire suite (via rspec spec) then I get failures - If I remove the controller tests entirely everything is green. Now I'm expecting this is entirely self inflicted but I just can't figure it out.
I've narrowed it down to specific examples in the controller tests - which cause the examples in model specs to fail.
eg. in a notes_controller_spec.rb if this line is present
Note.any_instance.stubs(:valid?).returns(false)
it causes a failure in my models/account_spec.rb
Failure/Error: @account.all_notes.should have(2).notes
ArgumentError:
comparison of Note with Note failed
./app/models/account.rb:293:in `sort'
where line 293 is;
(self.notes + self.transactions.map(&:notes).flatten).sort {|a,b| a.created_at <=> b.created_at }
I'm pretty sure this is going to be one of those face palm moments so be gentle with me!
created_at
may benil
for one of the Notes, which means your sort block would be comparingnil
against aFixnum
, which would cause the block to returnnil
, which would make sort blow up with the kind ofArgumentError
you're seeing. Are you sure all of your instances have been saved in the database when this line runs? Is it possible your database is not being emptied before each example? – Threegaitedbefore :all
block? That could cause the problem of the method staying stubbed. Just a guess. – Doro