[rspec-users] Strange validation errors

David Chelimsky dchelimsky at gmail.com
Mon Mar 15 08:40:53 EDT 2010


On Mon, Mar 15, 2010 at 6:54 AM, jollyroger
<timo.roessner at googlemail.com> wrote:
> Hey guys,
>
> I'm having a serious rspec-problem at the moment:
>
> I keep getting strange, empty validation errors when I run the whole
> spec-suite:
>
> #################################################################
> 1)
> ActiveRecord::RecordInvalid in 'LikesController DELETE destroy' should
> change like-count'
> Validation failed:
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/validations.rb:1090:in `save_without_dirty!'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/dirty.rb:87:in `save_without_transactions!'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/transactions.rb:200:in `save!'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/connection_adapters/abstract/database_statements.rb:
> 136:in `transaction'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/transactions.rb:182:in `transaction'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/transactions.rb:200:in `save!'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/transactions.rb:208:in `rollback_active_record_state!'
> my_project/vendor/bundled_gems/gems/activerecord-2.3.5/lib/
> active_record/transactions.rb:200:in `save!'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/proxy/create.rb:6:in `result'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:316:in `run'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:260:in `create'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/proxy/build.rb:17:in `associate'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/attribute/association.rb:15:in `add_to'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:313:in `run'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:311:in `each'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:311:in `run'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:260:in `create'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:291:in `send'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl/factory.rb:291:in `default_strategy'
> my_project/vendor/bundled_gems/gems/factory_girl-1.2.3/lib/
> factory_girl.rb:21:in `Factory'
> ./spec/controllers/likes_controller_spec.rb:46:
> #################################################################
>
> Here is the corresponding spec:
>
> #################################################################
>    it "should change like-count" do
>      we_are_logged_in_as(get_member_user)
>      entry = Factory(:entry)
>      Factory(:like, :user => get_member_user, :entry => entry)
>      lambda do
>        post 'destroy', :entry_id => entry.id
>      end.should change(Like, :count).by(-1)
>      response.should be_success
>    end
> #################################################################
>
> Trouble-Shooting turns out to be difficult:
>
> The spec itself seems to be correct, when running the spec-file alone
> I don't get any errors.
> I only get this error when running the whole spec-suite - running the
> single spec file is fine:
>
> #################################################################
> spec spec/controllers/likes_controller_spec.rb
> Example disabled: should change like-count on success
> ...
>
> Finished in 0.756284 seconds
>
> 3 examples, 0 failures
> #################################################################
>
> I have a lot of other specs failing in the very same way.
> The errors itself are confusing - empty validation error messages are
> utterly meaningless.
>
> I suspect that there is something going wrong with all the stubbing /
> mocking within in my specs.
>
> To be concrete:
>
> I suspect that something like:
>
> Foo.any_instance.stubs(:bar).returns....
>
> within a spec isn't properly isolated from the other specs, thus
> causing strange validation errors.
>
> What do you guys think?
> How could I narrow down this error further?
>
> Sys-Info:
> OS: Ubuntu 9.10
> spec -v
> rspec 1.3.0
> Mocking / Stubbing: Mocha 0.9.8

Take a look at this thread and see if it helps:

http://groups.google.com/group/mocha-developer/browse_thread/thread/5c2b8b28f700bb17?hl=en


More information about the rspec-users mailing list