Skip to content

Instantly share code, notes, and snippets.

@floehopper
Last active November 10, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floehopper/150effd6a3da1b9106280371dd0c6f25 to your computer and use it in GitHub Desktop.
Save floehopper/150effd6a3da1b9106280371dd0c6f25 to your computer and use it in GitHub Desktop.
Mocha issue 349
source 'https://rubygems.org'
gem 'minitest'
gem 'mocha'
GEM
remote: https://rubygems.org/
specs:
metaclass (0.0.4)
minitest (5.11.3)
mocha (1.7.0)
metaclass (~> 0.0.1)
PLATFORMS
ruby
DEPENDENCIES
minitest
mocha
BUNDLED WITH
1.17.1
$ ruby my_test.rb
Run options: --seed 53332
# Running:
F.
Finished in 0.002206s, 906.6181 runs/s, 453.3091 assertions/s.
1) Failure:
MyTest#test_blah_fail [my_test.rb:5]:
unexpected invocation: MyClass.new("SomeKey", 1234, 2018-11-10 09:17:45 +0000 (1541841465.160419 secs))
unsatisfied expectations:
- expected exactly once, not yet invoked: MyClass.new("SomeKey", 4321, anything)
2 runs, 1 assertions, 1 failures, 0 errors, 0 skips
require 'bundler/setup'
require 'minitest/autorun'
require 'mocha/minitest'
class MyClass; end
class SomethingElse
def blah
MyClass.new('SomeKey', 1234, Time.now)
end
end
class MyTest < Minitest::Test
def test_blah_pass
object = mock
MyClass.expects(:new).with('SomeKey', 1234, anything).returns(object)
test_obj = SomethingElse.new
test_obj.blah
end
def test_blah_fail
object = mock
MyClass.expects(:new).with('SomeKey', 4321, anything).returns(object)
test_obj = SomethingElse.new
test_obj.blah
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment