Class: BaconExpect::FailMessageRenderer
- Inherits:
-
Object
- Object
- BaconExpect::FailMessageRenderer
- Defined in:
- lib/bacon-expect/fail_message_renderer.rb
Class Method Summary collapse
- .expectation(negated) ⇒ Object
- .message_for_be(negated, subject, method_name, values) ⇒ Object
- .message_for_be_eq(negated, subject, value) ⇒ Object
- .message_for_be_equal(negated, subject, value) ⇒ Object
- .message_for_be_false(negated, subject) ⇒ Object
- .message_for_be_nil(negated, subject) ⇒ Object
- .message_for_be_true(negated, subject) ⇒ Object
- .message_for_be_within(negated, subject, range, center_value) ⇒ Object
- .message_for_change(negated, change_amount, value_diff) ⇒ Object
- .message_for_end_with(negated, subject, end_string) ⇒ Object
- .message_for_have_generic(negated, subject, method_name, values) ⇒ Object
- .message_for_have_items(negated, subject, expected_number_of_items, actual_number_of_items, key_type_name) ⇒ Object
- .message_for_include(negated, subject, values) ⇒ Object
- .message_for_match(negated, subject, match) ⇒ Object
- .message_for_match_array(negated, subject_array, expected_array) ⇒ Object
- .message_for_raise_error(negated, show_class, error_class, show_message, error_message, rescued_exception) ⇒ Object
- .message_for_respond_to(negated, subject, method_name, number_of_args) ⇒ Object
- .message_for_satisfy(negated) ⇒ Object
- .message_for_start_with(negated, subject, start_string) ⇒ Object
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.(negated, subject, method_name, values) = "#{subject.inspect} ##{method_name}" += "(#{values.map(&:inspect).join(', ')})" unless values.empty? += "#{expectation(negated)} to return true" end |
.message_for_be_eq(negated, subject, value) ⇒ Object
49 50 51 |
# File 'lib/bacon-expect/fail_message_renderer.rb', line 49 def self.(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.(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.(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.(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.(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.(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.(negated, change_amount, value_diff) = "Block#{expectation(negated)} to change value" += " by #{change_amount}" if change_amount += " but changed by #{value_diff}" if change_amount && !negated 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.(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.(negated, subject, method_name, values) = "#{subject.inspect} #has_#{method_name}?" += "(#{values.map(&:inspect).join(', ')})" unless values.empty? += "#{expectation(negated)} to return true" 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.(negated, subject, expected_number_of_items, actual_number_of_items, key_type_name) = "#{subject.inspect}#{expectation(negated)} to have #{expected_number_of_items} #{key_type_name}" += " but had #{actual_number_of_items}" unless negated 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.(negated, subject, values) = values.size == 1 ? values.first : values = "#{subject.inspect}#{expectation(negated)} to include #{.inspect}" end |
.message_for_match(negated, subject, match) ⇒ Object
78 79 80 |
# File 'lib/bacon-expect/fail_message_renderer.rb', line 78 def self.(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.(negated, subject_array, expected_array) = "#{subject_array.inspect}#{expectation(negated)} to match array" += " #{expected_array.inspect}" 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.(negated, show_class, error_class, , , rescued_exception) = "Block#{expectation(negated)} to raise error" += " of type #{error_class}" if show_class += " with message matching #{.inspect}" if += " but was #{rescued_exception.inspect}" if rescued_exception && !negated 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.(negated, subject, method_name, number_of_args) = "#{subject.inspect}#{expectation(negated)} to respond to ##{method_name}" += " with #{number_of_args} arguments" if number_of_args end |
.message_for_satisfy(negated) ⇒ Object
96 97 98 |
# File 'lib/bacon-expect/fail_message_renderer.rb', line 96 def self.(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.(negated, subject, start_string) "#{subject.inspect}#{expectation(negated)} to start with #{start_string.inspect}" end |