Class: Sinclair::Matchers::AddMethodTo

Inherits:
RSpec::Matchers::BuiltIn::BaseMatcher
  • Object
show all
Defined in:
lib/sinclair/matchers/add_method_to.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, method) ⇒ AddMethodTo

Returns a new instance of AddMethodTo.



6
7
8
9
10
11
12
13
# File 'lib/sinclair/matchers/add_method_to.rb', line 6

def initialize(instance, method)
  if instance.is_a?(Class)
    @instance_class = instance
  else
    @instance = instance
  end
  @method = method
end

Instance Attribute Details

#instance ⇒ Object (readonly)

Returns the value of attribute instance.



4
5
6
# File 'lib/sinclair/matchers/add_method_to.rb', line 4

def instance
  @instance
end

#method ⇒ Object (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/sinclair/matchers/add_method_to.rb', line 4

def method
  @method
end

Instance Method Details

#description ⇒ Object



15
16
17
# File 'lib/sinclair/matchers/add_method_to.rb', line 15

def description
  "add method '#{method}' to #{instance_class} instances"
end

#equal?(other) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/sinclair/matchers/add_method_to.rb', line 39

def equal?(other)
  return unless other.class == self.class
  other.method == method &&
    other.instance == instance
end

#failure_message_for_should ⇒ Object



19
20
21
22
# File 'lib/sinclair/matchers/add_method_to.rb', line 19

def failure_message_for_should
  "expected '#{method}' to be added to #{instance_class} but " \
    "#{@initial_state ? 'it already existed' : "it didn't"}"
end

#failure_message_for_should_not ⇒ Object



24
25
26
# File 'lib/sinclair/matchers/add_method_to.rb', line 24

def failure_message_for_should_not
  "expected '#{method}' not to be added to #{instance_class} but it was"
end

#matches?(event_proc) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/sinclair/matchers/add_method_to.rb', line 28

def matches?(event_proc)
  return false unless event_proc.is_a?(Proc)
  raise_block_syntax_error if block_given?
  perform_change(event_proc)
  changed?
end

#supports_block_expectations? ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/sinclair/matchers/add_method_to.rb', line 35

def supports_block_expectations?
  true
end