[rspec-users] stuck in testing hell...

Patrick J. Collins patrick at collinatorstudios.com
Tue May 1 19:17:18 UTC 2012

> The frustration your experiencing is actually a good thing, its your brain saying "hey something is just not right". Of
> course our natural reaction to this is just to get angry, but if we can get past that there is an opportunity to learn
> something important. In my limited experience I've found that listening to tests is one of the best ways to learn. There
> is probably something seriously wrong with your existing tests and code. So instead of trying to work around it, and get
> your tests to pass, seize the opportunity and try and work out why your tests and code suck and get to the bottom of the
> problem. This is a real opportunity to learn something.

I hear you, but honestly these tests are very straight forward and not
overly complicated in any way, shape, or form.  I did some more
experimenting and was able to narrow the problem down to:  Serialization and Mocha.

class Foo < ActiveRecord::Base
  serialize :bar

by using debugger within a test, I did:
> foo = Foo.create!
> foo.save
=> true

> foo.bar = stub("waka waka")
> foo.save
=> NoMethodError: undefined method `matches_method?' for nil:NilClass
/Users/bountybuy/.rvm/gems/ruby-1.9.3-p125 at bountybuy/gems/mocha-0.10.5/lib/mocha/mock.rb:185:in


So the solution since using OpenStruct as an alternative was a disaster

Foo.class_eval { attr_accessor :bar }

With that, ActiveRecord no longer handles the setter/getter methods
for that column, and this issue goes away.


So I am out of testing hell now..  yay!

Patrick J. Collins

More information about the rspec-users mailing list