[rspec-users] Observed models cause failures with DRBSpec ?
Francois Beausoleil
francois.beausoleil at gmail.com
Mon Jan 22 11:25:26 EST 2007
Hi all !
I don't believe I am the only one using model observers, right ?
Well, here's a nice one:
$ drbspec spec
.
Finished in 0.125322 seconds
1 specification, 0 failures
$ drbspec spec
F
1)
'A user with an inactive and an active project should be able to
return active projects only' FAILED
[] should == [#<Spec::Mocks::Mock:0xb75590bc @name="active", @options={}>]
./spec/models/user_spec.rb:11:
script/rails_spec_server:17:in `run'
script/rails_spec_server:38:
Finished in 0.024455 seconds
1 specification, 1 failure
# spec/models/user_spec.rb
require File.dirname(__FILE__) + "/../spec_helper"
context "A user with an inactive and an active project" do
setup do
@user = User.new
end
specify "should be able to return active projects only" do
@active = mock("active")
Project.stub!(:active).and_return([@active])
@user.active_projects.should == [@active]
end
end
# app/models/user.rb
class User < ActiveRecord::Base
has_many :projects, :foreign_key => "owner_id", :order => "projects.title"
def active_projects(force=false)
@active_projects = nil if force
@active_projects ||= self.projects.active
end
end
The observer is loaded in config/environment.rb like this:
Rails::Initializer.run do |config|
config.active_record.observers = :user_observer
end
There's nothing very interesting about this, except that if I comment
the user observer in the configuration, I can run drbspec spec
multiple times in a row without failures. If I add the observer, I
can run drbspec without failures once, then I get failures like the
one above for ever after.
Can anyone confirm / deny this behavior ?
Thanks !
--
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/
More information about the rspec-users
mailing list