[rspec-users] Rails 3.2.1 breaks stub ?

Larry info at stupidtuesday.com
Mon Jan 30 07:45:41 EST 2012


Hi David,

You were right, and your fix worked like a charm!

Thanks for taking the time to reply. And thanks again for what you've
done and meant to the Rails community.

-- Larry

On Jan 29, 10:02 am, David Chelimsky <dchelim... at gmail.com> wrote:
> 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
> > think it does; it works when I comment it out; plus, it fails in all 3
> > specs where I have a similar line) is:
>
> > act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError)
>
> I didn't notice this before, but the first two lines of the backtrace reveal the problem.
>
> The `and_raise` method only works with an error class if that class has a 0-arg initializer [1]. ActiveRecord::StaleObjectError's initializer requires two arguments [2]. This changed between 3.1 and 3.2 [3,4].
>
> I added a placeholder for a feature request to improve the error messaging in rspec-mocks [5].
>
> To fix the problem (with or without helpful error messages from rspec), it's up to you to change
>
>   act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError)
>
> to something like
>
>   act.stub(:update_attributes).and_raise(ActiveRecord::StaleObjectError.new(act, :update))
>
> HTH,
> David
>
> [1]http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/MessageExpectation#a...
> [2]https://github.com/rails/rails/blob/master/activerecord/lib/active_re...
> [3]https://github.com/rails/rails/commit/410fa4cf
> [4]https://github.com/rails/rails/commit/c6f0461
> [5]https://github.com/rspec/rspec-mocks/issues/99
>
>


More information about the rspec-users mailing list