super_diff 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +117 -89
- data/lib/super_diff.rb +33 -47
- data/lib/super_diff/active_record.rb +41 -0
- data/lib/super_diff/active_record/diff_formatters.rb +10 -0
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +23 -0
- data/lib/super_diff/active_record/differs.rb +10 -0
- data/lib/super_diff/active_record/differs/active_record_relation.rb +30 -0
- data/lib/super_diff/active_record/object_inspection.rb +14 -0
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +38 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +18 -0
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +18 -0
- data/lib/super_diff/active_record/operation_sequences.rb +10 -0
- data/lib/super_diff/active_record/operation_sequences/active_record_relation.rb +16 -0
- data/lib/super_diff/active_record/operational_sequencers.rb +14 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_model.rb +19 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_relation.rb +24 -0
- data/lib/super_diff/active_support.rb +33 -0
- data/lib/super_diff/active_support/diff_formatters.rb +10 -0
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/differs.rb +10 -0
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/object_inspection.rb +14 -0
- data/lib/super_diff/active_support/object_inspection/inspectors.rb +12 -0
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +18 -0
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +15 -0
- data/lib/super_diff/active_support/operation_sequences.rb +10 -0
- data/lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb +16 -0
- data/lib/super_diff/active_support/operational_sequencers.rb +10 -0
- data/lib/super_diff/active_support/operational_sequencers/hash_with_indifferent_access.rb +21 -0
- data/lib/super_diff/colorized_document_extensions.rb +17 -0
- data/lib/super_diff/csi.rb +45 -15
- data/lib/super_diff/csi/bold_sequence.rb +9 -0
- data/lib/super_diff/csi/color.rb +62 -0
- data/lib/super_diff/csi/color_sequence_block.rb +28 -0
- data/lib/super_diff/csi/colorized_document.rb +72 -0
- data/lib/super_diff/csi/document.rb +183 -0
- data/lib/super_diff/csi/eight_bit_color.rb +72 -26
- data/lib/super_diff/csi/four_bit_color.rb +63 -29
- data/lib/super_diff/csi/twenty_four_bit_color.rb +79 -18
- data/lib/super_diff/csi/uncolorized_document.rb +29 -0
- data/lib/super_diff/diff_formatter.rb +10 -15
- data/lib/super_diff/diff_formatters.rb +10 -1
- data/lib/super_diff/diff_formatters/base.rb +12 -17
- data/lib/super_diff/diff_formatters/collection.rb +81 -50
- data/lib/super_diff/diff_formatters/{object.rb → custom_object.rb} +12 -9
- data/lib/super_diff/diff_formatters/default_object.rb +48 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +31 -0
- data/lib/super_diff/differ.rb +35 -32
- data/lib/super_diff/differs.rb +16 -1
- data/lib/super_diff/differs/array.rb +2 -2
- data/lib/super_diff/differs/base.rb +11 -21
- data/lib/super_diff/differs/custom_object.rb +26 -0
- data/lib/super_diff/differs/default_object.rb +25 -0
- data/lib/super_diff/differs/empty.rb +1 -1
- data/lib/super_diff/differs/hash.rb +2 -2
- data/lib/super_diff/differs/{multi_line_string.rb → multiline_string.rb} +6 -5
- data/lib/super_diff/equality_matcher.rb +9 -22
- data/lib/super_diff/equality_matchers.rb +19 -1
- data/lib/super_diff/equality_matchers/array.rb +6 -4
- data/lib/super_diff/equality_matchers/base.rb +8 -16
- data/lib/super_diff/equality_matchers/default.rb +60 -0
- data/lib/super_diff/equality_matchers/hash.rb +6 -4
- data/lib/super_diff/equality_matchers/{multi_line_string.rb → multiline_string.rb} +9 -6
- data/lib/super_diff/equality_matchers/primitive.rb +34 -0
- data/lib/super_diff/equality_matchers/{single_line_string.rb → singleline_string.rb} +7 -5
- data/lib/super_diff/helpers.rb +17 -81
- data/lib/super_diff/no_differ_available_error.rb +22 -0
- data/lib/super_diff/{errors.rb → no_operational_sequencer_available_error.rb} +0 -0
- data/lib/super_diff/object_inspection.rb +24 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +144 -0
- data/lib/super_diff/object_inspection/inspector.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors.rb +18 -0
- data/lib/super_diff/object_inspection/inspectors/array.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +47 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/object_inspection/inspectors/string.rb +13 -0
- data/lib/super_diff/object_inspection/map.rb +28 -0
- data/lib/super_diff/object_inspection/nodes.rb +49 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +86 -0
- data/lib/super_diff/object_inspection/nodes/break.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +22 -0
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +24 -0
- data/lib/super_diff/operation_sequences.rb +9 -0
- data/lib/super_diff/operation_sequences/base.rb +1 -1
- data/lib/super_diff/operation_sequences/{object.rb → custom_object.rb} +4 -3
- data/lib/super_diff/operation_sequences/default_object.rb +25 -0
- data/lib/super_diff/operational_sequencer.rb +23 -18
- data/lib/super_diff/operational_sequencers.rb +12 -1
- data/lib/super_diff/operational_sequencers/array.rb +65 -62
- data/lib/super_diff/operational_sequencers/base.rb +18 -26
- data/lib/super_diff/operational_sequencers/custom_object.rb +35 -0
- data/lib/super_diff/operational_sequencers/{object.rb → default_object.rb} +21 -11
- data/lib/super_diff/operational_sequencers/hash.rb +8 -5
- data/lib/super_diff/operational_sequencers/{multi_line_string.rb → multiline_string.rb} +11 -6
- data/lib/super_diff/operations.rb +6 -0
- data/lib/super_diff/operations/binary_operation.rb +14 -34
- data/lib/super_diff/operations/unary_operation.rb +11 -2
- data/lib/super_diff/rails.rb +1 -0
- data/lib/super_diff/recursion_guard.rb +47 -0
- data/lib/super_diff/rspec-rails.rb +2 -0
- data/lib/super_diff/rspec.rb +52 -8
- data/lib/super_diff/rspec/augmented_matcher.rb +98 -0
- data/lib/super_diff/rspec/configuration.rb +31 -0
- data/lib/super_diff/rspec/differ.rb +60 -16
- data/lib/super_diff/rspec/differs.rb +13 -0
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +23 -0
- data/lib/super_diff/rspec/differs/partial_array.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_hash.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_object.rb +22 -0
- data/lib/super_diff/rspec/matcher_text_builders.rb +24 -0
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +155 -0
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +78 -0
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +14 -0
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +23 -0
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -0
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +99 -0
- data/lib/super_diff/rspec/matcher_text_template.rb +240 -0
- data/lib/super_diff/rspec/monkey_patches.rb +601 -98
- data/lib/super_diff/rspec/object_inspection.rb +8 -0
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +24 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +22 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers.rb +22 -0
- data/lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb +97 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_array.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +32 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_object.rb +64 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +328 -46
- data/spec/integration/rails/active_record_spec.rb +19 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_matcher_spec.rb +565 -0
- data/spec/integration/rspec/be_nil_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +546 -0
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +57 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +368 -0
- data/spec/integration/rspec/eq_matcher_spec.rb +874 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +299 -0
- data/spec/integration/rspec/include_matcher_spec.rb +350 -0
- data/spec/integration/rspec/match_matcher_spec.rb +1258 -0
- data/spec/integration/rspec/raise_error_matcher_spec.rb +350 -0
- data/spec/integration/rspec/respond_to_matcher_spec.rb +994 -0
- data/spec/integration/rspec/unhandled_errors_spec.rb +94 -0
- data/spec/spec_helper.rb +19 -4
- data/spec/support/colorizer.rb +9 -0
- data/spec/support/command_runner.rb +4 -0
- data/spec/support/integration/helpers.rb +179 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +79 -41
- data/spec/support/models/a.rb +11 -0
- data/spec/support/models/active_record/person.rb +26 -0
- data/spec/support/models/active_record/shipping_address.rb +29 -0
- data/spec/support/models/customer.rb +24 -0
- data/spec/support/models/empty_class.rb +6 -0
- data/spec/support/models/item.rb +10 -0
- data/spec/support/models/order.rb +9 -0
- data/spec/support/models/person.rb +20 -0
- data/spec/support/models/player.rb +33 -0
- data/spec/support/models/shipping_address.rb +34 -0
- data/spec/support/ruby_versions.rb +7 -0
- data/spec/support/shared_examples/active_record.rb +338 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +233 -0
- data/spec/unit/equality_matcher_spec.rb +579 -171
- data/spec/unit/object_inspection_spec.rb +1092 -0
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +23 -0
- data/spec/unit/rspec/matchers/be_falsey_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_nil_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +31 -0
- data/spec/unit/rspec/matchers/be_spec.rb +17 -0
- data/spec/unit/rspec/matchers/be_truthy_spec.rb +9 -0
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +11 -0
- data/spec/unit/rspec/matchers/eq_spec.rb +9 -0
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +11 -0
- data/spec/unit/rspec/matchers/include_spec.rb +21 -0
- data/spec/unit/rspec/matchers/match_spec.rb +9 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +29 -0
- data/spec/unit/rspec/matchers/respond_to_spec.rb +78 -0
- data/super_diff.gemspec +4 -2
- metadata +231 -34
- data/lib/super_diff/csi/color_helper.rb +0 -52
- data/lib/super_diff/csi/eight_bit_sequence.rb +0 -27
- data/lib/super_diff/csi/four_bit_sequence.rb +0 -24
- data/lib/super_diff/csi/sequence.rb +0 -22
- data/lib/super_diff/csi/twenty_four_bit_sequence.rb +0 -27
- data/lib/super_diff/diff_formatters/multi_line_string.rb +0 -31
- data/lib/super_diff/differs/object.rb +0 -68
- data/lib/super_diff/equality_matchers/object.rb +0 -18
- data/lib/super_diff/value_inspection.rb +0 -11
- data/spec/integration/rspec_spec.rb +0 -261
- data/spec/support/color_helper.rb +0 -49
- data/spec/support/person.rb +0 -23
- data/spec/support/person_diff_formatter.rb +0 -15
- data/spec/support/person_operation_sequence.rb +0 -14
- data/spec/support/person_operational_sequencer.rb +0 -19
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Integration with Rails's ActiveRecord class", type: :integration do
|
4
|
+
context "when using 'super_diff/rspec-rails'" do
|
5
|
+
include_context "integration with ActiveRecord"
|
6
|
+
|
7
|
+
def make_program(test, color_enabled:)
|
8
|
+
make_rspec_rails_test_program(test, color_enabled: color_enabled)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when using 'super_diff/active_record'" do
|
13
|
+
include_context "integration with ActiveRecord"
|
14
|
+
|
15
|
+
def make_program(test, color_enabled:)
|
16
|
+
make_rspec_active_record_program(test, color_enabled: color_enabled)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Integration with Rails's HashWithIndifferentAccess", type: :integration do
|
4
|
+
context "when using 'super_diff/rspec-rails'" do
|
5
|
+
include_context "integration with HashWithIndifferentAccess"
|
6
|
+
|
7
|
+
def make_program(test, color_enabled:)
|
8
|
+
make_rspec_rails_test_program(test, color_enabled: color_enabled)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when using 'super_diff/active_support'" do
|
13
|
+
include_context "integration with HashWithIndifferentAccess"
|
14
|
+
|
15
|
+
def make_program(test, color_enabled:)
|
16
|
+
make_rspec_active_support_program(test, color_enabled: color_enabled)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Integration with RSpec's #be_falsey matcher", type: :integration do
|
4
|
+
it "produces the correct failure message when used in the positive" do
|
5
|
+
as_both_colored_and_uncolored do |color_enabled|
|
6
|
+
snippet = %|expect(:foo).to be_falsey|
|
7
|
+
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
8
|
+
|
9
|
+
expected_output = build_expected_output(
|
10
|
+
color_enabled: color_enabled,
|
11
|
+
snippet: snippet,
|
12
|
+
expectation: proc {
|
13
|
+
line do
|
14
|
+
plain "Expected "
|
15
|
+
beta %|:foo|
|
16
|
+
plain " to be "
|
17
|
+
alpha %|falsey|
|
18
|
+
plain "."
|
19
|
+
end
|
20
|
+
},
|
21
|
+
)
|
22
|
+
|
23
|
+
expect(program).
|
24
|
+
to produce_output_when_run(expected_output).
|
25
|
+
in_color(color_enabled)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "produces the correct failure message when used in the negative" do
|
30
|
+
as_both_colored_and_uncolored do |color_enabled|
|
31
|
+
snippet = %|expect(false).not_to be_falsey|
|
32
|
+
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
33
|
+
|
34
|
+
expected_output = build_expected_output(
|
35
|
+
color_enabled: color_enabled,
|
36
|
+
snippet: snippet,
|
37
|
+
expectation: proc {
|
38
|
+
line do
|
39
|
+
plain "Expected "
|
40
|
+
beta %|false|
|
41
|
+
plain " not to be "
|
42
|
+
alpha %|falsey|
|
43
|
+
plain "."
|
44
|
+
end
|
45
|
+
},
|
46
|
+
)
|
47
|
+
|
48
|
+
expect(program).
|
49
|
+
to produce_output_when_run(expected_output).
|
50
|
+
in_color(color_enabled)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,565 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Integration with RSpec's #be matcher", type: :integration do
|
4
|
+
context "with a boolean" do
|
5
|
+
context "when comparing with false" do
|
6
|
+
it "produces the correct failure message when used in the positive" do
|
7
|
+
as_both_colored_and_uncolored do |color_enabled|
|
8
|
+
program =
|
9
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
10
|
+
expect(true).to be(false)
|
11
|
+
TEST
|
12
|
+
|
13
|
+
expected_output = build_expected_output(
|
14
|
+
color_enabled: color_enabled,
|
15
|
+
snippet: %|expect(true).to be(false)|,
|
16
|
+
expectation: proc {
|
17
|
+
line do
|
18
|
+
plain "Expected "
|
19
|
+
beta %|true|
|
20
|
+
plain " to equal "
|
21
|
+
alpha %|false|
|
22
|
+
plain "."
|
23
|
+
end
|
24
|
+
},
|
25
|
+
)
|
26
|
+
|
27
|
+
expect(program).
|
28
|
+
to produce_output_when_run(expected_output).
|
29
|
+
in_color(color_enabled)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "produces the correct failure message when used in the negative" do
|
34
|
+
as_both_colored_and_uncolored do |color_enabled|
|
35
|
+
program =
|
36
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
37
|
+
expect(false).not_to be(false)
|
38
|
+
TEST
|
39
|
+
|
40
|
+
expected_output = build_expected_output(
|
41
|
+
color_enabled: color_enabled,
|
42
|
+
snippet: %|expect(false).not_to be(false)|,
|
43
|
+
expectation: proc {
|
44
|
+
line do
|
45
|
+
plain "Expected "
|
46
|
+
beta %|false|
|
47
|
+
plain " not to equal "
|
48
|
+
alpha %|false|
|
49
|
+
plain "."
|
50
|
+
end
|
51
|
+
},
|
52
|
+
)
|
53
|
+
|
54
|
+
expect(program).
|
55
|
+
to produce_output_when_run(expected_output).
|
56
|
+
in_color(color_enabled)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when comparing with true" do
|
62
|
+
it "produces the correct failure message when used in the positive" do
|
63
|
+
as_both_colored_and_uncolored do |color_enabled|
|
64
|
+
program =
|
65
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
66
|
+
expect(false).to be(true)
|
67
|
+
TEST
|
68
|
+
|
69
|
+
expected_output = build_expected_output(
|
70
|
+
color_enabled: color_enabled,
|
71
|
+
snippet: %|expect(false).to be(true)|,
|
72
|
+
expectation: proc {
|
73
|
+
line do
|
74
|
+
plain "Expected "
|
75
|
+
beta %|false|
|
76
|
+
plain " to equal "
|
77
|
+
alpha %|true|
|
78
|
+
plain "."
|
79
|
+
end
|
80
|
+
},
|
81
|
+
)
|
82
|
+
|
83
|
+
expect(program).
|
84
|
+
to produce_output_when_run(expected_output).
|
85
|
+
in_color(color_enabled)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "produces the correct failure message when used in the negative" do
|
90
|
+
as_both_colored_and_uncolored do |color_enabled|
|
91
|
+
program =
|
92
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
93
|
+
expect(true).not_to be(true)
|
94
|
+
TEST
|
95
|
+
|
96
|
+
expected_output = build_expected_output(
|
97
|
+
color_enabled: color_enabled,
|
98
|
+
snippet: %|expect(true).not_to be(true)|,
|
99
|
+
expectation: proc {
|
100
|
+
line do
|
101
|
+
plain "Expected "
|
102
|
+
beta %|true|
|
103
|
+
plain " not to equal "
|
104
|
+
alpha %|true|
|
105
|
+
plain "."
|
106
|
+
end
|
107
|
+
},
|
108
|
+
)
|
109
|
+
|
110
|
+
expect(program).
|
111
|
+
to produce_output_when_run(expected_output).
|
112
|
+
in_color(color_enabled)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "with no arguments" do
|
119
|
+
it "produces the correct failure message when used in the positive" do
|
120
|
+
as_both_colored_and_uncolored do |color_enabled|
|
121
|
+
program =
|
122
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
123
|
+
expect(nil).to be
|
124
|
+
TEST
|
125
|
+
|
126
|
+
expected_output = build_expected_output(
|
127
|
+
color_enabled: color_enabled,
|
128
|
+
snippet: %|expect(nil).to be|,
|
129
|
+
expectation: proc {
|
130
|
+
line do
|
131
|
+
plain "Expected "
|
132
|
+
beta %|nil|
|
133
|
+
plain " to be "
|
134
|
+
alpha %|truthy|
|
135
|
+
plain "."
|
136
|
+
end
|
137
|
+
},
|
138
|
+
)
|
139
|
+
|
140
|
+
expect(program).
|
141
|
+
to produce_output_when_run(expected_output).
|
142
|
+
in_color(color_enabled)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "produces the correct failure message when used in the negative" do
|
147
|
+
as_both_colored_and_uncolored do |color_enabled|
|
148
|
+
program =
|
149
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
150
|
+
expect(:something).not_to be
|
151
|
+
TEST
|
152
|
+
|
153
|
+
expected_output = build_expected_output(
|
154
|
+
color_enabled: color_enabled,
|
155
|
+
snippet: %|expect(:something).not_to be|,
|
156
|
+
expectation: proc {
|
157
|
+
line do
|
158
|
+
plain "Expected "
|
159
|
+
beta %|:something|
|
160
|
+
plain " not to be "
|
161
|
+
alpha %|truthy|
|
162
|
+
plain "."
|
163
|
+
end
|
164
|
+
},
|
165
|
+
)
|
166
|
+
|
167
|
+
expect(program).
|
168
|
+
to produce_output_when_run(expected_output).
|
169
|
+
in_color(color_enabled)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "with ==" do
|
175
|
+
it "produces the correct failure message when used in the positive" do
|
176
|
+
as_both_colored_and_uncolored do |color_enabled|
|
177
|
+
program =
|
178
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
179
|
+
expect(nil).to be == :foo
|
180
|
+
TEST
|
181
|
+
|
182
|
+
expected_output = build_expected_output(
|
183
|
+
color_enabled: color_enabled,
|
184
|
+
snippet: %|expect(nil).to be == :foo|,
|
185
|
+
expectation: proc {
|
186
|
+
line do
|
187
|
+
plain "Expected "
|
188
|
+
beta %|nil|
|
189
|
+
plain " to == "
|
190
|
+
alpha %|:foo|
|
191
|
+
plain "."
|
192
|
+
end
|
193
|
+
},
|
194
|
+
)
|
195
|
+
|
196
|
+
expect(program).
|
197
|
+
to produce_output_when_run(expected_output).
|
198
|
+
in_color(color_enabled)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
it "produces the correct failure message when used in the negative" do
|
203
|
+
as_both_colored_and_uncolored do |color_enabled|
|
204
|
+
program =
|
205
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
206
|
+
expect(:foo).not_to be == :foo
|
207
|
+
TEST
|
208
|
+
|
209
|
+
expected_output = build_expected_output(
|
210
|
+
color_enabled: color_enabled,
|
211
|
+
snippet: %|expect(:foo).not_to be == :foo|,
|
212
|
+
expectation: proc {
|
213
|
+
line do
|
214
|
+
plain "Expected "
|
215
|
+
beta %|:foo|
|
216
|
+
plain " not to == "
|
217
|
+
alpha %|:foo|
|
218
|
+
plain "."
|
219
|
+
end
|
220
|
+
},
|
221
|
+
)
|
222
|
+
|
223
|
+
expect(program).
|
224
|
+
to produce_output_when_run(expected_output).
|
225
|
+
in_color(color_enabled)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context "with <" do
|
231
|
+
it "produces the correct failure message when used in the positive" do
|
232
|
+
as_both_colored_and_uncolored do |color_enabled|
|
233
|
+
program =
|
234
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
235
|
+
expect(1).to be < 1
|
236
|
+
TEST
|
237
|
+
|
238
|
+
expected_output = build_expected_output(
|
239
|
+
color_enabled: color_enabled,
|
240
|
+
snippet: %|expect(1).to be < 1|,
|
241
|
+
expectation: proc {
|
242
|
+
line do
|
243
|
+
plain "Expected "
|
244
|
+
beta %|1|
|
245
|
+
plain " to be < "
|
246
|
+
alpha %|1|
|
247
|
+
plain "."
|
248
|
+
end
|
249
|
+
},
|
250
|
+
)
|
251
|
+
|
252
|
+
expect(program).
|
253
|
+
to produce_output_when_run(expected_output).
|
254
|
+
in_color(color_enabled)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
it "produces the correct failure message when used in the negative" do
|
259
|
+
as_both_colored_and_uncolored do |color_enabled|
|
260
|
+
program =
|
261
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
262
|
+
expect(0).not_to be < 1
|
263
|
+
TEST
|
264
|
+
|
265
|
+
expected_output = build_expected_output(
|
266
|
+
color_enabled: color_enabled,
|
267
|
+
snippet: %|expect(0).not_to be < 1|,
|
268
|
+
expectation: proc {
|
269
|
+
line do
|
270
|
+
plain "Expected "
|
271
|
+
beta %|0|
|
272
|
+
plain " not to be < "
|
273
|
+
alpha %|1|
|
274
|
+
plain "."
|
275
|
+
end
|
276
|
+
},
|
277
|
+
)
|
278
|
+
|
279
|
+
expect(program).
|
280
|
+
to produce_output_when_run(expected_output).
|
281
|
+
in_color(color_enabled)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
context "with <=" do
|
287
|
+
it "produces the correct failure message when used in the positive" do
|
288
|
+
as_both_colored_and_uncolored do |color_enabled|
|
289
|
+
program =
|
290
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
291
|
+
expect(1).to be <= 0
|
292
|
+
TEST
|
293
|
+
|
294
|
+
expected_output = build_expected_output(
|
295
|
+
color_enabled: color_enabled,
|
296
|
+
snippet: %|expect(1).to be <= 0|,
|
297
|
+
expectation: proc {
|
298
|
+
line do
|
299
|
+
plain "Expected "
|
300
|
+
beta %|1|
|
301
|
+
plain " to be <= "
|
302
|
+
alpha %|0|
|
303
|
+
plain "."
|
304
|
+
end
|
305
|
+
},
|
306
|
+
)
|
307
|
+
|
308
|
+
expect(program).
|
309
|
+
to produce_output_when_run(expected_output).
|
310
|
+
in_color(color_enabled)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
it "produces the correct failure message when used in the negative" do
|
315
|
+
as_both_colored_and_uncolored do |color_enabled|
|
316
|
+
program =
|
317
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
318
|
+
expect(0).not_to be <= 0
|
319
|
+
TEST
|
320
|
+
|
321
|
+
expected_output = build_expected_output(
|
322
|
+
color_enabled: color_enabled,
|
323
|
+
snippet: %|expect(0).not_to be <= 0|,
|
324
|
+
expectation: proc {
|
325
|
+
line do
|
326
|
+
plain "Expected "
|
327
|
+
beta %|0|
|
328
|
+
plain " not to be <= "
|
329
|
+
alpha %|0|
|
330
|
+
plain "."
|
331
|
+
end
|
332
|
+
},
|
333
|
+
)
|
334
|
+
|
335
|
+
expect(program).
|
336
|
+
to produce_output_when_run(expected_output).
|
337
|
+
in_color(color_enabled)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
context "with >=" do
|
343
|
+
it "produces the correct failure message when used in the positive" do
|
344
|
+
as_both_colored_and_uncolored do |color_enabled|
|
345
|
+
program =
|
346
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
347
|
+
expect(1).to be >= 2
|
348
|
+
TEST
|
349
|
+
|
350
|
+
expected_output = build_expected_output(
|
351
|
+
color_enabled: color_enabled,
|
352
|
+
snippet: %|expect(1).to be >= 2|,
|
353
|
+
expectation: proc {
|
354
|
+
line do
|
355
|
+
plain "Expected "
|
356
|
+
beta %|1|
|
357
|
+
plain " to be >= "
|
358
|
+
alpha %|2|
|
359
|
+
plain "."
|
360
|
+
end
|
361
|
+
},
|
362
|
+
)
|
363
|
+
|
364
|
+
expect(program).
|
365
|
+
to produce_output_when_run(expected_output).
|
366
|
+
in_color(color_enabled)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
it "produces the correct failure message when used in the negative" do
|
371
|
+
as_both_colored_and_uncolored do |color_enabled|
|
372
|
+
program =
|
373
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
374
|
+
expect(2).not_to be >= 2
|
375
|
+
TEST
|
376
|
+
|
377
|
+
expected_output = build_expected_output(
|
378
|
+
color_enabled: color_enabled,
|
379
|
+
snippet: %|expect(2).not_to be >= 2|,
|
380
|
+
expectation: proc {
|
381
|
+
line do
|
382
|
+
plain "Expected "
|
383
|
+
beta %|2|
|
384
|
+
plain " not to be >= "
|
385
|
+
alpha %|2|
|
386
|
+
plain "."
|
387
|
+
end
|
388
|
+
},
|
389
|
+
)
|
390
|
+
|
391
|
+
expect(program).
|
392
|
+
to produce_output_when_run(expected_output).
|
393
|
+
in_color(color_enabled)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context "with >" do
|
399
|
+
it "produces the correct failure message when used in the positive" do
|
400
|
+
as_both_colored_and_uncolored do |color_enabled|
|
401
|
+
program =
|
402
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
403
|
+
expect(1).to be > 2
|
404
|
+
TEST
|
405
|
+
|
406
|
+
expected_output = build_expected_output(
|
407
|
+
color_enabled: color_enabled,
|
408
|
+
snippet: %|expect(1).to be > 2|,
|
409
|
+
expectation: proc {
|
410
|
+
line do
|
411
|
+
plain "Expected "
|
412
|
+
beta %|1|
|
413
|
+
plain " to be > "
|
414
|
+
alpha %|2|
|
415
|
+
plain "."
|
416
|
+
end
|
417
|
+
},
|
418
|
+
)
|
419
|
+
|
420
|
+
expect(program).
|
421
|
+
to produce_output_when_run(expected_output).
|
422
|
+
in_color(color_enabled)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
it "produces the correct failure message when used in the negative" do
|
427
|
+
as_both_colored_and_uncolored do |color_enabled|
|
428
|
+
program =
|
429
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
430
|
+
expect(3).not_to be > 2
|
431
|
+
TEST
|
432
|
+
|
433
|
+
expected_output = build_expected_output(
|
434
|
+
color_enabled: color_enabled,
|
435
|
+
snippet: %|expect(3).not_to be > 2|,
|
436
|
+
expectation: proc {
|
437
|
+
line do
|
438
|
+
plain "Expected "
|
439
|
+
beta %|3|
|
440
|
+
plain " not to be > "
|
441
|
+
alpha %|2|
|
442
|
+
plain "."
|
443
|
+
end
|
444
|
+
},
|
445
|
+
)
|
446
|
+
|
447
|
+
expect(program).
|
448
|
+
to produce_output_when_run(expected_output).
|
449
|
+
in_color(color_enabled)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
context "with ===" do
|
455
|
+
it "produces the correct failure message when used in the positive" do
|
456
|
+
as_both_colored_and_uncolored do |color_enabled|
|
457
|
+
program =
|
458
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
459
|
+
expect(String).to be === :foo
|
460
|
+
TEST
|
461
|
+
|
462
|
+
expected_output = build_expected_output(
|
463
|
+
color_enabled: color_enabled,
|
464
|
+
snippet: %|expect(String).to be === :foo|,
|
465
|
+
expectation: proc {
|
466
|
+
line do
|
467
|
+
plain "Expected "
|
468
|
+
beta %|String|
|
469
|
+
plain " to === "
|
470
|
+
alpha %|:foo|
|
471
|
+
plain "."
|
472
|
+
end
|
473
|
+
},
|
474
|
+
)
|
475
|
+
|
476
|
+
expect(program).
|
477
|
+
to produce_output_when_run(expected_output).
|
478
|
+
in_color(color_enabled)
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
it "produces the correct failure message when used in the negative" do
|
483
|
+
as_both_colored_and_uncolored do |color_enabled|
|
484
|
+
program =
|
485
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
486
|
+
expect(String).not_to be === "foo"
|
487
|
+
TEST
|
488
|
+
|
489
|
+
expected_output = build_expected_output(
|
490
|
+
color_enabled: color_enabled,
|
491
|
+
snippet: %|expect(String).not_to be === "foo"|,
|
492
|
+
expectation: proc {
|
493
|
+
line do
|
494
|
+
plain "Expected "
|
495
|
+
beta %|String|
|
496
|
+
plain " not to === "
|
497
|
+
alpha %|"foo"|
|
498
|
+
plain "."
|
499
|
+
end
|
500
|
+
},
|
501
|
+
)
|
502
|
+
|
503
|
+
expect(program).
|
504
|
+
to produce_output_when_run(expected_output).
|
505
|
+
in_color(color_enabled)
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
context "with =~" do
|
511
|
+
it "produces the correct failure message when used in the positive" do
|
512
|
+
as_both_colored_and_uncolored do |color_enabled|
|
513
|
+
program =
|
514
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
515
|
+
expect("foo").to be =~ /bar/
|
516
|
+
TEST
|
517
|
+
|
518
|
+
expected_output = build_expected_output(
|
519
|
+
color_enabled: color_enabled,
|
520
|
+
snippet: %|expect("foo").to be =~ /bar/|,
|
521
|
+
expectation: proc {
|
522
|
+
line do
|
523
|
+
plain "Expected "
|
524
|
+
beta %|"foo"|
|
525
|
+
plain " to =~ "
|
526
|
+
alpha %|/bar/|
|
527
|
+
plain "."
|
528
|
+
end
|
529
|
+
},
|
530
|
+
)
|
531
|
+
|
532
|
+
expect(program).
|
533
|
+
to produce_output_when_run(expected_output).
|
534
|
+
in_color(color_enabled)
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
it "produces the correct failure message when used in the negative" do
|
539
|
+
as_both_colored_and_uncolored do |color_enabled|
|
540
|
+
program =
|
541
|
+
make_plain_test_program(<<~TEST.strip, color_enabled: color_enabled)
|
542
|
+
expect("bar").not_to be =~ /bar/
|
543
|
+
TEST
|
544
|
+
|
545
|
+
expected_output = build_expected_output(
|
546
|
+
color_enabled: color_enabled,
|
547
|
+
snippet: %|expect("bar").not_to be =~ /bar/|,
|
548
|
+
expectation: proc {
|
549
|
+
line do
|
550
|
+
plain "Expected "
|
551
|
+
beta %|"bar"|
|
552
|
+
plain " not to =~ "
|
553
|
+
alpha %|/bar/|
|
554
|
+
plain "."
|
555
|
+
end
|
556
|
+
},
|
557
|
+
)
|
558
|
+
|
559
|
+
expect(program).
|
560
|
+
to produce_output_when_run(expected_output).
|
561
|
+
in_color(color_enabled)
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|