Skip to content

Instantly share code, notes, and snippets.

@mpouleijn
Created July 25, 2012 07:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mpouleijn/3174954 to your computer and use it in GitHub Desktop.
Save mpouleijn/3174954 to your computer and use it in GitHub Desktop.
Minitest shared example
class MiniTest::Spec
def self.shared_examples
@shared_examples ||= {}
end
end
module MiniTest::Spec::SharedExamples
def shared_examples_for(desc, &block)
MiniTest::Spec.shared_examples[desc] = block
end
def it_behaves_like(desc)
self.instance_eval do
MiniTest::Spec.shared_examples[desc].call
end
end
end
Object.class_eval { include(MiniTest::Spec::SharedExamples) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment