Class: Mocktail::RegistersMatcher

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mocktail/registers_matcher.rb,
lib/mocktail/sorbet/mocktail/registers_matcher.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistersMatcher

Returns a new instance of RegistersMatcher.



5
6
7
# File 'lib/mocktail/registers_matcher.rb', line 5

def initialize
  @grabs_original_method_parameters = GrabsOriginalMethodParameters.new
end

Instance Method Details

#register(matcher_type) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mocktail/registers_matcher.rb', line 9

def register(matcher_type)
  if invalid_type?(matcher_type)
    raise InvalidMatcherError.new <<~MSG.tr("\n", " ")
      Matchers must be Ruby classes
    MSG
  elsif invalid_name?(matcher_type)
    raise InvalidMatcherError.new <<~MSG.tr("\n", " ")
      #{matcher_type.name}.matcher_name must return a valid method name
    MSG
  elsif invalid_match?(matcher_type)
    raise InvalidMatcherError.new <<~MSG.tr("\n", " ")
      #{matcher_type.name}#match? must be defined as a one-argument method
    MSG
  elsif invalid_flag?(matcher_type)
    raise InvalidMatcherError.new <<~MSG.tr("\n", " ")
      #{matcher_type.name}#is_mocktail_matcher? must be defined
    MSG
  else
    MatcherRegistry.instance.add(matcher_type)
  end
end