Skip to content

Instantly share code, notes, and snippets.

@txus
Created October 2, 2010 17:01
Show Gist options
  • Save txus/607800 to your computer and use it in GitHub Desktop.
Save txus/607800 to your computer and use it in GitHub Desktop.
Sample spec for RSpec Matcher compatibility with TestUnit and Minitest
# matchers.rb
module RSpec
module Matchers
if RSpec.respond_to?(:configure)
RSpec.configure {|c| c.include self}
end
# Include Matchers for other test frameworks
if defined?(Test::Unit::TestCase)
Test::Unit::TestCase.send(:include, self)
end
if defined?(MiniTest::Unit::TestCase)
MiniTest::Unit::TestCase.send(:include, self)
end
end
end
# matchers_spec.rb
require 'spec_helper'
module Test
module Unit
class TestCase
end
end
end
module MiniTest
module Unit
class TestCase
end
end
end
module RSpec
describe Matchers do
let(:sample_matchers) do
[:be,
:be_close,
:be_instance_of,
:be_kind_of]
end
context "once required" do
before(:all) do
path = File.expand_path("../../../../#{path}", __FILE__)
require File.join(path, 'lib/rspec/matchers.rb')
end
it "includes itself in Test::Unit::TestCase" do
test_unit_case = Test::Unit::TestCase.new
sample_matchers.each do |sample_matcher|
test_unit_case.should respond_to(sample_matcher)
end
end
it "includes itself in MiniTest::Unit::TestCase" do
minitest_case = MiniTest::Unit::TestCase.new
sample_matchers.each do |sample_matcher|
minitest_case.should respond_to(sample_matcher)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment