[rspec-users] Observed models cause failures with DRBSpec ?

aslak hellesoy aslak.hellesoy at gmail.com
Mon Jan 22 11:45:23 EST 2007


On 1/22/07, Francois Beausoleil <francois.beausoleil at gmail.com> wrote:
> 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 ?
>

I haven't tried to reproduce this, but it sounds like
rails_spec_server is not reinitialising the rails environment
properly. Essentially, we're trying to make rails_spec_server behave
the same way as Rails in development mode - reload everything on each
HTTP request.

Take a peek inside rails_spec_server - perhaps we're not doing this
correctly? If it works with Rails in development mode (can you check
that please), it should work with rails_spec_server too.

If you can confirm that reloading happens ok in dev mode (hitting with
your browser), but not with rails_spec_server, then please submit a
bug report, along with useful versions/revision numbers etc.

By the way, drbspec will be replaced with spec --drb in the next RSpec release.

Not much help, but maybe a nudge in the right direction for more debugging.
Aslak

> Thanks !
> --
> François Beausoleil
> http://blog.teksol.info/
> http://piston.rubyforge.org/
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list