module RSpec2MiniTest

Public Instance Methods

add_matcher(matcher_name, matcher_module: nil, assertion_prefix: nil) click to toggle source
# File lib/rspec2minitest.rb, line 6
def add_matcher(matcher_name, matcher_module: nil, assertion_prefix: nil)
  test_names = [
      RSpec2MiniTest::PositiveTestName,
      RSpec2MiniTest::NegativeTestName
  ]

  test_names.each do |test_name|
    define_expectation(
        test_name.new(matcher_name, matcher_module, assertion_prefix)
    )
  end
end
add_matchers(matcher_module, assertion_prefix: nil) click to toggle source
# File lib/rspec2minitest.rb, line 21
def add_matchers(matcher_module, assertion_prefix: nil)
  matcher_module.public_instance_methods.each do |matcher_name|
    add_matcher matcher_name,
                matcher_module: matcher_module,
                assertion_prefix: assertion_prefix
  end
end
define_assertion(test_name) click to toggle source
# File lib/rspec2minitest.rb, line 34
def define_assertion(test_name)
  method_name = test_name.assertion_name
  MiniTest::Assertions.send(:define_method, method_name) do |object, *args|
    matcher = test_name.matcher(*args)

    matches = matcher.send test_name.match_method, object
    failure_message = message { matcher.send test_name.failure_message_method }

    assert matches, failure_message
  end
end
define_expectation(test_name) click to toggle source
# File lib/rspec2minitest.rb, line 29
def define_expectation(test_name)
  define_assertion test_name
  infect_assertion test_name
end
infect_assertion(test_name) click to toggle source
# File lib/rspec2minitest.rb, line 46
def infect_assertion(test_name)
  MiniTest::Expectations.infect_an_assertion test_name.assertion_name, test_name.expectation_name, true
end