Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should fail at_least_once #24

Closed
sekrett opened this issue Mar 5, 2011 · 5 comments
Closed

Should fail at_least_once #24

sekrett opened this issue Mar 5, 2011 · 5 comments

Comments

@sekrett
Copy link

sekrett commented Mar 5, 2011

Why do these tests pass? It is taken from documentation.

require "mocha"

describe "test" do
  it "should pass" do
    object = mock()
    object.expects(:expected_method).at_least_once
    object.expected_method
    # => verify succeeds
  end

  it "should fail" do
    object = mock()
    object.expects(:expected_method).at_least_once
    # => verify fails
  end
end

rspec 2.5.1, mocha 0.9.12, ruby 1.9.2-p136

@floehopper
Copy link
Member

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.

@floehopper
Copy link
Member

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

@sekrett
Copy link
Author

sekrett commented Mar 5, 2011

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.

@floehopper
Copy link
Member

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.

@sekrett
Copy link
Author

sekrett commented Mar 5, 2011

I type:

# rspec ./at_spec.rb

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

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants