rspec-expectations 2.99.2 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +14 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/Changelog.md +63 -104
  5. data/License.txt +1 -0
  6. data/README.md +14 -8
  7. data/features/README.md +1 -2
  8. data/features/built_in_matchers/README.md +3 -0
  9. data/features/built_in_matchers/be.feature +44 -44
  10. data/features/built_in_matchers/be_within.feature +1 -1
  11. data/features/built_in_matchers/comparisons.feature +97 -0
  12. data/features/built_in_matchers/cover.feature +3 -3
  13. data/features/built_in_matchers/end_with.feature +3 -3
  14. data/features/built_in_matchers/equality.feature +20 -23
  15. data/features/built_in_matchers/exist.feature +5 -5
  16. data/features/built_in_matchers/expect_error.feature +14 -14
  17. data/features/built_in_matchers/include.feature +15 -15
  18. data/features/built_in_matchers/match.feature +4 -5
  19. data/features/built_in_matchers/match_array.feature +37 -0
  20. data/features/built_in_matchers/predicates.feature +30 -6
  21. data/features/built_in_matchers/respond_to.feature +4 -4
  22. data/features/built_in_matchers/satisfy.feature +2 -2
  23. data/features/built_in_matchers/start_with.feature +3 -3
  24. data/features/built_in_matchers/types.feature +6 -6
  25. data/features/custom_matchers/access_running_example.feature +3 -3
  26. data/features/custom_matchers/define_matcher.feature +6 -34
  27. data/features/custom_matchers/define_matcher_outside_rspec.feature +2 -2
  28. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +1 -1
  29. data/features/customized_message.feature +18 -1
  30. data/features/diffing.feature +3 -3
  31. data/features/implicit_docstrings.feature +9 -9
  32. data/features/step_definitions/additional_cli_steps.rb +0 -10
  33. data/features/support/env.rb +10 -3
  34. data/features/test_frameworks/test_unit.feature +0 -40
  35. data/lib/rspec-expectations.rb +0 -5
  36. data/lib/rspec/expectations.rb +4 -18
  37. data/lib/rspec/expectations/expectation_target.rb +10 -77
  38. data/lib/rspec/expectations/extensions.rb +0 -1
  39. data/lib/rspec/expectations/handler.rb +1 -5
  40. data/lib/rspec/expectations/syntax.rb +25 -5
  41. data/lib/rspec/expectations/version.rb +1 -1
  42. data/lib/rspec/matchers.rb +7 -102
  43. data/lib/rspec/matchers/built_in/base_matcher.rb +10 -17
  44. data/lib/rspec/matchers/built_in/be.rb +5 -18
  45. data/lib/rspec/matchers/built_in/be_within.rb +2 -8
  46. data/lib/rspec/matchers/built_in/change.rb +1 -39
  47. data/lib/rspec/matchers/built_in/has.rb +7 -40
  48. data/lib/rspec/matchers/built_in/include.rb +1 -1
  49. data/lib/rspec/matchers/built_in/match_array.rb +1 -1
  50. data/lib/rspec/matchers/built_in/raise_error.rb +44 -23
  51. data/lib/rspec/matchers/built_in/respond_to.rb +1 -7
  52. data/lib/rspec/matchers/built_in/satisfy.rb +1 -7
  53. data/lib/rspec/matchers/built_in/throw_symbol.rb +2 -10
  54. data/lib/rspec/matchers/built_in/yield.rb +4 -25
  55. data/lib/rspec/matchers/compatibility.rb +2 -2
  56. data/lib/rspec/{expectations → matchers}/configuration.rb +9 -6
  57. data/lib/rspec/matchers/dsl.rb +2 -4
  58. data/lib/rspec/matchers/matcher.rb +163 -283
  59. data/lib/rspec/matchers/operator_matcher.rb +57 -71
  60. data/lib/rspec/matchers/pretty.rb +0 -4
  61. data/lib/rspec/matchers/test_unit_integration.rb +5 -22
  62. data/spec/rspec/expectations/expectation_target_spec.rb +0 -62
  63. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -4
  64. data/spec/rspec/expectations_spec.rb +2 -43
  65. data/spec/rspec/matchers/base_matcher_spec.rb +12 -27
  66. data/spec/rspec/matchers/be_spec.rb +2 -71
  67. data/spec/rspec/matchers/change_spec.rb +1 -76
  68. data/spec/rspec/{expectations → matchers}/configuration_spec.rb +41 -21
  69. data/spec/rspec/matchers/description_generation_spec.rb +2 -21
  70. data/spec/rspec/matchers/equal_spec.rb +0 -26
  71. data/spec/rspec/matchers/has_spec.rb +0 -24
  72. data/spec/rspec/matchers/match_array_spec.rb +0 -13
  73. data/spec/rspec/matchers/matcher_spec.rb +325 -279
  74. data/spec/rspec/matchers/matchers_spec.rb +36 -0
  75. data/spec/rspec/matchers/operator_matcher_spec.rb +8 -27
  76. data/spec/rspec/matchers/raise_error_spec.rb +65 -209
  77. data/spec/rspec/matchers/yield_spec.rb +32 -9
  78. data/spec/spec_helper.rb +21 -6
  79. data/spec/support/classes.rb +7 -7
  80. data/spec/support/in_sub_process.rb +7 -8
  81. data/spec/support/shared_examples.rb +0 -42
  82. metadata +113 -84
  83. metadata.gz.sig +4 -0
  84. data/features/built_in_matchers/have.feature +0 -109
  85. data/features/built_in_matchers/operators.feature +0 -227
  86. data/lib/rspec/expectations/caller_filter.rb +0 -60
  87. data/lib/rspec/expectations/deprecation.rb +0 -27
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/matchers/be_close.rb +0 -12
  90. data/lib/rspec/matchers/built_in/have.rb +0 -273
  91. data/lib/rspec/matchers/differentiate_block_method_types.rb +0 -55
  92. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  93. data/lib/rspec/matchers/match_aliases.rb +0 -22
  94. data/spec/rspec/matchers/be_close_spec.rb +0 -25
  95. data/spec/rspec/matchers/differentiate_block_method_types_spec.rb +0 -39
  96. data/spec/rspec/matchers/have_spec.rb +0 -853
  97. data/spec/rspec/matchers/pretty_spec.rb +0 -23
  98. data/spec/support/helper_methods.rb +0 -42
