rspec-expectations 2.14.0 → 3.13.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +976 -25
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +162 -26
- data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
- data/lib/rspec/expectations/configuration.rb +230 -0
- data/lib/rspec/expectations/expectation_target.rb +127 -51
- data/lib/rspec/expectations/fail_with.rb +17 -57
- data/lib/rspec/expectations/failure_aggregator.rb +229 -0
- data/lib/rspec/expectations/handler.rb +146 -32
- data/lib/rspec/expectations/minitest_integration.rb +58 -0
- data/lib/rspec/expectations/syntax.rb +68 -100
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +58 -23
- data/lib/rspec/matchers/aliased_matcher.rb +116 -0
- data/lib/rspec/matchers/built_in/all.rb +86 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +191 -20
- data/lib/rspec/matchers/built_in/be.rb +114 -114
- data/lib/rspec/matchers/built_in/be_between.rb +77 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
- data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
- data/lib/rspec/matchers/built_in/be_within.rb +35 -18
- data/lib/rspec/matchers/built_in/change.rb +389 -80
- data/lib/rspec/matchers/built_in/compound.rb +290 -0
- data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -0
- data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +30 -8
- data/lib/rspec/matchers/built_in/eql.rb +23 -8
- data/lib/rspec/matchers/built_in/equal.rb +55 -22
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +141 -22
- data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
- data/lib/rspec/matchers/built_in/include.rb +184 -32
- data/lib/rspec/matchers/built_in/match.rb +95 -1
- data/lib/rspec/matchers/built_in/operators.rb +128 -0
- data/lib/rspec/matchers/built_in/output.rb +207 -0
- data/lib/rspec/matchers/built_in/raise_error.rb +192 -44
- data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
- data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
- data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
- data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
- data/lib/rspec/matchers/built_in/yield.rb +240 -161
- data/lib/rspec/matchers/built_in.rb +47 -33
- data/lib/rspec/matchers/composable.rb +171 -0
- data/lib/rspec/matchers/dsl.rb +531 -10
- data/lib/rspec/matchers/english_phrasing.rb +58 -0
- data/lib/rspec/matchers/fail_matchers.rb +42 -0
- data/lib/rspec/matchers/generated_descriptions.rb +14 -8
- data/lib/rspec/matchers/matcher_delegator.rb +61 -0
- data/lib/rspec/matchers/matcher_protocol.rb +105 -0
- data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
- data/lib/rspec/matchers.rb +520 -173
- data.tar.gz.sig +0 -0
- metadata +141 -242
- metadata.gz.sig +2 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -90
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/cover.feature +0 -47
- data/features/built_in_matchers/end_with.feature +0 -48
- data/features/built_in_matchers/equality.feature +0 -139
- data/features/built_in_matchers/exist.feature +0 -45
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -144
- data/features/built_in_matchers/have.feature +0 -109
- data/features/built_in_matchers/include.feature +0 -174
- data/features/built_in_matchers/match.feature +0 -52
- data/features/built_in_matchers/operators.feature +0 -227
- data/features/built_in_matchers/predicates.feature +0 -137
- data/features/built_in_matchers/respond_to.feature +0 -84
- data/features/built_in_matchers/satisfy.feature +0 -33
- data/features/built_in_matchers/start_with.feature +0 -48
- data/features/built_in_matchers/throw_symbol.feature +0 -91
- data/features/built_in_matchers/types.feature +0 -116
- data/features/built_in_matchers/yield.feature +0 -161
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -368
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -22
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -14
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/test_unit.feature +0 -44
- data/lib/rspec/expectations/deprecation.rb +0 -17
- data/lib/rspec/expectations/differ.rb +0 -133
- data/lib/rspec/expectations/errors.rb +0 -9
- data/lib/rspec/expectations/extensions/array.rb +0 -9
- data/lib/rspec/expectations/extensions/object.rb +0 -29
- data/lib/rspec/expectations/extensions.rb +0 -2
- data/lib/rspec/matchers/be_close.rb +0 -9
- data/lib/rspec/matchers/built_in/have.rb +0 -124
- data/lib/rspec/matchers/built_in/match_array.rb +0 -51
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
- data/lib/rspec/matchers/compatibility.rb +0 -14
- data/lib/rspec/matchers/configuration.rb +0 -108
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
- data/lib/rspec/matchers/matcher.rb +0 -300
- data/lib/rspec/matchers/method_missing.rb +0 -12
- data/lib/rspec/matchers/operator_matcher.rb +0 -109
- data/lib/rspec/matchers/pretty.rb +0 -70
- data/lib/rspec/matchers/test_unit_integration.rb +0 -11
- data/lib/rspec-expectations.rb +0 -1
- data/spec/rspec/expectations/differ_spec.rb +0 -192
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -114
- data/spec/rspec/expectations/handler_spec.rb +0 -227
- data/spec/rspec/expectations/syntax_spec.rb +0 -139
- data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
- data/spec/rspec/matchers/be_close_spec.rb +0 -22
- data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/be_spec.rb +0 -516
- data/spec/rspec/matchers/be_within_spec.rb +0 -137
- data/spec/rspec/matchers/change_spec.rb +0 -553
- data/spec/rspec/matchers/configuration_spec.rb +0 -206
- data/spec/rspec/matchers/cover_spec.rb +0 -69
- data/spec/rspec/matchers/description_generation_spec.rb +0 -190
- data/spec/rspec/matchers/dsl_spec.rb +0 -57
- data/spec/rspec/matchers/eq_spec.rb +0 -60
- data/spec/rspec/matchers/eql_spec.rb +0 -41
- data/spec/rspec/matchers/equal_spec.rb +0 -78
- data/spec/rspec/matchers/exist_spec.rb +0 -124
- data/spec/rspec/matchers/has_spec.rb +0 -122
- data/spec/rspec/matchers/have_spec.rb +0 -455
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
- data/spec/rspec/matchers/include_spec.rb +0 -531
- data/spec/rspec/matchers/match_array_spec.rb +0 -194
- data/spec/rspec/matchers/match_spec.rb +0 -61
- data/spec/rspec/matchers/matcher_spec.rb +0 -471
- data/spec/rspec/matchers/matchers_spec.rb +0 -37
- data/spec/rspec/matchers/method_missing_spec.rb +0 -28
- data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
- data/spec/rspec/matchers/raise_error_spec.rb +0 -485
- data/spec/rspec/matchers/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
- data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
- data/spec/rspec/matchers/yield_spec.rb +0 -514
- data/spec/spec_helper.rb +0 -54
- data/spec/support/classes.rb +0 -56
- data/spec/support/in_sub_process.rb +0 -38
- data/spec/support/matchers.rb +0 -22
- data/spec/support/ruby_version.rb +0 -10
- data/spec/support/shared_examples.rb +0 -13
@@ -1,194 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class UnsortableObject
|
4
|
-
def initialize(id)
|
5
|
-
@id = id
|
6
|
-
end
|
7
|
-
|
8
|
-
def inspect
|
9
|
-
@id.to_s
|
10
|
-
end
|
11
|
-
|
12
|
-
def ==(other)
|
13
|
-
false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "should =~ array", :uses_should do
|
18
|
-
it "passes a valid positive expectation" do
|
19
|
-
[1, 2].should =~ [2, 1]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "fails an invalid positive expectation" do
|
23
|
-
expect {
|
24
|
-
[1, 2, 3].should =~ [2, 1]
|
25
|
-
}.to fail_with(/expected collection contained/)
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when the array defines a `=~` method" do
|
29
|
-
it 'delegates to that method rather than using the match_array matcher' do
|
30
|
-
array = []
|
31
|
-
def array.=~(other)
|
32
|
-
other == :foo
|
33
|
-
end
|
34
|
-
|
35
|
-
array.should =~ :foo
|
36
|
-
expect {
|
37
|
-
array.should =~ :bar
|
38
|
-
}.to fail_with(/expected: :bar/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when the array defines a `send` method' do
|
43
|
-
it 'still works' do
|
44
|
-
array = [1, 2]
|
45
|
-
def array.send; :sent; end
|
46
|
-
|
47
|
-
array.should =~ array
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "should_not =~ [:with, :multiple, :args]", :uses_should do
|
53
|
-
it "is not supported" do
|
54
|
-
expect {
|
55
|
-
[1,2,3].should_not =~ [1,2,3]
|
56
|
-
}.to fail_with(/Matcher does not support should_not/)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "using match_array with expect" do
|
61
|
-
it "passes a valid positive expectation" do
|
62
|
-
expect([1, 2]).to match_array [2, 1]
|
63
|
-
end
|
64
|
-
|
65
|
-
it "fails an invalid positive expectation" do
|
66
|
-
expect {
|
67
|
-
expect([1, 2, 3]).to match_array [2, 1]
|
68
|
-
}.to fail_with(/expected collection contained/)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "expect(array).to match_array other_array" do
|
73
|
-
it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
|
74
|
-
let(:matcher) { match_array([2, 1]) }
|
75
|
-
end
|
76
|
-
|
77
|
-
it "passes if target contains all items" do
|
78
|
-
expect([1,2,3]).to match_array [1,2,3]
|
79
|
-
end
|
80
|
-
|
81
|
-
it "passes if target contains all items out of order" do
|
82
|
-
expect([1,3,2]).to match_array [1,2,3]
|
83
|
-
end
|
84
|
-
|
85
|
-
it "fails if target includes extra items" do
|
86
|
-
expect {
|
87
|
-
expect([1,2,3,4]).to match_array [1,2,3]
|
88
|
-
}.to fail_with(<<-MESSAGE)
|
89
|
-
expected collection contained: [1, 2, 3]
|
90
|
-
actual collection contained: [1, 2, 3, 4]
|
91
|
-
the extra elements were: [4]
|
92
|
-
MESSAGE
|
93
|
-
end
|
94
|
-
|
95
|
-
it "fails if target is missing items" do
|
96
|
-
expect {
|
97
|
-
expect([1,2]).to match_array [1,2,3]
|
98
|
-
}.to fail_with(<<-MESSAGE)
|
99
|
-
expected collection contained: [1, 2, 3]
|
100
|
-
actual collection contained: [1, 2]
|
101
|
-
the missing elements were: [3]
|
102
|
-
MESSAGE
|
103
|
-
end
|
104
|
-
|
105
|
-
it "fails if target is missing items and has extra items" do
|
106
|
-
expect {
|
107
|
-
expect([1,2,4]).to match_array [1,2,3]
|
108
|
-
}.to fail_with(<<-MESSAGE)
|
109
|
-
expected collection contained: [1, 2, 3]
|
110
|
-
actual collection contained: [1, 2, 4]
|
111
|
-
the missing elements were: [3]
|
112
|
-
the extra elements were: [4]
|
113
|
-
MESSAGE
|
114
|
-
end
|
115
|
-
|
116
|
-
it "sorts items in the error message if they all respond to <=>" do
|
117
|
-
expect {
|
118
|
-
expect([6,2,1,5]).to match_array [4,1,2,3]
|
119
|
-
}.to fail_with(<<-MESSAGE)
|
120
|
-
expected collection contained: [1, 2, 3, 4]
|
121
|
-
actual collection contained: [1, 2, 5, 6]
|
122
|
-
the missing elements were: [3, 4]
|
123
|
-
the extra elements were: [5, 6]
|
124
|
-
MESSAGE
|
125
|
-
end
|
126
|
-
|
127
|
-
it "does not sort items in the error message if they don't all respond to <=>" do
|
128
|
-
expect {
|
129
|
-
expect([UnsortableObject.new(2), UnsortableObject.new(1)]).to match_array [UnsortableObject.new(4), UnsortableObject.new(3)]
|
130
|
-
}.to fail_with(<<-MESSAGE)
|
131
|
-
expected collection contained: [4, 3]
|
132
|
-
actual collection contained: [2, 1]
|
133
|
-
the missing elements were: [4, 3]
|
134
|
-
the extra elements were: [2, 1]
|
135
|
-
MESSAGE
|
136
|
-
end
|
137
|
-
|
138
|
-
it "accurately reports extra elements when there are duplicates" do
|
139
|
-
expect {
|
140
|
-
expect([1,1,1,5]).to match_array [1,5]
|
141
|
-
}.to fail_with(<<-MESSAGE)
|
142
|
-
expected collection contained: [1, 5]
|
143
|
-
actual collection contained: [1, 1, 1, 5]
|
144
|
-
the extra elements were: [1, 1]
|
145
|
-
MESSAGE
|
146
|
-
end
|
147
|
-
|
148
|
-
it "accurately reports missing elements when there are duplicates" do
|
149
|
-
expect {
|
150
|
-
expect([1,5]).to match_array [1,1,5]
|
151
|
-
}.to fail_with(<<-MESSAGE)
|
152
|
-
expected collection contained: [1, 1, 5]
|
153
|
-
actual collection contained: [1, 5]
|
154
|
-
the missing elements were: [1]
|
155
|
-
MESSAGE
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "expect(...).not_to match_array [:with, :multiple, :args]" do
|
160
|
-
it "is not supported" do
|
161
|
-
expect {
|
162
|
-
expect([1,2,3]).not_to match_array [1,2,3]
|
163
|
-
}.to fail_with(/Matcher does not support should_not/)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "matching against things that aren't arrays" do
|
168
|
-
it "fails with nil and the expected error message is given" do
|
169
|
-
expect {
|
170
|
-
expect(nil).to match_array([1,2,3])
|
171
|
-
}.to fail_with(/expected an array/)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "fails with a float and the expected error message is given" do
|
175
|
-
expect {
|
176
|
-
expect((3.7)).to match_array([1,2,3])
|
177
|
-
}.to fail_with(/expected an array/)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "fails with a string and the expected error message is given" do
|
181
|
-
expect {
|
182
|
-
expect("I like turtles").to match_array([1,2,3])
|
183
|
-
}.to fail_with(/expected an array/)
|
184
|
-
end
|
185
|
-
|
186
|
-
context "when using the `should =~` syntax", :uses_should do
|
187
|
-
it 'fails with a clear message when given a hash' do
|
188
|
-
expect {
|
189
|
-
{}.should =~ {}
|
190
|
-
}.to fail_with(/expected an array/)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "expect(...).to match(expected)" do
|
4
|
-
it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
|
5
|
-
let(:matcher) { match(/a/) }
|
6
|
-
end
|
7
|
-
|
8
|
-
it "passes when target (String) matches expected (Regexp)" do
|
9
|
-
expect("string").to match(/tri/)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "passes when target (String) matches expected (String)" do
|
13
|
-
expect("string").to match("tri")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "fails when target (String) does not match expected (Regexp)" do
|
17
|
-
expect {
|
18
|
-
expect("string").to match(/rings/)
|
19
|
-
}.to fail
|
20
|
-
end
|
21
|
-
|
22
|
-
it "fails when target (String) does not match expected (String)" do
|
23
|
-
expect {
|
24
|
-
expect("string").to match("rings")
|
25
|
-
}.to fail
|
26
|
-
end
|
27
|
-
|
28
|
-
it "provides message, expected and actual on failure" do
|
29
|
-
matcher = match(/rings/)
|
30
|
-
matcher.matches?("string")
|
31
|
-
expect(matcher.failure_message_for_should).to eq "expected \"string\" to match /rings/"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "expect(...).not_to match(expected)" do
|
36
|
-
it "passes when target (String) matches does not match (Regexp)" do
|
37
|
-
expect("string").not_to match(/rings/)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "passes when target (String) matches does not match (String)" do
|
41
|
-
expect("string").not_to match("rings")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "fails when target (String) matches expected (Regexp)" do
|
45
|
-
expect {
|
46
|
-
expect("string").not_to match(/tri/)
|
47
|
-
}.to fail
|
48
|
-
end
|
49
|
-
|
50
|
-
it "fails when target (String) matches expected (String)" do
|
51
|
-
expect {
|
52
|
-
expect("string").not_to match("tri")
|
53
|
-
}.to fail
|
54
|
-
end
|
55
|
-
|
56
|
-
it "provides message, expected and actual on failure" do
|
57
|
-
matcher = match(/tri/)
|
58
|
-
matcher.matches?("string")
|
59
|
-
expect(matcher.failure_message_for_should_not).to eq "expected \"string\" not to match /tri/"
|
60
|
-
end
|
61
|
-
end
|