Class: CabezaDeTermo::JsonSpec::ErbMessageFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ ErbMessageFormatter

Returns a new instance of ErbMessageFormatter.



7
8
9
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 7

def initialize(message)
	@message = message
end

Instance Method Details

#accessors_chainObject



30
31
32
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 30

def accessors_chain
	value_holder.accessors_chain
end

#expectationObject



42
43
44
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 42

def expectation
	@expectation
end

#fieldObject



34
35
36
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 34

def field
	accessors_chain.to_s
end

#format(value) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 46

def format(value)
	return 'null' if value == nil
	return 'an object' if value.kind_of? ::Hash
	return list_string(value) if value.kind_of? ::Array

	value.to_s
end

#format_messageObject

Formatting



20
21
22
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 20

def format_message
	ERB.new(@message).result(binding)
end

#list_string(array) ⇒ Object



54
55
56
57
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 54

def list_string(array)
	values = array.collect { |each| format each }
	'[' + values.join(', ') + ']'
end

#message_on(expectation, value_holder, *params) ⇒ Object



11
12
13
14
15
16
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 11

def message_on(expectation, value_holder, *params)
	@expectation = expectation
	@value_holder = value_holder

	format_message
end

#valueObject



38
39
40
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 38

def value
	@value_holder.value
end

#value_holderObject

Accessing



26
27
28
# File 'lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb', line 26

def value_holder
	@value_holder
end