Class: VariableMatcher

Inherits:
Object show all
Includes:
StringSymbolAdapter
Defined in:
lib/extensions/mspec/mspec/matchers/variable.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringSymbolAdapter

#convert_name

Constructor Details

#initialize(variable) ⇒ VariableMatcher

Returns a new instance of VariableMatcher.



10
11
12
# File 'lib/extensions/mspec/mspec/matchers/variable.rb', line 10

def initialize(variable)
  @variable = convert_name(variable)
end

Class Attribute Details

.descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/extensions/mspec/mspec/matchers/variable.rb', line 7

def description
  @description
end

.variables_methodObject

Returns the value of attribute variables_method.



7
8
9
# File 'lib/extensions/mspec/mspec/matchers/variable.rb', line 7

def variables_method
  @variables_method
end

Instance Method Details

#failure_messageObject



19
20
21
22
# File 'lib/extensions/mspec/mspec/matchers/variable.rb', line 19

def failure_message
  ["Expected #{@object} to have #{self.class.description} '#{@variable}'",
   "but it does not"]
end

#matches?(object) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/extensions/mspec/mspec/matchers/variable.rb', line 14

def matches?(object)
  @object = object
  @object.send(self.class.variables_method).include? @variable
end

#negative_failure_messageObject



24
25
26
27
# File 'lib/extensions/mspec/mspec/matchers/variable.rb', line 24

def negative_failure_message
  ["Expected #{@object} NOT to have #{self.class.description} '#{@variable}'",
   "but it does"]
end