Class: TarkaMatchers::Matchers::Class::HaveAnInstanceVariableOf
- Includes:
- Helpers::Utility
- Defined in:
- lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb
Instance Attribute Summary
Attributes included from Helpers::Utility
#description, #failure_message, #failure_message_when_negated
Instance Method Summary collapse
-
#initialize(instance_name) ⇒ HaveAnInstanceVariableOf
constructor
A new instance of HaveAnInstanceVariableOf.
- #matches?(actual) ⇒ Boolean
- #that_equals(expected) ⇒ Object
Methods included from Helpers::Utility
#difference, #fail_default, #fail_with_message, #negated_default, #pass_default, #pass_with_message, #selected
Constructor Details
#initialize(instance_name) ⇒ HaveAnInstanceVariableOf
Returns a new instance of HaveAnInstanceVariableOf.
13 14 15 |
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 13 def initialize instance_name @instance_name = instance_name end |
Instance Method Details
#matches?(actual) ⇒ Boolean
22 23 24 25 26 27 28 29 |
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 22 def matches? actual @actual = actual.instance_variable_get(@instance_name) pass_default "contain an instance variable called, '#{@instance_name}', that equals '#{@expected}'." negated_default fail_default append: "#{TarkaMatchers::Formatters::Difference.difference(@expected,@actual)}" "failed to contain an instance variable called '#{@instance_name}'. It does not exist inside the class." unless actual.instance_variable_defined?(@instance_name) @actual == @expected end |
#that_equals(expected) ⇒ Object
17 18 19 20 |
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 17 def that_equals expected @expected = expected self end |