Trying to run rails unit tests using dev-ruby/mocha mockup library causes "NameError: uninitialized constant Mocha::Mockery::Mock". The culprit seems to be the mocha-0.9.8+ruby-1.9.2.patch added by the mocha ebuild. As far as I understand the problems seems to lie with the removal of the "require mocha/mock" line from /usr/lib/ruby/gems/1.8/gems/mocha-0.9.8/lib/mocha/mockery.rb. Excerpt from patch below: diff --git a/lib/mocha/mockery.rb b/lib/mocha/mockery.rb index 6fd5e5a..3b847db 100644 --- a/lib/mocha/mockery.rb +++ b/lib/mocha/mockery.rb @@ -1,5 +1,4 @@ require 'mocha/central' -require 'mocha/mock' require 'mocha/names' require 'mocha/state_machine' require 'mocha/logger' Reproducible: Always Steps to Reproduce: 1. Emerge dev-lang/ruby-1.8.7_p249 and dev-ruby/mocha-0.9.8 2. Ensure ruby18 profile is selected with eselect ruby. 3. Run attached example test case: "ruby example_test.rb" Actual Results: Running test fails with NameError. Loaded suite example_test Started E Finished in 0.000319 seconds. 1) Error: test_call_to_mock_causes_name_error(ExampleTest): NameError: uninitialized constant Mocha::Mockery::Mock /usr/lib64/ruby/gems/1.8/gems/mocha-0.9.8/lib/mocha/mockery.rb:25:in `named_mock' /usr/lib64/ruby/gems/1.8/gems/mocha-0.9.8/lib/mocha/api.rb:43:in `mock' example_test.rb:8:in `test_call_to_mock_causes_name_error' /usr/lib64/ruby/gems/1.8/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `__send__' /usr/lib64/ruby/gems/1.8/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `run' 1 tests, 0 assertions, 0 failures, 1 errors Expected Results: Expected the tests to run successfully. Loaded suite example_test Started . Finished in 0.000321 seconds. 1 tests, 1 assertions, 0 failures, 0 errors As a workaround disabling the mocha-0.9.8+ruby-1.9.2 patch results in a working Mocha in Ruby 1.8.7.
Created attachment 243229 [details] Example test case illustrating the problem. Attached trivial test case using the Mocha library.
This is my fault for trusting upstream blindly.
Thanks for reporting, fixed with -r3. And I'll write 100 times on the blackboard "don't export upstream patches when you can do the same with a sed".
Thank you for the quick response and fix. However it seems that the SRC_URI in the ebuild was not updated to point to the new patch, resulting in emerge failure due to missing patchfile (mocha-0.9.8+ruby-1.9.2-r2.patch.bz2). Downloaded patch manually to /usr/portage/distfiles as a workaround and mocha works like a charm now.