Class: BaconExpect::FailMessageRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/bacon-expect/fail_message_renderer.rb

Class Method Summary collapse

Class Method Details

.expectation(negated) ⇒ Object



3
4
5
# File 'lib/bacon-expect/fail_message_renderer.rb', line 3

def self.expectation(negated)
  "#{negated ? " not" : ""} expected"
end

.message_for_be(negated, subject, method_name, values) ⇒ Object



19
20
21
22
23
24
# File 'lib/bacon-expect/fail_message_renderer.rb', line 19

def self.message_for_be(negated, subject, method_name, values)
  message = "#{subject.inspect} ##{method_name}"
  message += "(#{values.map(&:inspect).join(', ')})" unless values.empty?
  message += "#{expectation(negated)} to return true"
  message
end

.message_for_be_eq(negated, subject, value) ⇒ Object



49
50
51
# File 'lib/bacon-expect/fail_message_renderer.rb', line 49

def self.message_for_be_eq(negated, subject, value)
  "#{subject.inspect}#{expectation(negated)} to be == to #{value.inspect}"
end

.message_for_be_equal(negated, subject, value) ⇒ Object



45
46
47
# File 'lib/bacon-expect/fail_message_renderer.rb', line 45

def self.message_for_be_equal(negated, subject, value)
  "#{subject.inspect}#{expectation(negated)} to be same object as #{value.inspect}"
end

.message_for_be_false(negated, subject) ⇒ Object



7
8
9
# File 'lib/bacon-expect/fail_message_renderer.rb', line 7

def self.message_for_be_false(negated, subject)
  "#{subject.inspect}#{expectation(negated)} to be false"
end

.message_for_be_nil(negated, subject) ⇒ Object



15
16
17
# File 'lib/bacon-expect/fail_message_renderer.rb', line 15

def self.message_for_be_nil(negated, subject)
  "#{subject.inspect}#{expectation(negated)} to be nil"
end

.message_for_be_true(negated, subject) ⇒ Object



11
12
13
# File 'lib/bacon-expect/fail_message_renderer.rb', line 11

def self.message_for_be_true(negated, subject)
  "#{subject.inspect}#{expectation(negated)} to be true"
end

.message_for_be_within(negated, subject, range, center_value) ⇒ Object



26
27
28
# File 'lib/bacon-expect/fail_message_renderer.rb', line 26

def self.message_for_be_within(negated, subject, range, center_value)
  "#{subject.inspect}#{expectation(negated)} to be within #{range} of #{center_value}"
end

.message_for_change(negated, change_amount, value_diff) ⇒ Object



30
31
32
33
34
35
# File 'lib/bacon-expect/fail_message_renderer.rb', line 30

def self.message_for_change(negated, change_amount, value_diff)
  message = "Block#{expectation(negated)} to change value"
  message += " by #{change_amount}" if change_amount
  message += " but changed by #{value_diff}" if change_amount && !negated
  message
end

.message_for_end_with(negated, subject, end_string) ⇒ Object



37
38
39
# File 'lib/bacon-expect/fail_message_renderer.rb', line 37

def self.message_for_end_with(negated, subject, end_string)
  "#{subject.inspect}#{expectation(negated)} to end with #{end_string.inspect}"
end

.message_for_have_generic(negated, subject, method_name, values) ⇒ Object



53
54
55
56
57
58
# File 'lib/bacon-expect/fail_message_renderer.rb', line 53

def self.message_for_have_generic(negated, subject, method_name, values)
  message = "#{subject.inspect} #has_#{method_name}?"
  message += "(#{values.map(&:inspect).join(', ')})" unless values.empty?
  message += "#{expectation(negated)} to return true"
  message
end

.message_for_have_items(negated, subject, expected_number_of_items, actual_number_of_items, key_type_name) ⇒ Object



60
61
62
63
64
# File 'lib/bacon-expect/fail_message_renderer.rb', line 60

def self.message_for_have_items(negated, subject, expected_number_of_items, actual_number_of_items, key_type_name)
  message = "#{subject.inspect}#{expectation(negated)} to have #{expected_number_of_items} #{key_type_name}"
  message += " but had #{actual_number_of_items}" unless negated
  message
end

.message_for_include(negated, subject, values) ⇒ Object



66
67
68
69
70
# File 'lib/bacon-expect/fail_message_renderer.rb', line 66

def self.message_for_include(negated, subject, values)
  values_message = values.size == 1 ? values.first : values
  message = "#{subject.inspect}#{expectation(negated)} to include #{values_message.inspect}"
  message
end

.message_for_match(negated, subject, match) ⇒ Object



78
79
80
# File 'lib/bacon-expect/fail_message_renderer.rb', line 78

def self.message_for_match(negated, subject, match)
  "#{subject.inspect}#{expectation(negated)} to match #{match.inspect}"
end

.message_for_match_array(negated, subject_array, expected_array) ⇒ Object



72
73
74
75
76
# File 'lib/bacon-expect/fail_message_renderer.rb', line 72

def self.message_for_match_array(negated, subject_array, expected_array)
  message = "#{subject_array.inspect}#{expectation(negated)} to match array"
  message += " #{expected_array.inspect}"
  message
end

.message_for_raise_error(negated, show_class, error_class, show_message, error_message, rescued_exception) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/bacon-expect/fail_message_renderer.rb', line 82

def self.message_for_raise_error(negated, show_class, error_class, show_message, error_message, rescued_exception)
  message = "Block#{expectation(negated)} to raise error"
  message += " of type #{error_class}" if show_class
  message += " with message matching #{error_message.inspect}" if show_message
  message += " but was #{rescued_exception.inspect}" if rescued_exception && !negated
  message
end

.message_for_respond_to(negated, subject, method_name, number_of_args) ⇒ Object



90
91
92
93
94
# File 'lib/bacon-expect/fail_message_renderer.rb', line 90

def self.message_for_respond_to(negated, subject, method_name, number_of_args)
  message = "#{subject.inspect}#{expectation(negated)} to respond to ##{method_name}"
  message += " with #{number_of_args} arguments" if number_of_args
  message
end

.message_for_satisfy(negated) ⇒ Object



96
97
98
# File 'lib/bacon-expect/fail_message_renderer.rb', line 96

def self.message_for_satisfy(negated)
  "Block#{expectation(negated)} to satisfy condition"
end

.message_for_start_with(negated, subject, start_string) ⇒ Object



41
42
43
# File 'lib/bacon-expect/fail_message_renderer.rb', line 41

def self.message_for_start_with(negated, subject, start_string)
  "#{subject.inspect}#{expectation(negated)} to start with #{start_string.inspect}"
end