Skip to content

Instantly share code, notes, and snippets.

@floehopper

floehopper/Gemfile

Last active Nov 10, 2018
Embed
What would you like to do?
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