Module: RSpec2MiniTest

Defined in:
lib/rspec2minitest.rb,
lib/rspec2minitest/version.rb,
lib/rspec2minitest/test_name.rb

Defined Under Namespace

Classes: NegativeTestName, PositiveTestName, TestName, Version

Class Method Summary collapse

Class Method Details

.add_matcher(matcher_name, matcher_module: nil, assertion_prefix: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# 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) ⇒ Object



21
22
23
24
25
26
27
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



29
30
31
32
# File 'lib/rspec2minitest.rb', line 29

def define_expectation(test_name)
  define_assertion test_name
  infect_assertion test_name
end

.infect_assertion(test_name) ⇒ Object



46
47
48
# 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