Skip to content

Instantly share code, notes, and snippets.

@wojtekmach
Last active December 17, 2015 08:59
Show Gist options
  • Save wojtekmach/5583628 to your computer and use it in GitHub Desktop.
Save wojtekmach/5583628 to your computer and use it in GitHub Desktop.
minitest/spec + shared examples
require 'minitest/autorun'
class MiniTest::Spec
def self.include_tests(tests)
tests.each do |args, block|
it(*args, &block)
end
end
end
class Module
def included_tests
@included_tests ||= []
end
def it(*args, &block)
included_tests << [args, block]
self.class.send(:define_method, :included) do |base|
base.include_tests(included_tests)
end
end
alias :specify :it
end
module SupportsCount
it "returns a natural number" do
assert_operator @object.count, :>=, 0
end
it "returns an integer" do
assert_kind_of Integer, @object.count
end
end
describe Array do
include SupportsCount
before do
@object = []
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment