Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Friendlier behavior for non test-unit frameworks i.e. bacon #88

Closed
cldwalker opened this Issue Jul 7, 2012 · 9 comments

Comments

Projects
None yet
2 participants

I'm using mocha with bacon which hadn't been a problem until the integration check which errors out unless mini-test or test-unit is defined:

$ bacon -q -Ilib -I. test/*_test.rb
0 tests, 0 assertions, 0 failures, 0 errors
/Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/mocha-0.12.0/lib/mocha/integration.rb:39:in `<top (required)>': Test::Unit or MiniTest must be loaded *before* Mocha (use MOCHA_OPTIONS=skip_integration if you know what you are doing). (Run
timeError)
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/mocha-0.12.0/lib/mocha.rb:2:in `require'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/mocha-0.12.0/lib/mocha.rb:2:in `<top (required)>'
        from /Users/me/code/gems/hirb/test/test_helper.rb:3:in `require'
        from /Users/me/code/gems/hirb/test/test_helper.rb:3:in `<top (required)>'
        from /Users/me/code/gems/hirb/test/auto_table_test.rb:1:in `require'
        from /Users/me/code/gems/hirb/test/auto_table_test.rb:1:in `<top (required)>'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:115:in `load'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:115:in `block in <top (required)>'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:114:in `each'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:114:in `<top (required)>'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/bin/bacon:23:in `load'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/bin/bacon:23:in `<main>'/Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/mocha-0.12.0/lib/mocha/integration.rb:39:in `<top (required)>': Test::Unit or MiniTest must be loaded *before* Mocha (use MOCHA_OPTIONS=skip_integration if you know what you are doing). (RuntimeError)
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/mocha-0.12.0/lib/mocha.rb:2:in `require'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/mocha-0.12.0/lib/mocha.rb:2:in `<top (required)>'
        from /Users/me/code/gems/hirb/test/test_helper.rb:3:in `require'
        from /Users/me/code/gems/hirb/test/test_helper.rb:3:in `<top (required)>'
        from /Users/me/code/gems/hirb/test/auto_table_test.rb:1:in `require'
        from /Users/me/code/gems/hirb/test/auto_table_test.rb:1:in `<top (required)>'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:115:in `load'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:115:in `block in <top (required)>'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:114:in `each'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/gems/bacon-1.1.0/bin/bacon:114:in `<top (required)>'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/bin/bacon:23:in `load'
        from /Users/me/code/gems/hirb/vendor/ruby/1.9.1/bin/bacon:23:in `<main>'

I'm aware I can skip this check with MOCHA_OPTIONS=skip_integration but is there a way mocha could be friendlier to alternative test frameworks? I could put a check for bacon here if that works for you. Obviously this only solves mocha being friendly for bacon but I'm unsure how you'd want to generally solve this.

Owner

floehopper commented Jul 9, 2012

I'm very sympathetic to this, but I'd like to avoid dependencies on test frameworks that are not in the standard library.

I'm thinking of making test framework integration more explicit e.g. require "mocha/minitest" and require "mocha/test-unit" and that would make it easier to fail fast if integration with the named framework failed. Then since users of Bacon would not have either of these specific require statements, you wouldn't see an error.

It would be great to not see an error on startup. Anything I can do to help with this? Sounds like a patch that removes https://github.com/freerange/mocha/blob/master/lib/mocha/integration.rb#L38-40 would be a start

Owner

floehopper commented Jul 10, 2012

For now, could you lock your application to use v0.11.4 of Mocha. I don't just want to remove that section of code, because it is addressing a very common problem where people neglect to add the require: false bundler option for Mocha or then neglect to explicitly require Mocha after the test framework is loaded.

Can you remind me how Bacon integrates with Mocha at the moment? I think you ought to be able to change it so it does a require "mocha_standalone" instead of require "mocha" and then include the Mocha::API module into the equivalent of a test case and call Mocha::API#mocha_setup, Mocha::API#mocha_verify, & Mocha::API#mocha_teardown. This should avoid the exception you describe and fits in better with the direction in which I want to take Mocha.

Owner

floehopper commented Jul 10, 2012

I should get a chance to do some work on this tomorrow (Wed).

jamesotron added a commit to rubymotion/BubbleWrap that referenced this issue Jul 17, 2012

cldwalker added a commit to cldwalker/mocha-on-bacon that referenced this issue Jul 19, 2012

require mocha_standalone instead of mocha to avoid failure
mocha >= 0.12.0 fails explicitly if mocha is required as discussed
in freerange/mocha#88. Suggestion is to require new file.

I'm using mocha-on-bacon and opened a pull request with your suggestion.

For such a hard failure as require 'mocha' not working on alternative test frameworks, you should give a deprecation warning. It gives your users and other adapter gems time to avoid breakage. I have at least 6 gems using mocha and bacon and they are all now broken for contributors (example) until mocha-on-bacon is fixed or I lock down to old versions. I'd recommend releasing with deprecation warnings and having a future release revert to this behavior again.

cldwalker added a commit to cldwalker/hirb that referenced this issue Jul 19, 2012

@cldwalker cldwalker referenced this issue in cldwalker/hirb Jul 19, 2012

Closed

explicit require of test/unit (minitest) #60

Owner

floehopper commented Jul 19, 2012

I just released v0.12.1 with your requested change. I hope that helps. When I made the change, I didn't realise there were still test libraries that integrate with mocha in this way.

Thanks for the deprecation release. I'll ping you here when I've updated all my gems to be compliant with mocha_standalone.

@solidcell solidcell referenced this issue in norman/friendly_id Jul 20, 2012

Closed

Require mocha_standalone instead of mocha #315

@floehopper I've updated my old gems that had bacon - mocha issues. Thanks for the deprecation.

Owner

floehopper commented Sep 14, 2012

Thanks for letting me know.

cldwalker added a commit to cldwalker/hirb that referenced this issue Jan 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment