rspec-expectations 2.3.0 → 2.4.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 (37) hide show
  1. data/Guardfile +5 -0
  2. data/History.markdown +10 -0
  3. data/Rakefile +2 -2
  4. data/features/.nav +27 -0
  5. data/features/README.markdown +26 -2
  6. data/features/{matchers → built_in_matchers}/be.feature +31 -45
  7. data/features/{matchers → built_in_matchers}/be_within.feature +0 -0
  8. data/features/{matchers → built_in_matchers}/equality.feature +1 -1
  9. data/features/{matchers → built_in_matchers}/exist.feature +0 -0
  10. data/features/{matchers → built_in_matchers}/expect_change.feature +1 -1
  11. data/features/{matchers → built_in_matchers}/expect_error.feature +1 -1
  12. data/features/{matchers → built_in_matchers}/have.feature +0 -0
  13. data/features/{matchers → built_in_matchers}/include.feature +0 -0
  14. data/features/{matchers → built_in_matchers}/match.feature +0 -0
  15. data/features/built_in_matchers/operators.feature +221 -0
  16. data/features/{matchers → built_in_matchers}/predicates.feature +1 -1
  17. data/features/{matchers → built_in_matchers}/respond_to.feature +0 -0
  18. data/features/{matchers → built_in_matchers}/satisfy.feature +1 -1
  19. data/features/{matchers → built_in_matchers}/throw_symbol.feature +1 -1
  20. data/features/{matchers → built_in_matchers}/types.feature +0 -0
  21. data/features/{matchers → custom_matchers}/access_running_example.feature +1 -1
  22. data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
  23. data/features/{matchers → custom_matchers}/define_matcher.feature +1 -1
  24. data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
  25. data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +1 -1
  26. data/features/{expectations/customized_message.feature → customized_message.feature} +0 -0
  27. data/features/{expectations/diffing.feature → diffing.feature} +12 -12
  28. data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +0 -0
  29. data/lib/rspec/expectations/version.rb +1 -1
  30. data/lib/rspec/matchers/be.rb +4 -4
  31. data/lib/rspec/matchers/change.rb +25 -19
  32. data/lib/rspec/matchers/operator_matcher.rb +3 -3
  33. data/spec/rspec/matchers/be_spec.rb +8 -8
  34. data/spec/rspec/matchers/operator_matcher_spec.rb +10 -10
  35. metadata +55 -57
  36. data/features/expectations/attribute_of_subject.feature +0 -19
  37. data/features/matchers/operators.feature +0 -280
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch('^spec/(.*)_spec.rb')
3
+ watch('^lib/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('^spec/spec_helper.rb') { "spec" }
5
+ end
@@ -1,5 +1,15 @@
1
1
  ## rspec-expectations release history (incomplete)
2
2
 
3
+ ### 2.4.0 / 2011-01-02
4
+
5
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.3.0...v2.4.0)
6
+
7
+ No functional changes in this release, which was made to align with the
8
+ rspec-core-2.4.0 release.
9
+
10
+ * Enhancements
11
+ * improved RDoc for change matcher (Jo Liss)
12
+
3
13
  ### 2.3.0 / 2010-12-12
4
14
 
5
15
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0)
data/Rakefile CHANGED
@@ -55,10 +55,10 @@ Rake::RDocTask.new do |rdoc|
55
55
  rdoc.rdoc_files.include('lib/**/*.rb')
56
56
  end
57
57
 
58
- desc "Push cukes to relishapp using the relish-client-gem"
58
+ desc "Push docs/cukes to relishapp using the relish-client-gem"
59
59
  task :relish, :version do |t, args|
60
60
  raise "rake relish[VERSION]" unless args[:version]
61
- sh "bundle exec relish push --organization rspec --project rspec-expectations -v #{args[:version]}"
61
+ sh "relish push rspec/rspec-expectations:#{args[:version]}"
62
62
  end
63
63
 
64
64
  task :clobber do
@@ -0,0 +1,27 @@
1
+ - customized_message.feature
2
+ - diffing.feature
3
+ - implicit_docstrings.feature
4
+ - built_in_matchers:
5
+ - be.feature
6
+ - be_within.feature
7
+ - equality.feature
8
+ - exist.feature
9
+ - expect_change.feature
10
+ - expect_error.feature
11
+ - have.feature
12
+ - include.feature
13
+ - match.feature
14
+ - operators.feature
15
+ - predicates.feature
16
+ - respond_to.feature
17
+ - satisfy.feature
18
+ - throw_symbol.feature
19
+ - types.feature
20
+ - custom_matchers:
21
+ - define_matcher.feature
22
+ - define_diffable_matcher.feature
23
+ - define_matcher_with_fluent_interface.feature
24
+ - access_running_example.feature
25
+ - define_matcher_outside_rspec.feature
26
+ - test_frameworks:
27
+ - test_unit.feature
@@ -1,5 +1,4 @@
1
- rspec-expectations is used to set expectations in executable
2
- examples:
1
+ rspec-expectations is used to set expectations in executable examples.
3
2
 
4
3
  describe Account do
5
4
  it "has a balance of zero when first created" do
@@ -7,6 +6,31 @@ examples:
7
6
  end
8
7
  end
9
8
 
9
+ ## should and should_not
10
+
11
+ rspec-expectations adds `should` and `should_not` to every object. Each of
12
+ these can accept a matcher and, in most cases, an optional custom failure
13
+ message (see [customized
14
+ message](/rspec/rspec-expectations/v/2-3/customized-message)).
15
+
16
+ ## Matchers
17
+
18
+ A Matcher is any object that responds to the following methods:
19
+
20
+ matches?(actual)
21
+ failure_message_for_should
22
+
23
+ These methods are also part of the matcher protocol, but are optional:
24
+
25
+ does_not_match?(actual)
26
+ failure_message_for_should_not
27
+ description
28
+
29
+ RSpec ships with a number of [built-in
30
+ matchers](/rspec/rspec-expectations/v/2-3/dir/built-in-matchers) and a DSL for
31
+ writing your own [custom
32
+ matchers](/rspec/rspec-expectations/v/2-3/dir/custom-matchers).
33
+
10
34
  ## Issues
11
35
 
12
36
  The documentation for rspec-expectations is a work in progress. We'll be adding
@@ -1,15 +1,11 @@
1
- Feature: be matchers
1
+ Feature: "be" matchers
2
2
 
3
3
  There are several related "be" matchers:
4
4
 
5
- * obj.should be_true # passes if obj is truthy (not nil or false)
6
- * obj.should be_false # passes if obj is falsey (nil or false)
7
- * obj.should be_nil # passes if obj is nil
8
- * obj.should be # passes if obj is not nil
9
- * obj.should be < expected # passes if obj < expected
10
- * obj.should be > expected # passes if obj > expected
11
- * obj.should be <= expected # passes if obj <= expected
12
- * obj.should be >= expected # passes if obj >= expected
5
+ obj.should be_true # passes if obj is truthy (not nil or false)
6
+ obj.should be_false # passes if obj is falsy (nil or false)
7
+ obj.should be_nil # passes if obj is nil
8
+ obj.should be # passes if obj is not nil
13
9
 
14
10
  Scenario: be_true matcher
15
11
  Given a file named "be_true_spec.rb" with:
@@ -84,13 +80,32 @@ Feature: be matchers
84
80
  end
85
81
  """
86
82
  When I run "rspec be_nil_spec.rb"
87
- Then the output should contain all of these:
88
- | 10 examples, 5 failures |
89
- | expected not nil, got nil |
90
- | expected nil, got false |
91
- | expected nil, got true |
92
- | expected nil, got 7 |
93
- | expected nil, got "foo" |
83
+ Then the output should contain "10 examples, 5 failures"
84
+ And the output should contain:
85
+ """
86
+ expected: not nil
87
+ got: nil
88
+ """
89
+ And the output should contain:
90
+ """
91
+ expected: nil
92
+ got: false
93
+ """
94
+ And the output should contain:
95
+ """
96
+ expected: nil
97
+ got: true
98
+ """
99
+ And the output should contain:
100
+ """
101
+ expected: nil
102
+ got: 7
103
+ """
104
+ And the output should contain:
105
+ """
106
+ expected: nil
107
+ got: "foo"
108
+ """
94
109
 
95
110
  Scenario: be matcher
96
111
  Given a file named "be_spec.rb" with:
@@ -118,32 +133,3 @@ Feature: be matchers
118
133
  | expected "foo" to evaluate to false |
119
134
  | expected nil to evaluate to true |
120
135
  | expected false to evaluate to true |
121
-
122
- Scenario: be operator matchers
123
- Given a file named "be_operators_spec.rb" with:
124
- """
125
- describe 17 do
126
- it { should be < 20 }
127
- it { should be > 15 }
128
- it { should be <= 17 }
129
- it { should be >= 17 }
130
- it { should_not be < 15 }
131
- it { should_not be > 20 }
132
- it { should_not be <= 16 }
133
- it { should_not be >= 18 }
134
-
135
- # deliberate failures
136
- it { should be < 15 }
137
- it { should be > 20 }
138
- it { should be <= 16 }
139
- it { should be >= 18 }
140
- end
141
- """
142
- When I run "rspec be_operators_spec.rb"
143
- Then the output should contain all of these:
144
- | 12 examples, 4 failures |
145
- | expected < 15, got 17 |
146
- | expected > 20, got 17 |
147
- | expected <= 16, got 17 |
148
- | expected >= 18, got 17 |
149
-
@@ -1,4 +1,4 @@
1
- Feature: Equality matchers
1
+ Feature: equality matchers
2
2
 
3
3
  Ruby exposes several different methods for handling equality:
4
4
 
@@ -1,4 +1,4 @@
1
- Feature: Expect change
1
+ Feature: expect change
2
2
 
3
3
  Expect some code (wrapped in a proc) to change the state of some object.
4
4
 
@@ -1,4 +1,4 @@
1
- Feature: Expect error
1
+ Feature: expect error
2
2
 
3
3
  Expect a proc to raise an error when called.
4
4
 
@@ -0,0 +1,221 @@
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
+ 7.should == 7
8
+ [1, 2, 3].should == [1, 2, 3]
9
+ "this is a string".should =~ /^this/
10
+ "this is a string".should_not =~ /^that/
11
+ String.should === "this is a string"
12
+
13
+ You can also use comparison operators combined with the "be" matcher like
14
+ this:
15
+
16
+ 37.should be < 100
17
+ 37.should be <= 38
18
+ 37.should be >= 2
19
+ 37.should be > 7
20
+
21
+ RSpec also provides a `=~` matcher for arrays that disregards differences in
22
+ the ording between the actual and expected array. For example:
23
+
24
+ [1, 2, 3].should =~ [2, 3, 1] # pass
25
+ [:a, :c, :b].should =~ [:a, :c] # fail
26
+
27
+ Scenario: numeric operator matchers
28
+ Given a file named "numeric_operator_matchers_spec.rb" with:
29
+ """
30
+ describe 18 do
31
+ it { should == 18 }
32
+ it { should be < 20 }
33
+ it { should be > 15 }
34
+ it { should be <= 19 }
35
+ it { should be >= 17 }
36
+
37
+ it { should_not == 28 }
38
+
39
+ # deliberate failures
40
+ it { should == 28 }
41
+ it { should be < 15 }
42
+ it { should be > 20 }
43
+ it { should be <= 17 }
44
+ it { should be >= 19 }
45
+
46
+ it { should_not == 18 }
47
+ end
48
+ """
49
+ When I run "rspec numeric_operator_matchers_spec.rb"
50
+ Then the output should contain "12 examples, 6 failures"
51
+ And the output should contain:
52
+ """
53
+ Failure/Error: it { should == 28 }
54
+ expected: 28
55
+ got: 18 (using ==)
56
+ """
57
+ And the output should contain:
58
+ """
59
+ Failure/Error: it { should be < 15 }
60
+ expected: < 15
61
+ got: 18
62
+ """
63
+ And the output should contain:
64
+ """
65
+ Failure/Error: it { should be > 20 }
66
+ expected: > 20
67
+ got: 18
68
+ """
69
+ And the output should contain:
70
+ """
71
+ Failure/Error: it { should be <= 17 }
72
+ expected: <= 17
73
+ got: 18
74
+ """
75
+ And the output should contain:
76
+ """
77
+ Failure/Error: it { should be >= 19 }
78
+ expected: >= 19
79
+ got: 18
80
+ """
81
+ And the output should contain:
82
+ """
83
+ Failure/Error: it { should_not == 18 }
84
+ expected not: == 18
85
+ got: 18
86
+ """
87
+
88
+ Scenario: string operator matchers
89
+ Given a file named "string_operator_matchers_spec.rb" with:
90
+ """
91
+ describe "Strawberry" do
92
+ it { should == "Strawberry" }
93
+ it { should be < "Tomato" }
94
+ it { should be > "Apple" }
95
+ it { should be <= "Turnip" }
96
+ it { should be >= "Banana" }
97
+ it { should =~ /berry/ }
98
+
99
+ it { should_not == "Peach" }
100
+ it { should_not =~ /apple/ }
101
+
102
+ it "reports that it is a string using ===" do
103
+ String.should === subject
104
+ end
105
+
106
+ # deliberate failures
107
+ it { should == "Peach" }
108
+ it { should be < "Cranberry" }
109
+ it { should be > "Zuchini" }
110
+ it { should be <= "Potato" }
111
+ it { should be >= "Tomato" }
112
+ it { should =~ /apple/ }
113
+
114
+ it { should_not == "Strawberry" }
115
+ it { should_not =~ /berry/ }
116
+
117
+ it "fails a spec asserting that it is a symbol" do
118
+ Symbol.should === subject
119
+ end
120
+ end
121
+ """
122
+ When I run "rspec string_operator_matchers_spec.rb"
123
+ Then the output should contain "18 examples, 9 failures"
124
+ And the output should contain:
125
+ """
126
+ Failure/Error: it { should == "Peach" }
127
+ expected: "Peach"
128
+ got: "Strawberry" (using ==)
129
+ """
130
+ And the output should contain:
131
+ """
132
+ Failure/Error: it { should be < "Cranberry" }
133
+ expected: < "Cranberry"
134
+ got: "Strawberry"
135
+ """
136
+ And the output should contain:
137
+ """
138
+ Failure/Error: it { should be > "Zuchini" }
139
+ expected: > "Zuchini"
140
+ got: "Strawberry"
141
+ """
142
+ And the output should contain:
143
+ """
144
+ Failure/Error: it { should be <= "Potato" }
145
+ expected: <= "Potato"
146
+ got: "Strawberry"
147
+ """
148
+ And the output should contain:
149
+ """
150
+ Failure/Error: it { should be >= "Tomato" }
151
+ expected: >= "Tomato"
152
+ got: "Strawberry"
153
+ """
154
+ And the output should contain:
155
+ """
156
+ Failure/Error: it { should =~ /apple/ }
157
+ expected: /apple/
158
+ got: "Strawberry" (using =~)
159
+ """
160
+ And the output should contain:
161
+ """
162
+ Failure/Error: it { should_not == "Strawberry" }
163
+ expected not: == "Strawberry"
164
+ got: "Strawberry"
165
+ """
166
+ And the output should contain:
167
+ """
168
+ Failure/Error: it { should_not =~ /berry/ }
169
+ expected not: =~ /berry/
170
+ got: "Strawberry"
171
+ """
172
+ And the output should contain:
173
+ """
174
+ Failure/Error: Symbol.should === subject
175
+ expected: "Strawberry"
176
+ got: Symbol (using ===)
177
+ """
178
+
179
+ Scenario: array operator matchers
180
+ Given a file named "array_operator_matchers_spec.rb" with:
181
+ """
182
+ describe [1, 2, 3] do
183
+ it { should == [1, 2, 3] }
184
+ it { should_not == [1, 3, 2] }
185
+
186
+ it { should =~ [1, 2, 3] }
187
+ it { should =~ [1, 3, 2] }
188
+ it { should =~ [2, 1, 3] }
189
+ it { should =~ [2, 3, 1] }
190
+ it { should =~ [3, 1, 2] }
191
+ it { should =~ [3, 2, 1] }
192
+
193
+ # deliberate failures
194
+ it { should_not == [1, 2, 3] }
195
+ it { should == [1, 3, 2] }
196
+ it { should =~ [1, 2, 1] }
197
+ end
198
+ """
199
+ When I run "rspec array_operator_matchers_spec.rb"
200
+ Then the output should contain "11 examples, 3 failures"
201
+ And the output should contain:
202
+ """
203
+ Failure/Error: it { should_not == [1, 2, 3] }
204
+ expected not: == [1, 2, 3]
205
+ got: [1, 2, 3]
206
+ """
207
+ And the output should contain:
208
+ """
209
+ Failure/Error: it { should == [1, 3, 2] }
210
+ expected: [1, 3, 2]
211
+ got: [1, 2, 3] (using ==)
212
+ """
213
+ And the output should contain:
214
+ """
215
+ Failure/Error: it { should =~ [1, 2, 1] }
216
+ expected collection contained: [1, 1, 2]
217
+ actual collection contained: [1, 2, 3]
218
+ the missing elements were: [1]
219
+ the extra elements were: [3]
220
+ """
221
+