cfcosta / minitest-firemock

Makes your MiniTest mocks more resilient.
31 stars 1 forks source link

MiniTest::FireMock#initialize should be able to accept a constant, not just a string? #10

Open jrab89 opened 7 years ago

jrab89 commented 7 years ago

If I have test_my_class.rb:

require 'minitest/autorun'
require 'minitest/fire_mock'

class MyClass
end

class MyClassTest < MiniTest::Test
  # this test fails
  def test_something
    mock = MiniTest::FireMock.new('MyClass')
    mock.expect(:doesnt_exist, 42)
    assert_equal 42, mock.doesnt_exist
  end

  # this test should fail, but doesn't
  def test_something_else
    mock = MiniTest::FireMock.new(MyClass)
    mock.expect(:doesnt_exist, 42)
    assert_equal 42, mock.doesnt_exist
  end
end

and then I run:

$ ruby test_my_class.rb
Run options: --seed 28129

# Running:

E.

Finished in 0.000804s, 2487.5159 runs/s, 1243.7579 assertions/s.

  1) Error:
MyClassTest#test_something:
MockExpectationError: expected MyClass to define `doesnt_exist`, but it doesn't
    test_my_class.rb:11:in `test_something'

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

The first test fails, but the second one doesn't. Is this behavior intended? If not, would you accept a PR to fix this?

Thanks!

ghostsquad commented 5 years ago

I agree this would be a great addition.