rspec-expectations 2.13.0 → 3.0.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.
Files changed (142) hide show
  1. checksums.yaml +15 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +413 -23
  4. data/License.txt +1 -0
  5. data/README.md +109 -80
  6. data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
  7. data/lib/rspec/expectations/expectation_target.rb +71 -38
  8. data/lib/rspec/expectations/fail_with.rb +12 -44
  9. data/lib/rspec/expectations/handler.rb +135 -35
  10. data/lib/rspec/expectations/minitest_integration.rb +16 -0
  11. data/lib/rspec/expectations/syntax.rb +60 -94
  12. data/lib/rspec/expectations/version.rb +1 -1
  13. data/lib/rspec/expectations.rb +46 -24
  14. data/lib/rspec/matchers/aliased_matcher.rb +41 -0
  15. data/lib/rspec/matchers/built_in/all.rb +78 -0
  16. data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
  17. data/lib/rspec/matchers/built_in/be.rb +170 -79
  18. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  19. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  20. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  21. data/lib/rspec/matchers/built_in/be_within.rb +40 -16
  22. data/lib/rspec/matchers/built_in/change.rb +275 -74
  23. data/lib/rspec/matchers/built_in/compound.rb +122 -0
  24. data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
  25. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  26. data/lib/rspec/matchers/built_in/eq.rb +60 -6
  27. data/lib/rspec/matchers/built_in/eql.rb +17 -5
  28. data/lib/rspec/matchers/built_in/equal.rb +55 -21
  29. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  30. data/lib/rspec/matchers/built_in/has.rb +71 -15
  31. data/lib/rspec/matchers/built_in/include.rb +58 -29
  32. data/lib/rspec/matchers/built_in/match.rb +19 -1
  33. data/lib/rspec/matchers/built_in/operators.rb +119 -0
  34. data/lib/rspec/matchers/built_in/output.rb +150 -0
  35. data/lib/rspec/matchers/built_in/raise_error.rb +91 -33
  36. data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
  37. data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
  38. data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
  39. data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
  40. data/lib/rspec/matchers/built_in/yield.rb +237 -55
  41. data/lib/rspec/matchers/built_in.rb +45 -33
  42. data/lib/rspec/matchers/composable.rb +179 -0
  43. data/lib/rspec/matchers/dsl.rb +362 -5
  44. data/lib/rspec/matchers/generated_descriptions.rb +13 -6
  45. data/lib/rspec/matchers/matcher_delegator.rb +37 -0
  46. data/lib/rspec/matchers/pretty.rb +33 -20
  47. data/lib/rspec/matchers.rb +450 -227
  48. data.tar.gz.sig +1 -0
  49. metadata +100 -215
  50. metadata.gz.sig +0 -0
  51. data/features/README.md +0 -49
  52. data/features/Upgrade.md +0 -53
  53. data/features/built_in_matchers/README.md +0 -90
  54. data/features/built_in_matchers/be.feature +0 -175
  55. data/features/built_in_matchers/be_within.feature +0 -48
  56. data/features/built_in_matchers/cover.feature +0 -47
  57. data/features/built_in_matchers/end_with.feature +0 -48
  58. data/features/built_in_matchers/equality.feature +0 -139
  59. data/features/built_in_matchers/exist.feature +0 -45
  60. data/features/built_in_matchers/expect_change.feature +0 -59
  61. data/features/built_in_matchers/expect_error.feature +0 -144
  62. data/features/built_in_matchers/have.feature +0 -109
  63. data/features/built_in_matchers/include.feature +0 -174
  64. data/features/built_in_matchers/match.feature +0 -52
  65. data/features/built_in_matchers/operators.feature +0 -227
  66. data/features/built_in_matchers/predicates.feature +0 -137
  67. data/features/built_in_matchers/respond_to.feature +0 -84
  68. data/features/built_in_matchers/satisfy.feature +0 -33
  69. data/features/built_in_matchers/start_with.feature +0 -48
  70. data/features/built_in_matchers/throw_symbol.feature +0 -91
  71. data/features/built_in_matchers/types.feature +0 -116
  72. data/features/built_in_matchers/yield.feature +0 -146
  73. data/features/custom_matchers/access_running_example.feature +0 -53
  74. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  75. data/features/custom_matchers/define_matcher.feature +0 -368
  76. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  77. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  78. data/features/customized_message.feature +0 -22
  79. data/features/diffing.feature +0 -85
  80. data/features/implicit_docstrings.feature +0 -52
  81. data/features/step_definitions/additional_cli_steps.rb +0 -22
  82. data/features/support/env.rb +0 -5
  83. data/features/syntax_configuration.feature +0 -68
  84. data/features/test_frameworks/test_unit.feature +0 -46
  85. data/lib/rspec/expectations/deprecation.rb +0 -38
  86. data/lib/rspec/expectations/differ.rb +0 -115
  87. data/lib/rspec/expectations/errors.rb +0 -9
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/expectations/extensions/object.rb +0 -39
  90. data/lib/rspec/expectations/extensions.rb +0 -2
  91. data/lib/rspec/matchers/be_close.rb +0 -9
  92. data/lib/rspec/matchers/built_in/have.rb +0 -108
  93. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  94. data/lib/rspec/matchers/compatibility.rb +0 -14
  95. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  96. data/lib/rspec/matchers/matcher.rb +0 -300
  97. data/lib/rspec/matchers/method_missing.rb +0 -12
  98. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  99. data/lib/rspec-expectations.rb +0 -1
  100. data/spec/rspec/expectations/differ_spec.rb +0 -170
  101. data/spec/rspec/expectations/expectation_target_spec.rb +0 -75
  102. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  103. data/spec/rspec/expectations/fail_with_spec.rb +0 -95
  104. data/spec/rspec/expectations/handler_spec.rb +0 -206
  105. data/spec/rspec/expectations/syntax_spec.rb +0 -97
  106. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  107. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  108. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  109. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  110. data/spec/rspec/matchers/be_spec.rb +0 -516
  111. data/spec/rspec/matchers/be_within_spec.rb +0 -129
  112. data/spec/rspec/matchers/change_spec.rb +0 -542
  113. data/spec/rspec/matchers/configuration_spec.rb +0 -238
  114. data/spec/rspec/matchers/cover_spec.rb +0 -69
  115. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  116. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  117. data/spec/rspec/matchers/eq_spec.rb +0 -60
  118. data/spec/rspec/matchers/eql_spec.rb +0 -41
  119. data/spec/rspec/matchers/equal_spec.rb +0 -78
  120. data/spec/rspec/matchers/exist_spec.rb +0 -124
  121. data/spec/rspec/matchers/has_spec.rb +0 -122
  122. data/spec/rspec/matchers/have_spec.rb +0 -445
  123. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  124. data/spec/rspec/matchers/include_spec.rb +0 -531
  125. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  126. data/spec/rspec/matchers/match_spec.rb +0 -61
  127. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  128. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  129. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  130. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  131. data/spec/rspec/matchers/raise_error_spec.rb +0 -395
  132. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  133. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  134. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  135. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  136. data/spec/rspec/matchers/yield_spec.rb +0 -437
  137. data/spec/spec_helper.rb +0 -54
  138. data/spec/support/classes.rb +0 -56
  139. data/spec/support/in_sub_process.rb +0 -38
  140. data/spec/support/matchers.rb +0 -22
  141. data/spec/support/ruby_version.rb +0 -10
  142. 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(...).to_not 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(...).to_not 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