[rspec-users] removing Mocha; 'spec spec' fails but the specific model file passes

Doug dgoldie15 at gmail.com
Wed Jun 17 15:29:17 EDT 2009


ok, I investigated further...and I'm still confused.

this is testing a typical authenticate class method......

  # login can be either username or email address
  def self.authenticate(login, pass)
    user = find_by_username(login) || find_by_email(login)
    return user if user && user.matching_password?(pass)
  end

the 2 tests that fail only in spec spec.......
 before :each do
    @user = User.new
  end

  it "should not authenticate bad username" do
    #@user.attributes = valid_user_attributes
    @user = User.create!(valid_user_attributes)
    debugger
    @find_user = User.authenticate('nonexisting', 'secret')
    @find_user.should be_nil
  end

  it "should not authenticate bad password" do
    @user.attributes = valid_user_attributes
    @user.save!
    User.authenticate('joseph', 'badpassword').should be_nil
  end

When you run the specific spec file, it works correctly, i.e. by
executing this class method.
When you run spec spec, it seems to mock the method with mocha (never
passes through this method!)
and returns the fixture object.....which fails the test.

What is the correct way to do this?
... without using config.mock_with :mocha, of course

thanks





On Jun 13, 5:35 pm, David Chelimsky <dchelim... at gmail.com> wrote:
> On Sat, Jun 13, 2009 at 4:30 PM, Doug<dgoldi... at gmail.com> wrote:
> > I happened to mix ryan bates' authentication scaffold with
> > rspec_scaffold on a  demo project.
> > and ran into the problem of mixing mock frameworks...ryan uses mocha.
>
> > So, as a learning experience, I choose to redo ryan's tests without
> > mocha but ran into a strange problem with tests of the User model.
>
> > With debugging you can see....
> > If you run just the user_spec.rb file, everything is fine....rspec
> > goes through the User model.
> > However, if you run all the specs, it is somehow still using mocha
> > instead of the User model.
>
> > How is this possible since I removed the configuration for mocha.?
>
> In rails 2.3, activesupport/lib/active_support/test_case.rb requires
> mocha. That's the base class for all of the rails test cases, and
> consequently, rspec example groups as well.
>
>
>
> > In spec_helper.rb, I commented out the   line: #
> > config.mock_with :mocha
> > I also saw a require 'mocha' statement in test_helper that I removed.
>
> > ---------------------------------------------------------------------------------------------------------------------
>
> > 11:41 /c/work/quizmaker_demo (questions)$ spec spec
> > ...................................c:/work/quizmaker_demo/spec/models/
> > user_spec.rb:86
> > User.authenticate('nonexisting', 'secret').should be_nil
> > (rdb:1) s
> > c:/tools/ruby/ruby186/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/
> > class_method.rb:40
> > stubbee.__metaclass__.class_eval("def #{method}(*args, &block);
> > mocha.method_missing(:#{method}, *a
> > (rdb:1) c
>
> > _______________________________________________
> > rspec-users mailing list
> > rspec-us... at rubyforge.org
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list