On Jul 2, 2010, at 7:25 PM, Patrick Gannon wrote:

> Hi all,
> 
> I'm having a problem where stubbed static methods aren't properly becoming 
> "unstubbed".  I have tried manually unstubbing them, but it still doesn't 
> work.
> 
> Spec is as follows:
> 
>     it "creates user accounts for unknown users" do
>       Notification.stub(:deliver_routed)
>       User.should_receive(:create).with({:email => "sa...@etestflight.com"})
>       User.should_receive(:create).with({:email => "j...@etestflight.com"})
>       User.stub!(:find_by_email).with("sa...@etestflight.com") { nil }
>       User.stub!(:find_by_email).with("j...@etestflight.com") { nil }
>       User.stub!(:find_by_email).with("b...@etestflight.com") { User.new }
>       
>       begin
>         post :route, :id => "37", :email_addresses => "sa...@etestflight.com, 
> j...@etestflight.com, b...@etestflight.com"
>       ensure
>         User.unstub! :find_by_email
>         #User.unstub! :method_missing
>         User.rspec_reset
>       end      
>     end
> 
> It will pass, but then another spec fails with: "undefined method 
> `find_by_email' for Object:Class".  The other spec passes when I create a 
> database User and rely on the real definition of User.find_by_email (defined 
> by method_missing in MongoMapper's Document module) in this spec instead of 
> stubbing out the calls to find_by_email.  As you can see, I tried calling 
> "unstub!" on find_by_email, and calling rspec_reset, and it doesn't make any 
> difference (other spec still fails).  I even tried un-stubbing method_missing 
> (since that's what defines the real find_by_email) and it complains that that 
> was never stubbed.
> 
> I am running Rails 3 beta 4 with RSpec and rspec-rails beta 13 (tried 
> pointing Gemfile to the GIT repository and did a 'bundle install', but it 
> still installed beta 13 instead of 15 for some reason).

I just pushed what I  believe to be a fix for this - please try pointing 
Gemfile to the git repos again. It should work if you do this with all of them:

gem "rspec-rails",        :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec",              :git => "git://github.com/rspec/rspec.git"
gem "rspec-core",         :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => 
"git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks",        :git => "git://github.com/rspec/rspec-mocks.git"

Let me know if it works out.

Thx,
David
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to