Class: MotionSpec::FailMessageRenderer
- Defined in:
- lib/motion-spec/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
4 5 6 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 4 def self.expectation(negated) "#{negated ? ' not' : ''} expected" end |
.message_for_be(negated, subject, method_name, values) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 20 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
50 51 52 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 50 def self.(negated, subject, value) "#{subject.inspect}#{expectation(negated)} to be == to #{value.inspect}" end |
.message_for_be_equal(negated, subject, value) ⇒ Object
46 47 48 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 46 def self.(negated, subject, value) "#{subject.inspect}#{expectation(negated)} to be same object as #{value.inspect}" end |
.message_for_be_false(negated, subject) ⇒ Object
8 9 10 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 8 def self.(negated, subject) "#{subject.inspect}#{expectation(negated)} to be false" end |
.message_for_be_nil(negated, subject) ⇒ Object
16 17 18 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 16 def self.(negated, subject) "#{subject.inspect}#{expectation(negated)} to be nil" end |
.message_for_be_true(negated, subject) ⇒ Object
12 13 14 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 12 def self.(negated, subject) "#{subject.inspect}#{expectation(negated)} to be true" end |
.message_for_be_within(negated, subject, range, center_value) ⇒ Object
27 28 29 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 27 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
31 32 33 34 35 36 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 31 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
38 39 40 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 38 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
54 55 56 57 58 59 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 54 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
61 62 63 64 65 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 61 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
67 68 69 70 71 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 67 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
79 80 81 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 79 def self.(negated, subject, match) "#{subject.inspect}#{expectation(negated)} to match #{match.inspect}" end |
.message_for_match_array(negated, subject_array, expected_array) ⇒ Object
73 74 75 76 77 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 73 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
83 84 85 86 87 88 89 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 83 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
91 92 93 94 95 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 91 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
97 98 99 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 97 def self.(negated) "Block#{expectation(negated)} to satisfy condition" end |
.message_for_start_with(negated, subject, start_string) ⇒ Object
42 43 44 |
# File 'lib/motion-spec/fail_message_renderer.rb', line 42 def self.(negated, subject, start_string) "#{subject.inspect}#{expectation(negated)} to start with #{start_string.inspect}" end |