Code Monkey home page Code Monkey logo

Comments (5)

floehopper avatar floehopper commented on May 13, 2024

Hi Alexander,

How are you requiring rspec? It looks to me as if the mocha teardown hook is not being fired. This might be a load order issue or it might be a problem with rspec in Ruby 1.9.2. I don't know much about rspec, but the following code works for me in Ruby 1.9.2 :-

# my_test.rb
require "test/unit"
require "rubygems"
require "mocha"

class MyTest < Test::Unit::TestCase
  def test_should_pass
    object = mock()
    object.expects(:expected_method).at_least_once
    object.expected_method
  end
  def test_should_fail
    object = mock()
    object.expects(:expected_method).at_least_once
  end
end

Here's what happens when I run it as a standalone file :-

$ ruby my_test.rb
Loaded suite my_test
Started
F.
Finished in 0.007384 seconds.

  1) Failure:
test_should_fail(MyTest) [my_test.rb:13]:
not all expectations were satisfied
unsatisfied expectations:
- expected at least once, not yet invoked: #<Mock:0x1008434f0>.expected_method(any_parameters)

2 tests, 2 assertions, 1 failures, 0 errors, 0 skips

Test run options: --seed 60283

Regards, James.

from mocha.

floehopper avatar floehopper commented on May 13, 2024

Can you give me your equivalent standalone file i.e. including all require statements so I can see if I can reproduce your problem?

from mocha.

sekrett avatar sekrett commented on May 13, 2024

I just run this file from command line.
If I add:

RSpec.configure do |config|
  config.mock_with :mocha
end

it solves. Copied it from a Rails site.

from mocha.

floehopper avatar floehopper commented on May 13, 2024

Ok. I still don't see how you are loading rspec itself, but I'm glad you've solved your problem. I'm going to mark this as closed. I hope that's ok.

from mocha.

sekrett avatar sekrett commented on May 13, 2024

I type:

# rspec ./at_spec.rb

and it runs. No framework, no includes. Thanks anyway. I agree to close issue.

from mocha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.