1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
module Facon module Baconize # Mixin intended for Bacon::Context so that it runs spec_verify on all mocks # after each example. module ContextExtensions def self.included(base) base.class_eval do alias_method :it_without_mock_verification, :it alias_method :it, :it_with_mock_verification end end def it_with_mock_verification(description, &block) setup_facon_mocks it_without_mock_verification(description, &block) verify_facon_mocks end end module ShouldExtensions def receive(method, &block) end end end end begin Bacon::Context.class_eval { include Facon::Baconize::ContextExtensions } Should.class_eval { include Facon::Baconize::ShouldExtensions } rescue NameError require 'rubygems' require 'bacon' Bacon::Context.class_eval { include Facon::Baconize::ContextExtensions } Should.class_eval { include Facon::Baconize::ShouldExtensions } rescue LoadError puts 'Bacon is not available.' end
Refactorings
No refactoring yet !
macournoyer
February 13, 2008, February 13, 2008 02:05, permalink
Seems like there was a caching issue preventing this submission from being shown on the front page. Sorry about that
Basically what I'm trying to do is to include some extensions (in 2 modules) into classes from the Bacon gem. It should first try to include my modules directly into the classes (in case they are already required), require rubygems and bacon if that fails and try again, or worst case, fail with some indication of failure.
This is what I've got for now - is there a better way, or a more Ruby idiomatic way to do this?
Thanks for any advice!