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
# File 'lib/rspec2minitest.rb', line 6

def add_matcher(matcher_name, matcher_module: nil, assertion_prefix: nil)
  positive_name = RSpec2MiniTest::PositiveTestName.new(
      matcher_name, matcher_module: matcher_module, assertion_prefix: assertion_prefix
  )
  negative_name = RSpec2MiniTest::NegativeTestName.new(
      matcher_name, matcher_module: matcher_module, assertion_prefix: assertion_prefix
  )
  [positive_name, negative_name].each do |test_name|
    define_expectation test_name
  end
end

.define_assertion(test_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rspec2minitest.rb', line 23

def define_assertion(test_name)
  method_name = test_name.assertion_name
  MiniTest::Assertions.send(:define_method, method_name) do |page, *args|
    matcher = test_name.matcher(*args)

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

    assert matches, failure_message
  end
end

.define_expectation(test_name) ⇒ Object



18
19
20
21
# File 'lib/rspec2minitest.rb', line 18

def define_expectation(test_name)
  define_assertion test_name
  infect_assertion test_name
end

.infect_assertion(test_name) ⇒ Object



35
36
37
# File 'lib/rspec2minitest.rb', line 35

def infect_assertion(test_name)
  MiniTest::Expectations.infect_an_assertion test_name.assertion_name, test_name.expectation_name, true
end