@@ -0,0 +1,4 @@
1
+ ���ެ��M���fQ��Ƽ��V��4���A" 5�f���G&ʱD+w���
2
+ p>v�^4R-�)N�J�g�G�<���
3
+ �UŽ�^���b'�
4
+ i�������Ĩ�ik9�gu��@�5?a ��Ejdڳ*:�)�WL�B�i�g�2q �GF��D?�UN|*�����/�|�>)�gMkĺ��<؛tZ
@@ -1,109 +0,0 @@
1
- Feature: have(n).items matcher
2
-
3
- RSpec provides several matchers that make it easy to set expectations about the
4
- size of a collection. There are three basic forms:
5
-
6
- ```ruby
7
- collection.should have(x).items
8
- collection.should have_at_least(x).items
9
- collection.should have_at_most(x).items
10
- ```
11
-
12
- In addition, #have_exactly is provided as an alias to #have.
13
-
14
- These work on any collection-like object--the object just needs to respond to #size
15
- or #length (or both). When the matcher is called directly on a collection object,
16
- the #items call is pure syntactic sugar. You can use anything you want here. These
17
- are equivalent:
18
-
19
- ```ruby
20
- collection.should have(x).items
21
- collection.should have(x).things
22
- ```
23
-
24
- You can also use this matcher on a non-collection object that returns a collection
25
- from one of its methods. For example, Dir#entries returns an array, so you could
26
- set an expectation using the following:
27
-
28
- ```ruby
29
- Dir.new("my/directory").should have(7).entries
30
- ```
31
-
32
- Scenario: have(x).items on a collection
33
- Given a file named "have_items_spec.rb" with:
34
- """ruby
35
- describe [1, 2, 3] do
36
- it { should have(3).items }
37
- it { should_not have(2).items }
38
- it { should_not have(4).items }
39
-
40
- it { should have_exactly(3).items }
41
- it { should_not have_exactly(2).items }
42
- it { should_not have_exactly(4).items }
43
-
44
- it { should have_at_least(2).items }
45
- it { should have_at_most(4).items }
46
-
47
- # deliberate failures
48
- it { should_not have(3).items }
49
- it { should have(2).items }
50
- it { should have(4).items }
51
-
52
- it { should_not have_exactly(3).items }
53
- it { should have_exactly(2).items }
54
- it { should have_exactly(4).items }
55
-
56
- it { should have_at_least(4).items }
57
- it { should have_at_most(2).items }
58
- end
59
- """
60
- When I run `rspec have_items_spec.rb`
61
- Then the output should contain "16 examples, 8 failures"
62
- And the output should contain "expected target not to have 3 items, got 3"
63
- And the output should contain "expected 2 items, got 3"
64
- And the output should contain "expected 4 items, got 3"
65
- And the output should contain "expected at least 4 items, got 3"
66
- And the output should contain "expected at most 2 items, got 3"
67
-
68
- Scenario: have(x).words on a String when String#words is defined
69
- Given a file named "have_words_spec.rb" with:
70
- """ruby
71
- class String
72
- def words
73
- split(' ')
74
- end
75
- end
76
-
77
- describe "a sentence with some words" do
78
- it { should have(5).words }
79
- it { should_not have(4).words }
80
- it { should_not have(6).words }
81
-
82
- it { should have_exactly(5).words }
83
- it { should_not have_exactly(4).words }
84
- it { should_not have_exactly(6).words }
85
-
86
- it { should have_at_least(4).words }
87
- it { should have_at_most(6).words }
88
-
89
- # deliberate failures
90
- it { should_not have(5).words }
91
- it { should have(4).words }
92
- it { should have(6).words }
93
-
94
- it { should_not have_exactly(5).words }
95
- it { should have_exactly(4).words }
96
- it { should have_exactly(6).words }
97
-
98
- it { should have_at_least(6).words }
99
- it { should have_at_most(4).words }
100
- end
101
- """
102
- When I run `rspec have_words_spec.rb`
103
- Then the output should contain "16 examples, 8 failures"
104
- And the output should contain "expected target not to have 5 words, got 5"
105
- And the output should contain "expected 4 words, got 5"
106
- And the output should contain "expected 6 words, got 5"
107
- And the output should contain "expected at least 6 words, got 5"
108
- And the output should contain "expected at most 4 words, got 5"
109
-
@@ -1,227 +0,0 @@
1
- Feature: operator matchers
2
-
3
- RSpec provides a number of matchers that are based on Ruby's built-in
4
- operators. These pretty much work like you expect. For example, each of these
5
- pass:
6
-
7
- ```ruby
8
- 7.should == 7
9
- [1, 2, 3].should == [1, 2, 3]
10
- "this is a string".should =~ /^this/
11
- "this is a string".should_not =~ /^that/
12
- String.should === "this is a string"
13
- ```
14
-
15
- You can also use comparison operators combined with the "be" matcher like
16
- this:
17
-
18
- ```ruby
19
- 37.should be < 100
20
- 37.should be <= 38
21
- 37.should be >= 2
22
- 37.should be > 7
23
- ```
24
-
25
- RSpec also provides a `=~` matcher for arrays that disregards differences in
26
- the ording between the actual and expected array. For example:
27
-
28
- ```ruby
29
- [1, 2, 3].should =~ [2, 3, 1] # pass
30
- [:a, :c, :b].should =~ [:a, :c] # fail
31
- ```
32
-
33
- Scenario: numeric operator matchers
34
- Given a file named "numeric_operator_matchers_spec.rb" with:
35
- """ruby
36
- describe 18 do
37
- it { should == 18 }
38
- it { should be < 20 }
39
- it { should be > 15 }
40
- it { should be <= 19 }
41
- it { should be >= 17 }
42
-
43
- it { should_not == 28 }
44
-
45
- # deliberate failures
46
- it { should == 28 }
47
- it { should be < 15 }
48
- it { should be > 20 }
49
- it { should be <= 17 }
50
- it { should be >= 19 }
51
-
52
- it { should_not == 18 }
53
- end
54
- """
55
- When I run `rspec numeric_operator_matchers_spec.rb`
56
- Then the output should contain "12 examples, 6 failures"
57
- And the output should contain:
58
- """
59
- Failure/Error: it { should == 28 }
60
- expected: 28
61
- got: 18 (using ==)
62
- """
63
- And the output should contain:
64
- """
65
- Failure/Error: it { should be < 15 }
66
- expected: < 15
67
- got: 18
68
- """
69
- And the output should contain:
70
- """
71
- Failure/Error: it { should be > 20 }
72
- expected: > 20
73
- got: 18
74
- """
75
- And the output should contain:
76
- """
77
- Failure/Error: it { should be <= 17 }
78
- expected: <= 17
79
- got: 18
80
- """
81
- And the output should contain:
82
- """
83
- Failure/Error: it { should be >= 19 }
84
- expected: >= 19
85
- got: 18
86
- """
87
- And the output should contain:
88
- """
89
- Failure/Error: it { should_not == 18 }
90
- expected not: == 18
91
- got: 18
92
- """
93
-
94
- Scenario: string operator matchers
95
- Given a file named "string_operator_matchers_spec.rb" with:
96
- """ruby
97
- describe "Strawberry" do
98
- it { should == "Strawberry" }
99
- it { should be < "Tomato" }
100
- it { should be > "Apple" }
101
- it { should be <= "Turnip" }
102
- it { should be >= "Banana" }
103
- it { should =~ /berry/ }
104
-
105
- it { should_not == "Peach" }
106
- it { should_not =~ /apple/ }
107
-
108
- it "reports that it is a string using ===" do
109
- String.should === subject
110
- end
111
-
112
- # deliberate failures
113
- it { should == "Peach" }
114
- it { should be < "Cranberry" }
115
- it { should be > "Zuchini" }
116
- it { should be <= "Potato" }
117
- it { should be >= "Tomato" }
118
- it { should =~ /apple/ }
119
-
120
- it { should_not == "Strawberry" }
121
- it { should_not =~ /berry/ }
122
-
123
- it "fails a spec asserting that it is a symbol" do
124
- Symbol.should === subject
125
- end
126
- end
127
- """
128
- When I run `rspec string_operator_matchers_spec.rb`
129
- Then the output should contain "18 examples, 9 failures"
130
- And the output should contain:
131
- """
132
- Failure/Error: it { should == "Peach" }
133
- expected: "Peach"
134
- got: "Strawberry" (using ==)
135
- """
136
- And the output should contain:
137
- """
138
- Failure/Error: it { should be < "Cranberry" }
139
- expected: < "Cranberry"
140
- got: "Strawberry"
141
- """
142
- And the output should contain:
143
- """
144
- Failure/Error: it { should be > "Zuchini" }
145
- expected: > "Zuchini"
146
- got: "Strawberry"
147
- """
148
- And the output should contain:
149
- """
150
- Failure/Error: it { should be <= "Potato" }
151
- expected: <= "Potato"
152
- got: "Strawberry"
153
- """
154
- And the output should contain:
155
- """
156
- Failure/Error: it { should be >= "Tomato" }
157
- expected: >= "Tomato"
158
- got: "Strawberry"
159
- """
160
- And the output should contain:
161
- """
162
- Failure/Error: it { should =~ /apple/ }
163
- expected: /apple/
164
- got: "Strawberry" (using =~)
165
- """
166
- And the output should contain:
167
- """
168
- Failure/Error: it { should_not == "Strawberry" }
169
- expected not: == "Strawberry"
170
- got: "Strawberry"
171
- """
172
- And the output should contain:
173
- """
174
- Failure/Error: it { should_not =~ /berry/ }
175
- expected not: =~ /berry/
176
- got: "Strawberry"
177
- """
178
- And the output should contain:
179
- """
180
- Failure/Error: Symbol.should === subject
181
- expected: "Strawberry"
182
- got: Symbol (using ===)
183
- """
184
-
185
- Scenario: array operator matchers
186
- Given a file named "array_operator_matchers_spec.rb" with:
187
- """ruby
188
- describe [1, 2, 3] do
189
- it { should == [1, 2, 3] }
190
- it { should_not == [1, 3, 2] }
191
-
192
- it { should =~ [1, 2, 3] }
193
- it { should =~ [1, 3, 2] }
194
- it { should =~ [2, 1, 3] }
195
- it { should =~ [2, 3, 1] }
196
- it { should =~ [3, 1, 2] }
197
- it { should =~ [3, 2, 1] }
198
-
199
- # deliberate failures
200
- it { should_not == [1, 2, 3] }
201
- it { should == [1, 3, 2] }
202
- it { should =~ [1, 2, 1] }
203
- end
204
- """
205
- When I run `rspec array_operator_matchers_spec.rb`
206
- Then the output should contain "11 examples, 3 failures"
207
- And the output should contain:
208
- """
209
- Failure/Error: it { should_not == [1, 2, 3] }
210
- expected not: == [1, 2, 3]
211
- got: [1, 2, 3]
212
- """
213
- And the output should contain:
214
- """
215
- Failure/Error: it { should == [1, 3, 2] }
216
- expected: [1, 3, 2]
217
- got: [1, 2, 3] (using ==)
218
- """
219
- And the output should contain:
220
- """
221
- Failure/Error: it { should =~ [1, 2, 1] }
222
- expected collection contained: [1, 1, 2]
223
- actual collection contained: [1, 2, 3]
224
- the missing elements were: [1]
225
- the extra elements were: [3]
226
- """
227
-
@@ -1,60 +0,0 @@
1
- module RSpec
2
- # Consistent implementation for "cleaning" the caller method to strip out
3
- # non-rspec lines. This enables errors to be reported at the call site in
4
- # the code using the library, which is far more useful than the particular
5
- # internal method that raised an error.
6
-
7
- unless defined?(CallerFilter)
8
-
9
- class CallerFilter
10
-
11
- RSPEC_LIBS = %w[
12
- core
13
- mocks
14
- expectations
15
- matchers
16
- rails
17
- ]
18
-
19
- ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
20
-
21
- LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
22
-
23
- if RUBY_VERSION >= '2.0.0'
24
- def self.first_non_rspec_line
25
- # `caller` is an expensive method that scales linearly with the size of
26
- # the stack. The performance hit for fetching it in chunks is small,
27
- # and since the target line is probably near the top of the stack, the
28
- # overall improvement of a chunked search like this is significant.
29
- #
30
- # See benchmarks/caller.rb for measurements.
31
-
32
- # Initial value here is mostly arbitrary, but is chosen to give good
33
- # performance on the common case of creating a double.
34
- increment = 5
35
- i = 1
36
- line = nil
37
-
38
- while !line
39
- stack = caller(i, increment)
40
- return nil unless stack
41
-
42
- line = stack.find { |l| l !~ LIB_REGEX }
43
-
44
- i += increment
45
- increment *= 2 # The choice of two here is arbitrary.
46
- end
47
-
48
- line
49
- end
50
- else
51
- # Earlier rubies do not support the two argument form of `caller`. This
52
- # fallback is logically the same, but slower.
53
- def self.first_non_rspec_line
54
- caller.find { |line| line !~ LIB_REGEX }
55
- end
56
- end
57
- end
58
-
59
- end
60
- end
@@ -1,27 +0,0 @@
1
- require 'rspec/expectations/caller_filter' unless defined?(::RSpec::CallerFilter)
2
-
3
- module RSpec
4
- module Expectations
5
- module Deprecation
6
- # @private
7
- #
8
- # Used internally to print deprecation warnings
9
- def deprecate(deprecated, options={})
10
- message = "DEPRECATION: #{deprecated} is deprecated."
11
- message << " Use #{options[:replacement]} instead." if options[:replacement]
12
- message << " Called from #{CallerFilter.first_non_rspec_line}."
13
- warn message
14
- end
15
-
16
- # @private
17
- #
18
- # Used internally to print deprecation warnings
19
- def warn_deprecation(warning)
20
- message = "\nDEPRECATION: #{warning}\n"
21
- warn message
22
- end
23
- end
24
- end
25
-
26
- extend(Expectations::Deprecation) unless respond_to?(:deprecate)
27
- end
@@ -1,9 +0,0 @@
1
- # @private
2
- class Array
3
- unless public_instance_methods.map {|m| m.to_s}.include?('none?')
4
- # Supports +none?+ on early patch levels of Ruby 1.8.6
5
- def none?(&block)
6
- !any?(&block)
7
- end
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- # @deprecated use +be_within+ instead.
4
- def be_close(expected, delta)
5
- RSpec.deprecate("be_close(#{expected}, #{delta})",
6
- :replacement => "be_within(#{delta}).of(#{expected})",
7
- :type => 'the be_close matcher'
8
- )
9
- be_within(delta).of(expected)
10
- end
11
- end
12
- end