super_diff 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +65 -26
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/differs.rb +1 -1
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/object_inspection.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_record/operation_trees.rb +1 -1
- data/lib/super_diff/active_record.rb +7 -15
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/differs.rb +1 -1
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
- data/lib/super_diff/active_support/object_inspection.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_support/operation_trees.rb +1 -1
- data/lib/super_diff/active_support.rb +6 -10
- data/lib/super_diff/colorized_document_extensions.rb +2 -4
- data/lib/super_diff/configuration.rb +14 -8
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/colorized_document.rb +12 -16
- data/lib/super_diff/csi/document.rb +8 -19
- data/lib/super_diff/csi/eight_bit_color.rb +19 -19
- data/lib/super_diff/csi/four_bit_color.rb +82 -31
- data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
- data/lib/super_diff/csi/uncolorized_document.rb +2 -6
- data/lib/super_diff/csi.rb +10 -14
- data/lib/super_diff/diff_formatters/collection.rb +35 -41
- data/lib/super_diff/differs/date_like.rb +15 -0
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/defaults.rb +2 -1
- data/lib/super_diff/differs/main.rb +2 -13
- data/lib/super_diff/differs.rb +1 -0
- data/lib/super_diff/equality_matchers/array.rb +10 -12
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -4
- data/lib/super_diff/equality_matchers/defaults.rb +1 -1
- data/lib/super_diff/equality_matchers/hash.rb +10 -12
- data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
- data/lib/super_diff/equality_matchers/primitive.rb +10 -12
- data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
- data/lib/super_diff/equality_matchers.rb +1 -1
- data/lib/super_diff/errors.rb +2 -6
- data/lib/super_diff/gem_version.rb +3 -3
- data/lib/super_diff/helpers.rb +10 -10
- data/lib/super_diff/implementation_checks.rb +2 -2
- data/lib/super_diff/line.rb +3 -3
- data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
- data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
- data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
- data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
- data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
- data/lib/super_diff/object_inspection/nodes.rb +7 -7
- data/lib/super_diff/object_inspection.rb +3 -3
- data/lib/super_diff/operation_tree_builders/array.rb +12 -11
- data/lib/super_diff/operation_tree_builders/base.rb +17 -15
- data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
- data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
- data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
- data/lib/super_diff/operation_tree_builders/main.rb +4 -11
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
- data/lib/super_diff/operation_tree_builders.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
- data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
- data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners.rb +3 -3
- data/lib/super_diff/operation_trees/base.rb +3 -5
- data/lib/super_diff/operation_trees/default_object.rb +1 -3
- data/lib/super_diff/operations/binary_operation.rb +2 -2
- data/lib/super_diff/operations/unary_operation.rb +1 -1
- data/lib/super_diff/rails.rb +2 -1
- data/lib/super_diff/recursion_guard.rb +5 -4
- data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
- data/lib/super_diff/rspec/differ.rb +6 -13
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs.rb +3 -3
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
- data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
- data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
- data/lib/super_diff/rspec/monkey_patches.rb +180 -123
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
- data/lib/super_diff/rspec/object_inspection.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
- data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
- data/lib/super_diff/rspec.rb +17 -18
- data/lib/super_diff/tiered_lines_elider.rb +87 -115
- data/lib/super_diff/tiered_lines_formatter.rb +5 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +13 -9
- data/spec/examples.txt +541 -483
- data/spec/integration/rails/active_record_spec.rb +3 -1
- data/spec/integration/rails/engines_spec.rb +25 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
- data/spec/integration/rspec/be_matcher_spec.rb +360 -320
- data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
- data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
- data/spec/integration/rspec/include_matcher_spec.rb +327 -225
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
- data/spec/integration/rspec/match_matcher_spec.rb +916 -903
- data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
- data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
- data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
- data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +20 -20
- data/spec/support/command_runner.rb +34 -57
- data/spec/support/integration/helpers.rb +44 -32
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +17 -22
- data/spec/support/integration/test_programs/plain.rb +6 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
- data/spec/support/models/active_record/person.rb +6 -4
- data/spec/support/models/active_record/shipping_address.rb +9 -10
- data/spec/support/models/customer.rb +2 -4
- data/spec/support/models/player.rb +3 -6
- data/spec/support/models/shipping_address.rb +4 -13
- data/spec/support/shared_examples/active_record.rb +258 -240
- data/spec/support/shared_examples/active_support.rb +174 -51
- data/spec/support/shared_examples/elided_diffs.rb +447 -423
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
- data/spec/support/shared_examples/key.rb +123 -0
- data/spec/support/unit/helpers.rb +1 -3
- data/spec/support/unit/matchers/match_output.rb +12 -13
- data/spec/unit/active_record/object_inspection_spec.rb +222 -206
- data/spec/unit/active_support/object_inspection_spec.rb +170 -0
- data/spec/unit/equality_matchers/main_spec.rb +1049 -984
- data/spec/unit/helpers_spec.rb +14 -21
- data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
- data/spec/unit/rspec/matchers/include_spec.rb +2 -2
- data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
- data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +351 -326
- data/spec/unit/super_diff_spec.rb +1594 -1437
- data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
- data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
- data/super_diff.gemspec +13 -12
- metadata +88 -75
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
- data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -1,72 +1,75 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
RSpec.describe "Integration with RSpec's #raise_error matcher",
|
3
|
+
RSpec.describe "Integration with RSpec's #raise_error matcher",
|
4
|
+
type: :integration do
|
4
5
|
context "given only an exception class" do
|
5
6
|
context "when used in the positive" do
|
6
7
|
context "when the block raises a different error than what is given" do
|
7
|
-
context "when the message is short" do
|
8
|
+
context "when the actual message is short" do
|
8
9
|
it "produces the correct failure message" do
|
9
10
|
as_both_colored_and_uncolored do |color_enabled|
|
10
11
|
snippet = <<~TEST.strip
|
11
12
|
expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)
|
12
13
|
TEST
|
13
|
-
program =
|
14
|
-
snippet,
|
15
|
-
color_enabled: color_enabled,
|
16
|
-
)
|
14
|
+
program =
|
15
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
17
16
|
|
18
|
-
expected_output =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
expected_output =
|
18
|
+
build_expected_output(
|
19
|
+
color_enabled: color_enabled,
|
20
|
+
snippet:
|
21
|
+
"expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)",
|
22
|
+
expectation:
|
23
|
+
proc do
|
24
|
+
line do
|
25
|
+
plain "Expected raised exception "
|
26
|
+
actual %|#<StandardError "boo">|
|
27
|
+
plain " to match "
|
28
|
+
expected "a kind of RuntimeError"
|
29
|
+
plain "."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
)
|
31
33
|
|
32
|
-
expect(program).
|
33
|
-
|
34
|
-
|
34
|
+
expect(program).to produce_output_when_run(
|
35
|
+
expected_output
|
36
|
+
).in_color(color_enabled)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
context "when the message is long" do
|
41
|
+
context "when the actual message is long" do
|
40
42
|
it "produces the correct failure message" do
|
41
43
|
as_both_colored_and_uncolored do |color_enabled|
|
42
44
|
snippet = <<~TEST.strip
|
43
45
|
expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)
|
44
46
|
TEST
|
45
|
-
program =
|
46
|
-
snippet,
|
47
|
-
color_enabled: color_enabled,
|
48
|
-
)
|
49
|
-
|
50
|
-
expected_output = build_expected_output(
|
51
|
-
color_enabled: color_enabled,
|
52
|
-
snippet: %|expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)|,
|
53
|
-
newline_before_expectation: true,
|
54
|
-
expectation: proc {
|
55
|
-
line do
|
56
|
-
plain %|Expected raised exception |
|
57
|
-
actual %|#<StandardError "this is a super super super long message">|
|
58
|
-
end
|
47
|
+
program =
|
48
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
59
49
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
expected_output =
|
51
|
+
build_expected_output(
|
52
|
+
color_enabled: color_enabled,
|
53
|
+
snippet:
|
54
|
+
"expect { raise StandardError.new('this is a super super super long message') }.to raise_error(RuntimeError)",
|
55
|
+
newline_before_expectation: true,
|
56
|
+
expectation:
|
57
|
+
proc do
|
58
|
+
line do
|
59
|
+
plain "Expected raised exception "
|
60
|
+
actual %|#<StandardError "this is a super super super long message">|
|
61
|
+
end
|
62
|
+
|
63
|
+
line do
|
64
|
+
plain " to match "
|
65
|
+
expected "a kind of RuntimeError"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
)
|
66
69
|
|
67
|
-
expect(program).
|
68
|
-
|
69
|
-
|
70
|
+
expect(program).to produce_output_when_run(
|
71
|
+
expected_output
|
72
|
+
).in_color(color_enabled)
|
70
73
|
end
|
71
74
|
end
|
72
75
|
end
|
@@ -78,137 +81,141 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
78
81
|
snippet = <<~TEST.strip
|
79
82
|
expect { }.to raise_error(RuntimeError)
|
80
83
|
TEST
|
81
|
-
program =
|
82
|
-
snippet,
|
83
|
-
color_enabled: color_enabled,
|
84
|
-
)
|
84
|
+
program =
|
85
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
85
86
|
|
86
|
-
expected_output =
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
expected_output =
|
88
|
+
build_expected_output(
|
89
|
+
color_enabled: color_enabled,
|
90
|
+
snippet: "expect { }.to raise_error(RuntimeError)",
|
91
|
+
expectation:
|
92
|
+
proc do
|
93
|
+
line do
|
94
|
+
plain "Expected "
|
95
|
+
actual "exception-free block"
|
96
|
+
plain " to raise "
|
97
|
+
expected "a kind of RuntimeError"
|
98
|
+
plain "."
|
99
|
+
end
|
100
|
+
end
|
101
|
+
)
|
97
102
|
|
98
|
-
expect(program).
|
99
|
-
|
100
|
-
|
103
|
+
expect(program).to produce_output_when_run(
|
104
|
+
expected_output
|
105
|
+
).in_color(color_enabled)
|
101
106
|
end
|
102
107
|
end
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
106
111
|
context "when used in the negative" do
|
107
|
-
context "when the message is short" do
|
112
|
+
context "when the actual message is short" do
|
108
113
|
it "produces the correct failure message" do
|
109
114
|
as_both_colored_and_uncolored do |color_enabled|
|
110
115
|
snippet = <<~TEST.strip
|
111
116
|
expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)
|
112
117
|
TEST
|
113
|
-
program =
|
114
|
-
snippet,
|
115
|
-
color_enabled: color_enabled,
|
116
|
-
)
|
118
|
+
program =
|
119
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
117
120
|
|
118
|
-
expected_output =
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
121
|
+
expected_output =
|
122
|
+
build_expected_output(
|
123
|
+
color_enabled: color_enabled,
|
124
|
+
snippet:
|
125
|
+
"expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)",
|
126
|
+
expectation:
|
127
|
+
proc do
|
128
|
+
line do
|
129
|
+
plain "Expected raised exception "
|
130
|
+
actual %|#<StandardError "boo">|
|
131
|
+
plain " not to match "
|
132
|
+
expected "a kind of StandardError"
|
133
|
+
plain "."
|
134
|
+
end
|
135
|
+
end
|
136
|
+
)
|
131
137
|
|
132
|
-
expect(program).
|
133
|
-
|
134
|
-
|
138
|
+
expect(program).to produce_output_when_run(
|
139
|
+
expected_output
|
140
|
+
).in_color(color_enabled)
|
135
141
|
end
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
|
-
context "when the message is long" do
|
145
|
+
context "when the actual message is long" do
|
140
146
|
it "produces the correct failure message" do
|
141
147
|
as_both_colored_and_uncolored do |color_enabled|
|
142
148
|
snippet = <<~TEST.strip
|
143
149
|
expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)
|
144
150
|
TEST
|
145
|
-
program =
|
146
|
-
snippet,
|
147
|
-
color_enabled: color_enabled,
|
148
|
-
)
|
151
|
+
program =
|
152
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
149
153
|
|
150
|
-
expected_output =
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
expected_output =
|
155
|
+
build_expected_output(
|
156
|
+
color_enabled: color_enabled,
|
157
|
+
snippet:
|
158
|
+
"expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(StandardError)",
|
159
|
+
newline_before_expectation: true,
|
160
|
+
expectation:
|
161
|
+
proc do
|
162
|
+
line do
|
163
|
+
plain "Expected raised exception "
|
164
|
+
actual %|#<StandardError "this is a super super long message">|
|
165
|
+
end
|
159
166
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
167
|
+
line do
|
168
|
+
plain " not to match "
|
169
|
+
expected "a kind of StandardError"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
)
|
166
173
|
|
167
|
-
expect(program).
|
168
|
-
|
169
|
-
|
174
|
+
expect(program).to produce_output_when_run(
|
175
|
+
expected_output
|
176
|
+
).in_color(color_enabled)
|
170
177
|
end
|
171
178
|
end
|
172
179
|
end
|
173
180
|
end
|
174
181
|
end
|
175
182
|
|
176
|
-
context "
|
183
|
+
context "given only a string message" do
|
177
184
|
context "when used in the positive" do
|
178
185
|
context "when the block raises a different error than what is given" do
|
179
|
-
context "when the message is short" do
|
186
|
+
context "when the expected and/or actual message is short" do
|
180
187
|
it "produces the correct failure message" do
|
181
188
|
as_both_colored_and_uncolored do |color_enabled|
|
182
189
|
snippet = <<~TEST.strip
|
183
190
|
expect { raise 'boo' }.to raise_error('hell')
|
184
191
|
TEST
|
185
|
-
program =
|
186
|
-
snippet,
|
187
|
-
color_enabled: color_enabled,
|
188
|
-
)
|
192
|
+
program =
|
193
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
189
194
|
|
190
|
-
expected_output =
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
195
|
+
expected_output =
|
196
|
+
build_expected_output(
|
197
|
+
color_enabled: color_enabled,
|
198
|
+
snippet: "expect { raise 'boo' }.to raise_error('hell')",
|
199
|
+
expectation:
|
200
|
+
proc do
|
201
|
+
line do
|
202
|
+
plain "Expected raised exception "
|
203
|
+
actual %|#<RuntimeError "boo">|
|
204
|
+
plain " to match "
|
205
|
+
expected %|a kind of Exception with message "hell"|
|
206
|
+
plain "."
|
207
|
+
end
|
208
|
+
end
|
209
|
+
)
|
203
210
|
|
204
|
-
expect(program).
|
205
|
-
|
206
|
-
|
211
|
+
expect(program).to produce_output_when_run(
|
212
|
+
expected_output
|
213
|
+
).in_color(color_enabled)
|
207
214
|
end
|
208
215
|
end
|
209
216
|
end
|
210
217
|
|
211
|
-
context "when the message is long" do
|
218
|
+
context "when the expected and/or actual message is long" do
|
212
219
|
context "but contains no line breaks" do
|
213
220
|
it "produces the correct failure message when used in the positive" do
|
214
221
|
as_both_colored_and_uncolored do |color_enabled|
|
@@ -217,31 +224,32 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
217
224
|
expected_message = "whatever"
|
218
225
|
expect { raise(actual_message) }.to raise_error(expected_message)
|
219
226
|
TEST
|
220
|
-
program =
|
221
|
-
snippet,
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
227
|
+
program =
|
228
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
229
|
+
|
230
|
+
expected_output =
|
231
|
+
build_expected_output(
|
232
|
+
color_enabled: color_enabled,
|
233
|
+
snippet:
|
234
|
+
"expect { raise(actual_message) }.to raise_error(expected_message)",
|
235
|
+
newline_before_expectation: true,
|
236
|
+
expectation:
|
237
|
+
proc do
|
238
|
+
line do
|
239
|
+
plain "Expected raised exception "
|
240
|
+
actual %|#<RuntimeError "some really really really long message">|
|
241
|
+
end
|
242
|
+
|
243
|
+
line do
|
244
|
+
plain " to match "
|
245
|
+
expected %|a kind of Exception with message "whatever"|
|
246
|
+
end
|
247
|
+
end
|
248
|
+
)
|
249
|
+
|
250
|
+
expect(program).to produce_output_when_run(
|
251
|
+
expected_output
|
252
|
+
).in_color(color_enabled)
|
245
253
|
end
|
246
254
|
end
|
247
255
|
end
|
@@ -260,35 +268,37 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
260
268
|
MESSAGE
|
261
269
|
expect { raise(actual_message) }.to raise_error(expected_message)
|
262
270
|
TEST
|
263
|
-
program =
|
264
|
-
snippet,
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
271
|
+
program =
|
272
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
273
|
+
|
274
|
+
expected_output =
|
275
|
+
build_expected_output(
|
276
|
+
color_enabled: color_enabled,
|
277
|
+
snippet:
|
278
|
+
"expect { raise(actual_message) }.to raise_error(expected_message)",
|
279
|
+
expectation:
|
280
|
+
proc do
|
281
|
+
line do
|
282
|
+
plain "Expected raised exception "
|
283
|
+
actual %|#<RuntimeError "This is fun\\nSo is this">|
|
284
|
+
end
|
285
|
+
|
286
|
+
line do
|
287
|
+
plain " to match "
|
288
|
+
expected %|a kind of Exception with message "This is fun\\nAnd so is this"|
|
289
|
+
end
|
290
|
+
end,
|
291
|
+
diff:
|
292
|
+
proc do
|
293
|
+
plain_line %| This is fun\\n|
|
294
|
+
expected_line "- And so is this"
|
295
|
+
actual_line "+ So is this"
|
296
|
+
end
|
297
|
+
)
|
298
|
+
|
299
|
+
expect(program).to produce_output_when_run(
|
300
|
+
expected_output
|
301
|
+
).in_color(color_enabled)
|
292
302
|
end
|
293
303
|
end
|
294
304
|
end
|
@@ -296,105 +306,113 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
296
306
|
end
|
297
307
|
|
298
308
|
context "when the block raises no error" do
|
299
|
-
context "when the message is short" do
|
309
|
+
context "when the expected message is short" do
|
300
310
|
it "produces the correct failure message" do
|
301
311
|
as_both_colored_and_uncolored do |color_enabled|
|
302
312
|
snippet = <<~TEST.strip
|
303
313
|
expect { }.to raise_error('hell')
|
304
314
|
TEST
|
305
|
-
program =
|
306
|
-
snippet,
|
307
|
-
color_enabled: color_enabled,
|
308
|
-
)
|
315
|
+
program =
|
316
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
309
317
|
|
310
|
-
expected_output =
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
318
|
+
expected_output =
|
319
|
+
build_expected_output(
|
320
|
+
color_enabled: color_enabled,
|
321
|
+
snippet: "expect { }.to raise_error('hell')",
|
322
|
+
expectation:
|
323
|
+
proc do
|
324
|
+
line do
|
325
|
+
plain "Expected "
|
326
|
+
actual "exception-free block"
|
327
|
+
plain " to raise "
|
328
|
+
expected %|a kind of Exception with message "hell"|
|
329
|
+
plain "."
|
330
|
+
end
|
331
|
+
end
|
332
|
+
)
|
321
333
|
|
322
|
-
expect(program).
|
323
|
-
|
324
|
-
|
334
|
+
expect(program).to produce_output_when_run(
|
335
|
+
expected_output
|
336
|
+
).in_color(color_enabled)
|
325
337
|
end
|
326
338
|
end
|
327
|
-
|
328
339
|
end
|
329
340
|
|
330
|
-
context "when the message is long" do
|
341
|
+
context "when the expected message is long" do
|
331
342
|
context "but contains no line breaks" do
|
332
343
|
it "produces the correct failure message" do
|
333
344
|
as_both_colored_and_uncolored do |color_enabled|
|
334
345
|
snippet = <<~TEST.strip
|
335
346
|
expect { }.to raise_error("this is a super super super super super super long message")
|
336
347
|
TEST
|
337
|
-
program =
|
338
|
-
snippet,
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
348
|
+
program =
|
349
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
350
|
+
|
351
|
+
expected_output =
|
352
|
+
build_expected_output(
|
353
|
+
color_enabled: color_enabled,
|
354
|
+
snippet:
|
355
|
+
%|expect { }.to raise_error("this is a super super super super super super long message")|,
|
356
|
+
newline_before_expectation: true,
|
357
|
+
expectation:
|
358
|
+
proc do
|
359
|
+
# stree-ignore
|
360
|
+
line do
|
361
|
+
plain "Expected "
|
362
|
+
actual "exception-free block"
|
363
|
+
end
|
364
|
+
|
365
|
+
line do
|
366
|
+
plain "to raise "
|
367
|
+
expected %|a kind of Exception with message "this is a super super super super super super long message"|
|
368
|
+
end
|
369
|
+
end
|
370
|
+
)
|
371
|
+
|
372
|
+
expect(program).to produce_output_when_run(
|
373
|
+
expected_output
|
374
|
+
).in_color(color_enabled)
|
362
375
|
end
|
363
376
|
end
|
364
377
|
end
|
365
378
|
|
366
379
|
context "but contains line breaks" do
|
367
|
-
it "produces the correct failure message
|
380
|
+
it "produces the correct failure message" do
|
368
381
|
as_both_colored_and_uncolored do |color_enabled|
|
369
382
|
snippet = <<~TEST.strip
|
370
|
-
|
371
|
-
|
383
|
+
expected_message = <<\~MESSAGE.rstrip
|
384
|
+
this is a super super
|
385
|
+
super super super
|
386
|
+
super long message
|
387
|
+
MESSAGE
|
388
|
+
expect { }.to raise_error(expected_message)
|
372
389
|
TEST
|
373
|
-
program =
|
374
|
-
snippet,
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
390
|
+
program =
|
391
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
392
|
+
|
393
|
+
expected_output =
|
394
|
+
build_expected_output(
|
395
|
+
color_enabled: color_enabled,
|
396
|
+
snippet: "expect { }.to raise_error(expected_message)",
|
397
|
+
newline_before_expectation: true,
|
398
|
+
expectation:
|
399
|
+
proc do
|
400
|
+
# stree-ignore
|
401
|
+
line do
|
402
|
+
plain "Expected "
|
403
|
+
actual "exception-free block"
|
404
|
+
end
|
405
|
+
|
406
|
+
line do
|
407
|
+
plain "to raise "
|
408
|
+
expected %|a kind of Exception with message "this is a super super\\nsuper super super\\nsuper long message"|
|
409
|
+
end
|
410
|
+
end
|
411
|
+
)
|
412
|
+
|
413
|
+
expect(program).to produce_output_when_run(
|
414
|
+
expected_output
|
415
|
+
).in_color(color_enabled)
|
398
416
|
end
|
399
417
|
end
|
400
418
|
end
|
@@ -403,39 +421,39 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
403
421
|
end
|
404
422
|
|
405
423
|
context "when used in the negative" do
|
406
|
-
context "when the message is short" do
|
424
|
+
context "when the expected and/or actual message is short" do
|
407
425
|
it "produces the correct failure message" do
|
408
426
|
as_both_colored_and_uncolored do |color_enabled|
|
409
427
|
snippet = <<~TEST.strip
|
410
428
|
expect { raise 'boo' }.not_to raise_error('boo')
|
411
429
|
TEST
|
412
|
-
program =
|
413
|
-
snippet,
|
414
|
-
color_enabled: color_enabled,
|
415
|
-
)
|
430
|
+
program =
|
431
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
416
432
|
|
417
|
-
expected_output =
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
433
|
+
expected_output =
|
434
|
+
build_expected_output(
|
435
|
+
color_enabled: color_enabled,
|
436
|
+
snippet: "expect { raise 'boo' }.not_to raise_error('boo')",
|
437
|
+
expectation:
|
438
|
+
proc do
|
439
|
+
line do
|
440
|
+
plain "Expected raised exception "
|
441
|
+
actual %|#<RuntimeError "boo">|
|
442
|
+
plain " not to match "
|
443
|
+
expected %|a kind of Exception with message "boo"|
|
444
|
+
plain "."
|
445
|
+
end
|
446
|
+
end
|
447
|
+
)
|
430
448
|
|
431
|
-
expect(program).
|
432
|
-
|
433
|
-
|
449
|
+
expect(program).to produce_output_when_run(
|
450
|
+
expected_output
|
451
|
+
).in_color(color_enabled)
|
434
452
|
end
|
435
453
|
end
|
436
454
|
end
|
437
455
|
|
438
|
-
context "when the message is long" do
|
456
|
+
context "when the expected and/or actual message is long" do
|
439
457
|
context "but contains no line breaks" do
|
440
458
|
it "produces the correct failure message" do
|
441
459
|
as_both_colored_and_uncolored do |color_enabled|
|
@@ -443,31 +461,32 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
443
461
|
message = "some really long message"
|
444
462
|
expect { raise(message) }.not_to raise_error(message)
|
445
463
|
TEST
|
446
|
-
program =
|
447
|
-
snippet,
|
448
|
-
color_enabled: color_enabled,
|
449
|
-
)
|
450
|
-
|
451
|
-
expected_output = build_expected_output(
|
452
|
-
color_enabled: color_enabled,
|
453
|
-
snippet: %|expect { raise(message) }.not_to raise_error(message)|,
|
454
|
-
newline_before_expectation: true,
|
455
|
-
expectation: proc {
|
456
|
-
line do
|
457
|
-
plain %|Expected raised exception |
|
458
|
-
actual %|#<RuntimeError "some really long message">|
|
459
|
-
end
|
464
|
+
program =
|
465
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
460
466
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
+
expected_output =
|
468
|
+
build_expected_output(
|
469
|
+
color_enabled: color_enabled,
|
470
|
+
snippet:
|
471
|
+
"expect { raise(message) }.not_to raise_error(message)",
|
472
|
+
newline_before_expectation: true,
|
473
|
+
expectation:
|
474
|
+
proc do
|
475
|
+
line do
|
476
|
+
plain "Expected raised exception "
|
477
|
+
actual %|#<RuntimeError "some really long message">|
|
478
|
+
end
|
479
|
+
|
480
|
+
line do
|
481
|
+
plain " not to match "
|
482
|
+
expected %|a kind of Exception with message "some really long message"|
|
483
|
+
end
|
484
|
+
end
|
485
|
+
)
|
467
486
|
|
468
|
-
expect(program).
|
469
|
-
|
470
|
-
|
487
|
+
expect(program).to produce_output_when_run(
|
488
|
+
expected_output
|
489
|
+
).in_color(color_enabled)
|
471
490
|
end
|
472
491
|
end
|
473
492
|
end
|
@@ -477,250 +496,990 @@ RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integrati
|
|
477
496
|
as_both_colored_and_uncolored do |color_enabled|
|
478
497
|
snippet = <<~TEST.strip
|
479
498
|
message = <<\~MESSAGE.rstrip
|
480
|
-
|
481
|
-
|
499
|
+
this is a super super
|
500
|
+
super super super
|
501
|
+
super long message
|
482
502
|
MESSAGE
|
483
503
|
expect { raise(message) }.not_to raise_error(message)
|
484
504
|
TEST
|
485
|
-
program =
|
486
|
-
snippet,
|
487
|
-
|
488
|
-
|
505
|
+
program =
|
506
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
507
|
+
|
508
|
+
expected_output =
|
509
|
+
build_expected_output(
|
510
|
+
color_enabled: color_enabled,
|
511
|
+
snippet:
|
512
|
+
"expect { raise(message) }.not_to raise_error(message)",
|
513
|
+
newline_before_expectation: true,
|
514
|
+
expectation:
|
515
|
+
proc do
|
516
|
+
line do
|
517
|
+
plain "Expected raised exception "
|
518
|
+
actual %|#<RuntimeError "this is a super super\\nsuper super super\\nsuper long message">|
|
519
|
+
end
|
520
|
+
|
521
|
+
line do
|
522
|
+
plain " not to match "
|
523
|
+
expected %|a kind of Exception with message "this is a super super\\nsuper super super\\nsuper long message"|
|
524
|
+
end
|
525
|
+
end
|
526
|
+
)
|
527
|
+
|
528
|
+
expect(program).to produce_output_when_run(
|
529
|
+
expected_output
|
530
|
+
).in_color(color_enabled)
|
531
|
+
end
|
532
|
+
end
|
533
|
+
end
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
context "given only a regexp message" do
|
539
|
+
context "when used in the positive" do
|
540
|
+
context "when the block raises a different error than what is given" do
|
541
|
+
it "produces the correct failure message" do
|
542
|
+
as_both_colored_and_uncolored do |color_enabled|
|
543
|
+
snippet = <<~TEST.strip
|
544
|
+
expect { raise 'boo' }.to raise_error(/hell/i)
|
545
|
+
TEST
|
546
|
+
program =
|
547
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
489
548
|
|
490
|
-
|
549
|
+
expected_output =
|
550
|
+
build_expected_output(
|
491
551
|
color_enabled: color_enabled,
|
492
|
-
snippet:
|
552
|
+
snippet: "expect { raise 'boo' }.to raise_error(/hell/i)",
|
493
553
|
newline_before_expectation: true,
|
494
|
-
expectation:
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
554
|
+
expectation:
|
555
|
+
proc do
|
556
|
+
line do
|
557
|
+
plain "Expected raised exception "
|
558
|
+
actual %|#<RuntimeError "boo">|
|
559
|
+
end
|
499
560
|
|
500
|
-
|
501
|
-
|
502
|
-
|
561
|
+
line do
|
562
|
+
plain " to match "
|
563
|
+
expected "a kind of Exception with message matching /hell/i"
|
564
|
+
end
|
503
565
|
end
|
504
|
-
},
|
505
566
|
)
|
506
567
|
|
507
|
-
|
508
|
-
|
509
|
-
|
568
|
+
expect(program).to produce_output_when_run(
|
569
|
+
expected_output
|
570
|
+
).in_color(color_enabled)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
context "when the block raises no error" do
|
576
|
+
context "when the expected message is short" do
|
577
|
+
it "produces the correct failure message" do
|
578
|
+
as_both_colored_and_uncolored do |color_enabled|
|
579
|
+
snippet = <<~TEST.strip
|
580
|
+
expect { }.to raise_error(/hell/i)
|
581
|
+
TEST
|
582
|
+
program =
|
583
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
584
|
+
|
585
|
+
expected_output =
|
586
|
+
build_expected_output(
|
587
|
+
color_enabled: color_enabled,
|
588
|
+
snippet: "expect { }.to raise_error(/hell/i)",
|
589
|
+
expectation:
|
590
|
+
proc do
|
591
|
+
line do
|
592
|
+
plain "Expected "
|
593
|
+
actual "exception-free block"
|
594
|
+
plain " to raise "
|
595
|
+
expected "a kind of Exception with message matching /hell/i"
|
596
|
+
plain "."
|
597
|
+
end
|
598
|
+
end
|
599
|
+
)
|
600
|
+
|
601
|
+
expect(program).to produce_output_when_run(
|
602
|
+
expected_output
|
603
|
+
).in_color(color_enabled)
|
510
604
|
end
|
511
605
|
end
|
512
606
|
end
|
607
|
+
|
608
|
+
context "when the expected message is long" do
|
609
|
+
it "produces the correct failure message" do
|
610
|
+
as_both_colored_and_uncolored do |color_enabled|
|
611
|
+
snippet = <<~TEST.strip
|
612
|
+
expect { }.to raise_error(/this is a super super super super super super long message/i)
|
613
|
+
TEST
|
614
|
+
program =
|
615
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
616
|
+
|
617
|
+
expected_output =
|
618
|
+
build_expected_output(
|
619
|
+
color_enabled: color_enabled,
|
620
|
+
snippet:
|
621
|
+
"expect { }.to raise_error(/this is a super super super super super super long message/i)",
|
622
|
+
newline_before_expectation: true,
|
623
|
+
expectation:
|
624
|
+
proc do
|
625
|
+
line do
|
626
|
+
plain "Expected "
|
627
|
+
actual "exception-free block"
|
628
|
+
end
|
629
|
+
|
630
|
+
line do
|
631
|
+
plain "to raise "
|
632
|
+
expected "a kind of Exception with message matching /this is a super super super super super super long message/i"
|
633
|
+
end
|
634
|
+
end
|
635
|
+
)
|
636
|
+
|
637
|
+
expect(program).to produce_output_when_run(
|
638
|
+
expected_output
|
639
|
+
).in_color(color_enabled)
|
640
|
+
end
|
641
|
+
end
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
context "when used in the negative" do
|
647
|
+
it "produces the correct failure message" do
|
648
|
+
as_both_colored_and_uncolored do |color_enabled|
|
649
|
+
snippet = <<~TEST.strip
|
650
|
+
expect { raise 'boo' }.not_to raise_error(/boo/i)
|
651
|
+
TEST
|
652
|
+
program =
|
653
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
654
|
+
|
655
|
+
expected_output =
|
656
|
+
build_expected_output(
|
657
|
+
color_enabled: color_enabled,
|
658
|
+
snippet: "expect { raise 'boo' }.not_to raise_error(/boo/i)",
|
659
|
+
newline_before_expectation: true,
|
660
|
+
expectation:
|
661
|
+
proc do
|
662
|
+
line do
|
663
|
+
plain "Expected raised exception "
|
664
|
+
actual %|#<RuntimeError "boo">|
|
665
|
+
end
|
666
|
+
|
667
|
+
line do
|
668
|
+
plain " not to match "
|
669
|
+
expected "a kind of Exception with message matching /boo/i"
|
670
|
+
end
|
671
|
+
end
|
672
|
+
)
|
673
|
+
|
674
|
+
expect(program).to produce_output_when_run(expected_output).in_color(
|
675
|
+
color_enabled
|
676
|
+
)
|
677
|
+
end
|
513
678
|
end
|
514
679
|
end
|
515
680
|
end
|
516
681
|
|
517
|
-
context "
|
682
|
+
context "given both an exception class and string message" do
|
518
683
|
context "when used in the positive" do
|
519
684
|
context "when the block raises a different error than what is given" do
|
520
|
-
context "when the message is short" do
|
685
|
+
context "when the expected and/or actual message is short" do
|
521
686
|
it "produces the correct failure message" do
|
522
687
|
as_both_colored_and_uncolored do |color_enabled|
|
523
688
|
snippet = <<~TEST.strip
|
524
689
|
block = -> { raise StandardError.new('a') }
|
525
690
|
expect(&block).to raise_error(RuntimeError, 'b')
|
526
691
|
TEST
|
527
|
-
program =
|
528
|
-
snippet,
|
529
|
-
color_enabled: color_enabled,
|
530
|
-
)
|
692
|
+
program =
|
693
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
531
694
|
|
532
|
-
expected_output =
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
695
|
+
expected_output =
|
696
|
+
build_expected_output(
|
697
|
+
color_enabled: color_enabled,
|
698
|
+
snippet: "expect(&block).to raise_error(RuntimeError, 'b')",
|
699
|
+
expectation:
|
700
|
+
proc do
|
701
|
+
line do
|
702
|
+
plain "Expected raised exception "
|
703
|
+
actual %|#<StandardError "a">|
|
704
|
+
plain " to match "
|
705
|
+
expected %|a kind of RuntimeError with message "b"|
|
706
|
+
plain "."
|
707
|
+
end
|
708
|
+
end
|
709
|
+
)
|
545
710
|
|
546
|
-
expect(program).
|
547
|
-
|
548
|
-
|
711
|
+
expect(program).to produce_output_when_run(
|
712
|
+
expected_output
|
713
|
+
).in_color(color_enabled)
|
549
714
|
end
|
550
715
|
end
|
551
716
|
end
|
552
717
|
|
553
|
-
context "when the message is long" do
|
718
|
+
context "when the expected and/or actual message is long" do
|
554
719
|
it "produces the correct failure message" do
|
555
720
|
as_both_colored_and_uncolored do |color_enabled|
|
556
721
|
snippet = <<~TEST.strip
|
557
722
|
block = -> { raise StandardError.new('this is a long message') }
|
558
723
|
expect(&block).to raise_error(RuntimeError, 'this is another long message')
|
559
724
|
TEST
|
560
|
-
program =
|
561
|
-
snippet,
|
562
|
-
color_enabled: color_enabled,
|
563
|
-
)
|
725
|
+
program =
|
726
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
564
727
|
|
565
|
-
expected_output =
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
728
|
+
expected_output =
|
729
|
+
build_expected_output(
|
730
|
+
color_enabled: color_enabled,
|
731
|
+
snippet:
|
732
|
+
"expect(&block).to raise_error(RuntimeError, 'this is another long message')",
|
733
|
+
newline_before_expectation: true,
|
734
|
+
expectation:
|
735
|
+
proc do
|
736
|
+
line do
|
737
|
+
plain "Expected raised exception "
|
738
|
+
actual %|#<StandardError "this is a long message">|
|
739
|
+
end
|
740
|
+
|
741
|
+
line do
|
742
|
+
plain " to match "
|
743
|
+
expected %|a kind of RuntimeError with message "this is another long message"|
|
744
|
+
end
|
745
|
+
end
|
746
|
+
)
|
581
747
|
|
582
|
-
expect(program).
|
583
|
-
|
584
|
-
|
748
|
+
expect(program).to produce_output_when_run(
|
749
|
+
expected_output
|
750
|
+
).in_color(color_enabled)
|
585
751
|
end
|
586
752
|
end
|
587
753
|
end
|
588
754
|
end
|
589
755
|
|
590
756
|
context "when the block raises no error" do
|
591
|
-
context "when the message is short" do
|
757
|
+
context "when the expected message is short" do
|
592
758
|
it "produces the correct failure message" do
|
593
759
|
as_both_colored_and_uncolored do |color_enabled|
|
594
760
|
snippet = <<~TEST.strip
|
595
761
|
expect { }.to raise_error(RuntimeError, 'b')
|
596
762
|
TEST
|
597
|
-
program =
|
598
|
-
snippet,
|
599
|
-
color_enabled: color_enabled,
|
600
|
-
)
|
763
|
+
program =
|
764
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
601
765
|
|
602
|
-
expected_output =
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
766
|
+
expected_output =
|
767
|
+
build_expected_output(
|
768
|
+
color_enabled: color_enabled,
|
769
|
+
snippet: "expect { }.to raise_error(RuntimeError, 'b')",
|
770
|
+
expectation:
|
771
|
+
proc do
|
772
|
+
line do
|
773
|
+
plain "Expected "
|
774
|
+
actual "exception-free block"
|
775
|
+
plain " to raise "
|
776
|
+
expected %|a kind of RuntimeError with message "b"|
|
777
|
+
plain "."
|
778
|
+
end
|
779
|
+
end
|
780
|
+
)
|
613
781
|
|
614
|
-
expect(program).
|
615
|
-
|
616
|
-
|
782
|
+
expect(program).to produce_output_when_run(
|
783
|
+
expected_output
|
784
|
+
).in_color(color_enabled)
|
617
785
|
end
|
618
786
|
end
|
619
787
|
end
|
620
788
|
|
621
|
-
context "when the message is long" do
|
789
|
+
context "when the expected message is long" do
|
622
790
|
it "produces the correct failure message" do
|
623
791
|
as_both_colored_and_uncolored do |color_enabled|
|
624
792
|
snippet = <<~TEST.strip
|
625
793
|
expect { }.to raise_error(RuntimeError, 'this is a super super super super super super long message')
|
626
794
|
TEST
|
627
|
-
program =
|
628
|
-
snippet,
|
629
|
-
color_enabled: color_enabled,
|
630
|
-
)
|
795
|
+
program =
|
796
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
631
797
|
|
632
|
-
expected_output =
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
798
|
+
expected_output =
|
799
|
+
build_expected_output(
|
800
|
+
color_enabled: color_enabled,
|
801
|
+
snippet:
|
802
|
+
"expect { }.to raise_error(RuntimeError, 'this is a super super super super super super long message')",
|
803
|
+
newline_before_expectation: true,
|
804
|
+
expectation:
|
805
|
+
proc do
|
806
|
+
line do
|
807
|
+
plain "Expected "
|
808
|
+
actual "exception-free block"
|
809
|
+
end
|
810
|
+
|
811
|
+
line do
|
812
|
+
plain "to raise "
|
813
|
+
expected %|a kind of RuntimeError with message "this is a super super super super super super long message"|
|
814
|
+
end
|
815
|
+
end
|
816
|
+
)
|
817
|
+
|
818
|
+
expect(program).to produce_output_when_run(
|
819
|
+
expected_output
|
820
|
+
).in_color(color_enabled)
|
821
|
+
end
|
822
|
+
end
|
823
|
+
end
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
context "when used in the negative" do
|
828
|
+
it "produces the correct failure message" do
|
829
|
+
as_both_colored_and_uncolored do |color_enabled|
|
830
|
+
snippet = <<~TEST.strip
|
831
|
+
block = -> { raise StandardError.new('a') }
|
832
|
+
expect(&block).not_to raise_error(StandardError, 'a')
|
833
|
+
TEST
|
834
|
+
program =
|
835
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
836
|
+
|
837
|
+
expected_output =
|
838
|
+
build_expected_output(
|
839
|
+
color_enabled: color_enabled,
|
840
|
+
snippet: "expect(&block).not_to raise_error(StandardError, 'a')",
|
841
|
+
newline_before_expectation: true,
|
842
|
+
expectation:
|
843
|
+
proc do
|
637
844
|
line do
|
638
|
-
plain
|
639
|
-
|
845
|
+
plain "Expected raised exception "
|
846
|
+
actual %|#<StandardError "a">|
|
640
847
|
end
|
641
848
|
|
642
849
|
line do
|
643
|
-
plain
|
644
|
-
expected
|
850
|
+
plain " not to match "
|
851
|
+
expected %|a kind of StandardError with message "a"|
|
645
852
|
end
|
646
|
-
|
647
|
-
|
853
|
+
end
|
854
|
+
)
|
648
855
|
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
end
|
653
|
-
end
|
856
|
+
expect(program).to produce_output_when_run(expected_output).in_color(
|
857
|
+
color_enabled
|
858
|
+
)
|
654
859
|
end
|
655
860
|
end
|
656
861
|
end
|
862
|
+
end
|
657
863
|
|
658
|
-
|
659
|
-
|
864
|
+
context "given both an exception class and regexp message" do
|
865
|
+
context "when used in the positive" do
|
866
|
+
context "when the block raises a different error than what is given" do
|
660
867
|
it "produces the correct failure message" do
|
661
868
|
as_both_colored_and_uncolored do |color_enabled|
|
662
869
|
snippet = <<~TEST.strip
|
663
870
|
block = -> { raise StandardError.new('a') }
|
664
|
-
expect(&block).
|
871
|
+
expect(&block).to raise_error(RuntimeError, /b/i)
|
665
872
|
TEST
|
666
|
-
program =
|
667
|
-
snippet,
|
668
|
-
color_enabled: color_enabled,
|
669
|
-
)
|
873
|
+
program =
|
874
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
670
875
|
|
671
|
-
expected_output =
|
876
|
+
expected_output =
|
877
|
+
build_expected_output(
|
878
|
+
color_enabled: color_enabled,
|
879
|
+
snippet: "expect(&block).to raise_error(RuntimeError, /b/i)",
|
880
|
+
newline_before_expectation: true,
|
881
|
+
expectation:
|
882
|
+
proc do
|
883
|
+
line do
|
884
|
+
plain "Expected raised exception "
|
885
|
+
actual %|#<StandardError "a">|
|
886
|
+
end
|
887
|
+
|
888
|
+
line do
|
889
|
+
plain " to match "
|
890
|
+
expected "a kind of RuntimeError with message matching /b/i"
|
891
|
+
end
|
892
|
+
end
|
893
|
+
)
|
894
|
+
|
895
|
+
expect(program).to produce_output_when_run(
|
896
|
+
expected_output
|
897
|
+
).in_color(color_enabled)
|
898
|
+
end
|
899
|
+
end
|
900
|
+
end
|
901
|
+
|
902
|
+
context "when the block raises no error" do
|
903
|
+
context "when the expected message is short" do
|
904
|
+
it "produces the correct failure message" do
|
905
|
+
as_both_colored_and_uncolored do |color_enabled|
|
906
|
+
snippet = <<~TEST.strip
|
907
|
+
expect { }.to raise_error(RuntimeError, /b/i)
|
908
|
+
TEST
|
909
|
+
program =
|
910
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
911
|
+
|
912
|
+
expected_output =
|
913
|
+
build_expected_output(
|
914
|
+
color_enabled: color_enabled,
|
915
|
+
snippet: "expect { }.to raise_error(RuntimeError, /b/i)",
|
916
|
+
expectation:
|
917
|
+
proc do
|
918
|
+
line do
|
919
|
+
plain "Expected "
|
920
|
+
actual "exception-free block"
|
921
|
+
plain " to raise "
|
922
|
+
expected "a kind of RuntimeError with message matching /b/i"
|
923
|
+
end
|
924
|
+
end
|
925
|
+
)
|
926
|
+
|
927
|
+
expect(program).to produce_output_when_run(
|
928
|
+
expected_output
|
929
|
+
).in_color(color_enabled)
|
930
|
+
end
|
931
|
+
end
|
932
|
+
end
|
933
|
+
|
934
|
+
context "when the expected message is long" do
|
935
|
+
it "produces the correct failure message" do
|
936
|
+
as_both_colored_and_uncolored do |color_enabled|
|
937
|
+
snippet = <<~TEST.strip
|
938
|
+
expect { }.to raise_error(RuntimeError, /this is a super super super super super super long message/i)
|
939
|
+
TEST
|
940
|
+
program =
|
941
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
942
|
+
|
943
|
+
expected_output =
|
944
|
+
build_expected_output(
|
945
|
+
color_enabled: color_enabled,
|
946
|
+
snippet:
|
947
|
+
"expect { }.to raise_error(RuntimeError, /this is a super super super super super super long message/i)",
|
948
|
+
newline_before_expectation: true,
|
949
|
+
expectation:
|
950
|
+
proc do
|
951
|
+
line do
|
952
|
+
plain "Expected "
|
953
|
+
actual "exception-free block"
|
954
|
+
end
|
955
|
+
|
956
|
+
line do
|
957
|
+
plain "to raise "
|
958
|
+
expected "a kind of RuntimeError with message matching /this is a super super super super super super long message/i"
|
959
|
+
end
|
960
|
+
end
|
961
|
+
)
|
962
|
+
|
963
|
+
expect(program).to produce_output_when_run(
|
964
|
+
expected_output
|
965
|
+
).in_color(color_enabled)
|
966
|
+
end
|
967
|
+
end
|
968
|
+
end
|
969
|
+
end
|
970
|
+
end
|
971
|
+
|
972
|
+
context "when used in the negative" do
|
973
|
+
it "produces the correct failure message" do
|
974
|
+
as_both_colored_and_uncolored do |color_enabled|
|
975
|
+
snippet = <<~TEST.strip
|
976
|
+
block = -> { raise StandardError.new('a') }
|
977
|
+
expect(&block).not_to raise_error(StandardError, /a/i)
|
978
|
+
TEST
|
979
|
+
program =
|
980
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
981
|
+
|
982
|
+
expected_output =
|
983
|
+
build_expected_output(
|
672
984
|
color_enabled: color_enabled,
|
673
|
-
snippet:
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
985
|
+
snippet: "expect(&block).not_to raise_error(StandardError, /a/i)",
|
986
|
+
newline_before_expectation: true,
|
987
|
+
expectation:
|
988
|
+
proc do
|
989
|
+
line do
|
990
|
+
plain "Expected raised exception "
|
991
|
+
actual %|#<StandardError "a">|
|
992
|
+
end
|
993
|
+
|
994
|
+
line do
|
995
|
+
plain " not to match "
|
996
|
+
expected "a kind of StandardError with message matching /a/i"
|
997
|
+
end
|
681
998
|
end
|
682
|
-
},
|
683
999
|
)
|
684
1000
|
|
685
|
-
|
686
|
-
|
687
|
-
|
1001
|
+
expect(program).to produce_output_when_run(expected_output).in_color(
|
1002
|
+
color_enabled
|
1003
|
+
)
|
1004
|
+
end
|
1005
|
+
end
|
1006
|
+
end
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
context "given a simple RSpec matcher" do
|
1010
|
+
context "when used in the positive" do
|
1011
|
+
context "when the block raises a different error than what is given" do
|
1012
|
+
context "when the expected error and/or actual message is short" do
|
1013
|
+
it "produces the correct failure message" do
|
1014
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1015
|
+
snippet = <<~TEST.strip
|
1016
|
+
expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array))
|
1017
|
+
TEST
|
1018
|
+
program =
|
1019
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1020
|
+
|
1021
|
+
expected_output =
|
1022
|
+
build_expected_output(
|
1023
|
+
color_enabled: color_enabled,
|
1024
|
+
snippet:
|
1025
|
+
"expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array))",
|
1026
|
+
expectation:
|
1027
|
+
proc do
|
1028
|
+
line do
|
1029
|
+
plain "Expected raised exception "
|
1030
|
+
actual %|#<StandardError "boo">|
|
1031
|
+
plain " to match "
|
1032
|
+
expected "#<a kind of Array>"
|
1033
|
+
plain "."
|
1034
|
+
end
|
1035
|
+
end
|
1036
|
+
)
|
1037
|
+
|
1038
|
+
expect(program).to produce_output_when_run(
|
1039
|
+
expected_output
|
1040
|
+
).in_color(color_enabled)
|
1041
|
+
end
|
1042
|
+
end
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
context "when the expected error and/or actual message is long" do
|
1046
|
+
it "produces the correct failure message" do
|
1047
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1048
|
+
snippet = <<~TEST.strip
|
1049
|
+
expect { raise StandardError.new('this is a super super super long message') }.to raise_error(a_kind_of(RuntimeError))
|
1050
|
+
TEST
|
1051
|
+
program =
|
1052
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1053
|
+
|
1054
|
+
expected_output =
|
1055
|
+
build_expected_output(
|
1056
|
+
color_enabled: color_enabled,
|
1057
|
+
snippet:
|
1058
|
+
"expect { raise StandardError.new('this is a super super super long message') }.to raise_error(a_kind_of(RuntimeError))",
|
1059
|
+
newline_before_expectation: true,
|
1060
|
+
expectation:
|
1061
|
+
proc do
|
1062
|
+
line do
|
1063
|
+
plain "Expected raised exception "
|
1064
|
+
actual %|#<StandardError "this is a super super super long message">|
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
line do
|
1068
|
+
plain " to match "
|
1069
|
+
expected "#<a kind of RuntimeError>"
|
1070
|
+
end
|
1071
|
+
end
|
1072
|
+
)
|
1073
|
+
|
1074
|
+
expect(program).to produce_output_when_run(
|
1075
|
+
expected_output
|
1076
|
+
).in_color(color_enabled)
|
1077
|
+
end
|
1078
|
+
end
|
1079
|
+
end
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
context "when the block raises no error" do
|
1083
|
+
it "produces the correct failure message" do
|
1084
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1085
|
+
snippet = <<~TEST.strip
|
1086
|
+
expect { }.to raise_error(a_kind_of(RuntimeError))
|
1087
|
+
TEST
|
1088
|
+
program =
|
1089
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1090
|
+
|
1091
|
+
expected_output =
|
1092
|
+
build_expected_output(
|
1093
|
+
color_enabled: color_enabled,
|
1094
|
+
snippet: "expect { }.to raise_error(a_kind_of(RuntimeError))",
|
1095
|
+
expectation:
|
1096
|
+
proc do
|
1097
|
+
line do
|
1098
|
+
plain "Expected "
|
1099
|
+
actual "exception-free block"
|
1100
|
+
plain " to raise "
|
1101
|
+
expected "#<a kind of RuntimeError>"
|
1102
|
+
plain "."
|
1103
|
+
end
|
1104
|
+
end
|
1105
|
+
)
|
1106
|
+
|
1107
|
+
expect(program).to produce_output_when_run(
|
1108
|
+
expected_output
|
1109
|
+
).in_color(color_enabled)
|
688
1110
|
end
|
689
1111
|
end
|
690
1112
|
end
|
1113
|
+
end
|
691
1114
|
|
692
|
-
|
1115
|
+
context "when used in the negative" do
|
1116
|
+
context "when the expected error and/or actual message is short" do
|
693
1117
|
it "produces the correct failure message" do
|
694
1118
|
as_both_colored_and_uncolored do |color_enabled|
|
695
1119
|
snippet = <<~TEST.strip
|
696
|
-
|
697
|
-
expect(&block).not_to raise_error(StandardError, 'this is a long message')
|
1120
|
+
expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError))
|
698
1121
|
TEST
|
699
|
-
program =
|
700
|
-
snippet,
|
1122
|
+
program =
|
1123
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1124
|
+
|
1125
|
+
expected_output =
|
1126
|
+
build_expected_output(
|
1127
|
+
color_enabled: color_enabled,
|
1128
|
+
snippet:
|
1129
|
+
"expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError))",
|
1130
|
+
expectation:
|
1131
|
+
proc do
|
1132
|
+
line do
|
1133
|
+
plain "Expected raised exception "
|
1134
|
+
actual %|#<StandardError "boo">|
|
1135
|
+
plain " not to match "
|
1136
|
+
expected "#<a kind of StandardError>"
|
1137
|
+
plain "."
|
1138
|
+
end
|
1139
|
+
end
|
1140
|
+
)
|
1141
|
+
|
1142
|
+
expect(program).to produce_output_when_run(
|
1143
|
+
expected_output
|
1144
|
+
).in_color(color_enabled)
|
1145
|
+
end
|
1146
|
+
end
|
1147
|
+
end
|
1148
|
+
|
1149
|
+
context "when the expected error and/or actual message is long" do
|
1150
|
+
it "produces the correct failure message" do
|
1151
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1152
|
+
snippet = <<~TEST.strip
|
1153
|
+
expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError))
|
1154
|
+
TEST
|
1155
|
+
program =
|
1156
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1157
|
+
|
1158
|
+
expected_output =
|
1159
|
+
build_expected_output(
|
1160
|
+
color_enabled: color_enabled,
|
1161
|
+
snippet:
|
1162
|
+
"expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError))",
|
1163
|
+
newline_before_expectation: true,
|
1164
|
+
expectation:
|
1165
|
+
proc do
|
1166
|
+
line do
|
1167
|
+
plain "Expected raised exception "
|
1168
|
+
actual %|#<StandardError "this is a super super long message">|
|
1169
|
+
end
|
1170
|
+
|
1171
|
+
line do
|
1172
|
+
plain " not to match "
|
1173
|
+
expected "#<a kind of StandardError>"
|
1174
|
+
end
|
1175
|
+
end
|
1176
|
+
)
|
1177
|
+
|
1178
|
+
expect(program).to produce_output_when_run(
|
1179
|
+
expected_output
|
1180
|
+
).in_color(color_enabled)
|
1181
|
+
end
|
1182
|
+
end
|
1183
|
+
end
|
1184
|
+
end
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
context "given only a simple RSpec matcher and string message" do
|
1188
|
+
context "when used in the positive" do
|
1189
|
+
context "when the block raises a different error than what is given" do
|
1190
|
+
it "produces the correct failure message" do
|
1191
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1192
|
+
snippet = <<~TEST.strip
|
1193
|
+
expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), "boo")
|
1194
|
+
TEST
|
1195
|
+
program =
|
1196
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1197
|
+
|
1198
|
+
expected_output =
|
1199
|
+
build_expected_output(
|
1200
|
+
color_enabled: color_enabled,
|
1201
|
+
snippet:
|
1202
|
+
%|expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), "boo")|,
|
1203
|
+
newline_before_expectation: true,
|
1204
|
+
expectation:
|
1205
|
+
proc do
|
1206
|
+
line do
|
1207
|
+
plain "Expected raised exception "
|
1208
|
+
actual %|#<StandardError "boo">|
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
line do
|
1212
|
+
plain " to match "
|
1213
|
+
expected %|#<a kind of RuntimeError> with message "boo"|
|
1214
|
+
end
|
1215
|
+
end
|
1216
|
+
)
|
1217
|
+
|
1218
|
+
expect(program).to produce_output_when_run(
|
1219
|
+
expected_output
|
1220
|
+
).in_color(color_enabled)
|
1221
|
+
end
|
1222
|
+
end
|
1223
|
+
end
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
context "when used in the negative" do
|
1227
|
+
it "produces the correct failure message" do
|
1228
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1229
|
+
snippet = <<~TEST.strip
|
1230
|
+
expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), "boo")
|
1231
|
+
TEST
|
1232
|
+
program =
|
1233
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1234
|
+
|
1235
|
+
expected_output =
|
1236
|
+
build_expected_output(
|
701
1237
|
color_enabled: color_enabled,
|
1238
|
+
snippet:
|
1239
|
+
%|expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), "boo")|,
|
1240
|
+
newline_before_expectation: true,
|
1241
|
+
expectation:
|
1242
|
+
proc do
|
1243
|
+
line do
|
1244
|
+
plain "Expected raised exception "
|
1245
|
+
actual %|#<StandardError "boo">|
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
line do
|
1249
|
+
plain " not to match "
|
1250
|
+
expected %|#<a kind of StandardError> with message "boo"|
|
1251
|
+
end
|
1252
|
+
end
|
702
1253
|
)
|
703
1254
|
|
704
|
-
|
1255
|
+
expect(program).to produce_output_when_run(expected_output).in_color(
|
1256
|
+
color_enabled
|
1257
|
+
)
|
1258
|
+
end
|
1259
|
+
end
|
1260
|
+
end
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
context "given only a simple RSpec matcher and regexp message" do
|
1264
|
+
context "when used in the positive" do
|
1265
|
+
context "when the block raises a different error than what is given" do
|
1266
|
+
it "produces the correct failure message" do
|
1267
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1268
|
+
snippet = <<~TEST.strip
|
1269
|
+
expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), /boo/i)
|
1270
|
+
TEST
|
1271
|
+
program =
|
1272
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1273
|
+
|
1274
|
+
expected_output =
|
1275
|
+
build_expected_output(
|
1276
|
+
color_enabled: color_enabled,
|
1277
|
+
snippet:
|
1278
|
+
"expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(RuntimeError), /boo/i)",
|
1279
|
+
newline_before_expectation: true,
|
1280
|
+
expectation:
|
1281
|
+
proc do
|
1282
|
+
line do
|
1283
|
+
plain "Expected raised exception "
|
1284
|
+
actual %|#<StandardError "boo">|
|
1285
|
+
end
|
1286
|
+
|
1287
|
+
line do
|
1288
|
+
plain " to match "
|
1289
|
+
expected "#<a kind of RuntimeError> with message matching /boo/i"
|
1290
|
+
end
|
1291
|
+
end
|
1292
|
+
)
|
1293
|
+
|
1294
|
+
expect(program).to produce_output_when_run(
|
1295
|
+
expected_output
|
1296
|
+
).in_color(color_enabled)
|
1297
|
+
end
|
1298
|
+
end
|
1299
|
+
end
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
context "when used in the negative" do
|
1303
|
+
it "produces the correct failure message" do
|
1304
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1305
|
+
snippet = <<~TEST.strip
|
1306
|
+
expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), /boo/i)
|
1307
|
+
TEST
|
1308
|
+
program =
|
1309
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1310
|
+
|
1311
|
+
expected_output =
|
1312
|
+
build_expected_output(
|
705
1313
|
color_enabled: color_enabled,
|
706
|
-
snippet:
|
1314
|
+
snippet:
|
1315
|
+
"expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError), /boo/i)",
|
707
1316
|
newline_before_expectation: true,
|
708
|
-
expectation:
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
1317
|
+
expectation:
|
1318
|
+
proc do
|
1319
|
+
line do
|
1320
|
+
plain "Expected raised exception "
|
1321
|
+
actual %|#<StandardError "boo">|
|
1322
|
+
end
|
713
1323
|
|
714
|
-
|
715
|
-
|
716
|
-
|
1324
|
+
line do
|
1325
|
+
plain " not to match "
|
1326
|
+
expected "#<a kind of StandardError> with message matching /boo/i"
|
1327
|
+
end
|
717
1328
|
end
|
718
|
-
},
|
719
1329
|
)
|
720
1330
|
|
721
|
-
|
722
|
-
|
723
|
-
|
1331
|
+
expect(program).to produce_output_when_run(expected_output).in_color(
|
1332
|
+
color_enabled
|
1333
|
+
)
|
1334
|
+
end
|
1335
|
+
end
|
1336
|
+
end
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
# NOTE: No need to test this using a string or regexp message — we've tested
|
1340
|
+
# it enough above
|
1341
|
+
context "given a compound RSpec matcher" do
|
1342
|
+
context "when used in the positive" do
|
1343
|
+
context "when the block raises a different error than what is given" do
|
1344
|
+
context "when the expected error and/or actual message is short" do
|
1345
|
+
it "produces the correct failure message" do
|
1346
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1347
|
+
snippet = <<~TEST.strip
|
1348
|
+
expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array).or eq(true))
|
1349
|
+
TEST
|
1350
|
+
program =
|
1351
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1352
|
+
|
1353
|
+
expected_output =
|
1354
|
+
build_expected_output(
|
1355
|
+
color_enabled: color_enabled,
|
1356
|
+
snippet:
|
1357
|
+
"expect { raise StandardError.new('boo') }.to raise_error(a_kind_of(Array).or eq(true))",
|
1358
|
+
expectation:
|
1359
|
+
proc do
|
1360
|
+
line do
|
1361
|
+
plain "Expected raised exception "
|
1362
|
+
actual %|#<StandardError "boo">|
|
1363
|
+
plain " to match "
|
1364
|
+
expected "#<a kind of Array or eq true>"
|
1365
|
+
plain "."
|
1366
|
+
end
|
1367
|
+
end
|
1368
|
+
)
|
1369
|
+
|
1370
|
+
expect(program).to produce_output_when_run(
|
1371
|
+
expected_output
|
1372
|
+
).in_color(color_enabled)
|
1373
|
+
end
|
1374
|
+
end
|
1375
|
+
end
|
1376
|
+
|
1377
|
+
context "when the expected error and/or actual message is long"
|
1378
|
+
end
|
1379
|
+
|
1380
|
+
context "when the block raises no error" do
|
1381
|
+
it "produces the correct failure message" do
|
1382
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1383
|
+
snippet = <<~TEST.strip
|
1384
|
+
expect { }.to raise_error(a_kind_of(RuntimeError).and having_attributes(beep: :boop))
|
1385
|
+
TEST
|
1386
|
+
program =
|
1387
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1388
|
+
|
1389
|
+
expected_output =
|
1390
|
+
build_expected_output(
|
1391
|
+
color_enabled: color_enabled,
|
1392
|
+
snippet:
|
1393
|
+
"expect { }.to raise_error(a_kind_of(RuntimeError).and having_attributes(beep: :boop))",
|
1394
|
+
newline_before_expectation: true,
|
1395
|
+
expectation:
|
1396
|
+
proc do
|
1397
|
+
line do
|
1398
|
+
plain "Expected "
|
1399
|
+
actual "exception-free block"
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
line do
|
1403
|
+
plain "to raise "
|
1404
|
+
expected "#<a kind of RuntimeError and having attributes (beep: :boop)>"
|
1405
|
+
end
|
1406
|
+
end
|
1407
|
+
)
|
1408
|
+
|
1409
|
+
expect(program).to produce_output_when_run(
|
1410
|
+
expected_output
|
1411
|
+
).in_color(color_enabled)
|
1412
|
+
end
|
1413
|
+
end
|
1414
|
+
end
|
1415
|
+
end
|
1416
|
+
|
1417
|
+
context "when used in the negative" do
|
1418
|
+
context "when the expected and/or actual message is short" do
|
1419
|
+
it "produces the correct failure message" do
|
1420
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1421
|
+
snippet = <<~TEST.strip
|
1422
|
+
expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError).or eq(true))
|
1423
|
+
TEST
|
1424
|
+
program =
|
1425
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1426
|
+
|
1427
|
+
expected_output =
|
1428
|
+
build_expected_output(
|
1429
|
+
color_enabled: color_enabled,
|
1430
|
+
snippet:
|
1431
|
+
"expect { raise StandardError.new('boo') }.not_to raise_error(a_kind_of(StandardError).or eq(true))",
|
1432
|
+
expectation:
|
1433
|
+
proc do
|
1434
|
+
line do
|
1435
|
+
plain "Expected raised exception "
|
1436
|
+
actual %|#<StandardError "boo">|
|
1437
|
+
plain " not to match "
|
1438
|
+
expected "#<a kind of StandardError or eq true>"
|
1439
|
+
plain "."
|
1440
|
+
end
|
1441
|
+
end
|
1442
|
+
)
|
1443
|
+
|
1444
|
+
expect(program).to produce_output_when_run(
|
1445
|
+
expected_output
|
1446
|
+
).in_color(color_enabled)
|
1447
|
+
end
|
1448
|
+
end
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
context "when the expected and/or actual message is long" do
|
1452
|
+
it "produces the correct failure message" do
|
1453
|
+
as_both_colored_and_uncolored do |color_enabled|
|
1454
|
+
snippet = <<~TEST.strip
|
1455
|
+
expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError).and having_attributes(message: kind_of(String)))
|
1456
|
+
TEST
|
1457
|
+
program =
|
1458
|
+
make_plain_test_program(snippet, color_enabled: color_enabled)
|
1459
|
+
|
1460
|
+
expected_output =
|
1461
|
+
build_expected_output(
|
1462
|
+
color_enabled: color_enabled,
|
1463
|
+
snippet:
|
1464
|
+
"expect { raise StandardError.new('this is a super super long message') }.not_to raise_error(a_kind_of(StandardError).and having_attributes(message: kind_of(String)))",
|
1465
|
+
newline_before_expectation: true,
|
1466
|
+
expectation:
|
1467
|
+
proc do
|
1468
|
+
line do
|
1469
|
+
plain "Expected raised exception "
|
1470
|
+
actual %|#<StandardError "this is a super super long message">|
|
1471
|
+
end
|
1472
|
+
|
1473
|
+
line do
|
1474
|
+
plain " not to match "
|
1475
|
+
expected "#<a kind of StandardError and having attributes (message: #<a kind of String>)>"
|
1476
|
+
end
|
1477
|
+
end
|
1478
|
+
)
|
1479
|
+
|
1480
|
+
expect(program).to produce_output_when_run(
|
1481
|
+
expected_output
|
1482
|
+
).in_color(color_enabled)
|
724
1483
|
end
|
725
1484
|
end
|
726
1485
|
end
|