floehopper/mocha — Issue #63: cannot load such file -- mocha/mockery when expectation not met
Author: julik
Created: 2012-02-03 16:16:27+00:00
State: open

I have a Sinatra app where I am testing the following assertion

def test_get_resized_image_with_proper_signature_should_return_image
OpenSSL::HMAC.expects(:hexdigest).returns("zzz")
get '/pic/2?width=123&sig=zzz'
assert_equal 404, last_response.status
end

This fails with Mocha failing to load it's component

1) Error:
test_get_resized_image_with_proper_signature_should_return_image(TestMappe):
LoadError: cannot load such file -- mocha/mockery
method require in dependencies.rb at line 239
method block in require in dependencies.rb at line 239
method block in load_dependency in dependencies.rb at line 225
method new_constants_in in dependencies.rb at line 596
method load_dependency in dependencies.rb at line 225
method require in dependencies.rb at line 239
method method_missing in mock.rb at line 166
method hexdigest in class_method.rb at line 46
method block in in app.rb at line 256
method call in base.rb at line 1212
method block in compile! in base.rb at line 1212
method [] in base.rb at line 772
method block (3 levels) in route! in base.rb at line 772
method route_eval in base.rb at line 788
method block (2 levels) in route! in base.rb at line 772
method block in process_route in base.rb at line 821
method catch in base.rb at line 819
method process_route in base.rb at line 819
method block in route! in base.rb at line 771
method each in base.rb at line 770
method route! in base.rb at line 770
method dispatch! in base.rb at line 886
method block in call! in base.rb at line 706
method block in invoke in base.rb at line 871
method catch in base.rb at line 871
method invoke in base.rb at line 871
method call! in base.rb at line 706
method call in base.rb at line 692
method call in static.rb at line 66
method call in reconnect.rb at line 9
method call in conditional_auth.rb at line 12
method call in conditional_auth.rb at line 12
method call in no_record.rb at line 7
method call in xss_header.rb at line 22
method call in base.rb at line 47
method call in base.rb at line 47
method call in path_traversal.rb at line 16
method call in json_csrf.rb at line 17
method call in base.rb at line 47
method call in xss_header.rb at line 22
method context in id.rb at line 205
method call in id.rb at line 200
method call in nulllogger.rb at line 9
method call in head.rb at line 9
method call in methodoverride.rb at line 21
method block in call in base.rb at line 1334
method synchronize in at line 10
method synchronize in base.rb at line 1401
method call in base.rb at line 1334
method request in mock_session.rb at line 30
method process_request in test.rb at line 219
method get in test.rb at line 57
method get in index_test.rb at line 18
method test_get_resized_image_with_proper_signature_should_return_image in index_test.rb at line 62
method run in version_230_to_262.rb at line 28
method run in testcase.rb at line 17

My Gemfile reads

group :test do
gem "rack-test", :require => "rack/test"
gem "minitest"
gem "mocha", :git => 'git://github.com/floehopper/mocha.git', :require => false
end

and I am running on ruby 1.9.3-p0

This references line 166 of mock.rb which reads

require 'mocha/mockery'

and this problem might be intrinsic to new Rubies when doing a require inside a method_missing block. Once I move the require into the header of the file loading Mockery at once the problem dissapears.