rubyunit-testingruby-mocha

Ruby Mocha Unittest can't find "has_key" method


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!


Solution

  • 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.