Created
September 11, 2012 06:10
-
-
Save tf/3696362 to your computer and use it in GitHub Desktop.
Using RSpec expectations in MiniTest tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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