Class: Minitest::MustWonted::Matcher::Legacy

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/mustwonted/matcher/legacy.rb

Overview

This matcher automatically calls the legacy ‘must_smth`, `refute_something` matchers if they are exists

Instance Method Summary collapse

Constructor Details

#initialize(name, args, test) ⇒ Legacy

Returns a new instance of Legacy.



7
8
9
10
11
# File 'lib/minitest/mustwonted/matcher/legacy.rb', line 7

def initialize(name, args, test)
  @name = name
  @args = args
  @test = test
end

Instance Method Details

#match?(subject, wont) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/minitest/mustwonted/matcher/legacy.rb', line 13

def match?(subject, wont)
  # trying the must_smth|wont_smth first, coz they expect the subject first
  if subject.respond_to?(name = "#{wont ? 'wont' : 'must'}_#{@name}")
    subject.__send__ name, *@args

  # falling back to aseert|refute methods in case
  elsif @test.respond_to?(name = "#{wont ? 'refute' : 'assert'}_#{@name}")
    @test.__send__ name, subject, *@args
  elsif wont
    raise "Couldn't find the '#{wont ? 'refute' : 'assert'}_#{@name}' matcher"
  end
end