[rspec-users] before_validation callbacks bypassed when stubbing :valid?

Zubin Henner lists at ruby-forum.com
Tue Apr 15 18:05:54 EDT 2008


I'm testing an ActiveRecord model using rspec and mocha, and found that
if I stub out the :valid? method, all before_validation callbacks are
also skipped!

Not ideal - I still want the callbacks to execute, but the validation to
return true.
Anyone know how to achieve this?

class Item < ActiveRecord::Base
  before_validation :do_something

  def do_something
    raise "hell"
  end
end

Item.any_instance.stubs(:valid?).returns(true)
item = Item.new
item.valid?
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list