Class: TarkaMatchers::Matchers::Class::HaveAnInstanceVariableOf

Inherits:
Object
  • Object
show all
Defined in:
lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance_name) ⇒ HaveAnInstanceVariableOf

Returns a new instance of HaveAnInstanceVariableOf.



11
12
13
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 11

def initialize instance_name
	@instance_name = instance_name
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 25

def description
	"contain an instance variable called, '#{@instance_name}', that equals '#{@expected}'."
end

#failure_messageObject



29
30
31
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 29

def failure_message
	"failed to #{description}\n#{TarkaMatchers::Formatters::Difference.difference(@expected,@actual)}"
end

#failure_message_when_negatedObject



33
34
35
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 33

def failure_message_when_negated
	"did #{description}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 20

def matches? actual
	@actual = actual.instance_variable_get(@instance_name)
	@actual == @expected
end

#that_equals(expected) ⇒ Object



15
16
17
18
# File 'lib/tarka_matchers/matchers/class/have_an_instance_variable_of.rb', line 15

def that_equals expected
	@expected = expected
	self
end