Skip to content

Instantly share code, notes, and snippets.

@tf
Created September 11, 2012 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tf/3696362 to your computer and use it in GitHub Desktop.
Save tf/3696362 to your computer and use it in GitHub Desktop.
Using RSpec expectations in MiniTest tests
module RSpecTest
include RSpec::Matchers
def self.included(base)
base.extend ClassMethods
end
def expect(*a, &b)
# So number of assertions equals number of expectations in output
assert(true)
super
end
module ClassMethods
def test(*args, &block)
super(*args) do
begin
self.instance_eval(&block)
rescue RSpec::Expectations::ExpectationNotMetError => e
raise MiniTest::Assertion, e.message
end
end
end
end
end
class SomeTest < ActiveSupport::TestCase
include RSpecTest
test 'it can use matchers' do
expect(3).to eq(3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment