0

I've written a Unit test using Test::Unit and Mocha. I'm using "expects" to mock a method in a class I'm testing, and I want to check if a certain parameter is passed into the object:

service.expects(:get).once.with(path, has_key('t')).returns([])

On my development system, this runs just fine. On my colleague's computer, as well as on the Travis CI servers, the unit test fails with the following error:

NoMethodError: undefined method `has_key' for #<FloxTest:0x000000036d4770>

The same happens with all other methods that Mocha is supposed to add to the unit test, e.g. the "mock()" method.

I know that Mocha is picky concerning the import order. I imported it after "test/unit", though:

require 'test/unit'
require 'mocha/test_unit'

If anyone needs more context, the complete test file is here. In fact, the complete project is open source, and it's a rather small project: GitHub; the complete error log can be seen on Travis CI.

I don't have any more ideas on what I could try. We even made sure that my colleague has the exact same gem versions as I have; and the Ruby version is also identical.

Thanks in advance for any help from a Ruby Guru out there, I'd really appreciate it!

Vega
  • 27,856
  • 27
  • 95
  • 103
PrimaryFeather
  • 479
  • 3
  • 12

1 Answers1

1

I've now added this as an issue on the Mocha issue tracker on your behalf.

You can see my suggested fix in my comment there. I hope that helps.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
James Mead
  • 3,472
  • 19
  • 17
  • Indeed, that worked perfectly fine, thanks a lot! For reference / other readers: I've exchanged 'mocha/test_unit' with 'mocha/setup'. The reason for the problem was that the standard library version of 'Test::Unit' uses 'MiniTest' internally, so it's 'MiniTest' that needs to be manipulated by Mocha. – PrimaryFeather Mar 03 '14 at 13:36
  • @JamesMead why don't you include the fix in your answer here, since link-only answers are of limited use (and for that reason, are generally considered non-answers on stack overflow). – mah Mar 03 '14 at 22:13