rspec-expectations 2.0.0.beta.22 → 2.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  *.sw?
2
2
  .DS_Store
3
- coverage
3
+ coverage*
4
4
  rdoc
5
5
  pkg
6
6
  doc
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gem "rspec-expectations", :path => "."
9
9
  gem "rspec-core", :path => "../rspec-core"
10
10
  gem "rspec-mocks", :path => "../rspec-mocks"
11
11
  gem "watchr"
12
+ gem "rcov"
12
13
 
13
14
  case RUBY_VERSION
14
15
  when '1.9.2'
@@ -1,5 +1,16 @@
1
1
  ## rspec-expectations release history (incomplete)
2
2
 
3
+ ### 2.0.0.rc / 2010-10-05
4
+
5
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.22...v2.0.0.rc)
6
+
7
+ * Enhancements
8
+ * require 'rspec/expectations' in a T::U or MiniUnit suite (Josep M. Bach)
9
+
10
+ * Bug fixes
11
+ * change by 0 passes/fails correctly (Len Smith)
12
+ * Add description to satisfy matcher
13
+
3
14
  ### 2.0.0.beta.22 / 2010-09-12
4
15
 
5
16
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.20...v2.0.0.beta.22)
@@ -13,4 +24,3 @@
13
24
 
14
25
  * Bug fixes
15
26
  * should[_not] change now handles boolean values correctly
16
-
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ Bundler::GemHelper.install_tasks
5
5
  require 'rake'
6
6
  require 'rake/rdoctask'
7
7
  require 'rspec/core/rake_task'
8
+ require 'rspec/expectations/version'
8
9
  require 'cucumber/rake/task'
9
10
 
10
11
  RSpec::Core::RakeTask.new(:spec)
@@ -17,8 +18,22 @@ class Cucumber::Rake::Task::ForkedCucumberRunner
17
18
  end
18
19
  end
19
20
 
20
- Cucumber::Rake::Task.new do |t|
21
+ desc "Run all examples using rcov"
22
+ RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
23
+ t.rcov = true
24
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
25
+ t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
26
+ end
27
+
28
+ task :cleanup_rcov_files do
29
+ rm_rf 'coverage.data'
30
+ end
31
+
32
+ Cucumber::Rake::Task.new :cucumber => :cleanup_rcov_files do |t|
21
33
  t.cucumber_opts = %w{--format progress}
34
+ t.rcov = true
35
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
36
+ t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
22
37
  end
23
38
 
24
39
  task :default => [:spec, :cucumber]
@@ -24,7 +24,7 @@ Feature: implicit docstrings
24
24
  And the output should contain "should include 2"
25
25
  And the output should contain "should respond to #size"
26
26
 
27
- Scenario Outline: run failing examples
27
+ Scenario: run failing examples
28
28
  Given a file named "failing_implicit_docstrings_spec.rb" with:
29
29
  """
30
30
  describe "Failing examples with no descriptions" do
@@ -48,5 +48,5 @@ Feature: implicit docstrings
48
48
 
49
49
  Then the output should contain "should equal 2"
50
50
  And the output should contain "should be > 5"
51
- And the output should contain "should include "b""
51
+ And the output should contain "should include 4"
52
52
  And the output should contain "should not respond to #size"
@@ -1,6 +1,6 @@
1
1
  Feature: expect error
2
2
 
3
- Expect a proc to change the state of some object.
3
+ Expect a proc to raise an error when called.
4
4
 
5
5
  Scenario: expect error
6
6
  Given a file named "expect_error_spec.rb" with:
@@ -0,0 +1,103 @@
1
+ Feature: have matchers
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
+ * collection.should have(x).items
7
+ * collection.should have_at_least(x).items
8
+ * collection.should have_at_most(x).items
9
+
10
+ In addition, #have_exactly is provided as an alias to #have.
11
+
12
+ These work on any collection-like object--the object just needs to respond to #size
13
+ or #length (or both). When the matcher is called directly on a collection object,
14
+ the #items call is pure syntactic sugar. You can use anything you want here. These
15
+ are equivalent:
16
+
17
+ * collection.should have(x).items
18
+ * collection.should have(x).things
19
+
20
+ You can also use this matcher on a non-collection object that returns a collection
21
+ from one of its methods. For example, Dir#entries returns an array, so you could
22
+ set an expectation using the following:
23
+
24
+ Dir.new("my/directory").should have(7).entries
25
+
26
+ Scenario: have(x).items on a collection
27
+ Given a file named "have_items_spec.rb" with:
28
+ """
29
+ describe [1, 2, 3] do
30
+ it { should have(3).items }
31
+ it { should_not have(2).items }
32
+ it { should_not have(4).items }
33
+
34
+ it { should have_exactly(3).items }
35
+ it { should_not have_exactly(2).items }
36
+ it { should_not have_exactly(4).items }
37
+
38
+ it { should have_at_least(2).items }
39
+ it { should have_at_most(4).items }
40
+
41
+ # deliberate failures
42
+ it { should_not have(3).items }
43
+ it { should have(2).items }
44
+ it { should have(4).items }
45
+
46
+ it { should_not have_exactly(3).items }
47
+ it { should have_exactly(2).items }
48
+ it { should have_exactly(4).items }
49
+
50
+ it { should have_at_least(4).items }
51
+ it { should have_at_most(2).items }
52
+ end
53
+ """
54
+ When I run "rspec have_items_spec.rb"
55
+ Then the output should contain "16 examples, 8 failures"
56
+ And the output should contain "expected target not to have 3 items, got 3"
57
+ And the output should contain "expected 2 items, got 3"
58
+ And the output should contain "expected 4 items, got 3"
59
+ And the output should contain "expected at least 4 items, got 3"
60
+ And the output should contain "expected at most 2 items, got 3"
61
+
62
+ Scenario: have(x).words on a String when String#words is defined
63
+ Given a file named "have_words_spec.rb" with:
64
+ """
65
+ class String
66
+ def words
67
+ split(' ')
68
+ end
69
+ end
70
+
71
+ describe "a sentence with some words" do
72
+ it { should have(5).words }
73
+ it { should_not have(4).words }
74
+ it { should_not have(6).words }
75
+
76
+ it { should have_exactly(5).words }
77
+ it { should_not have_exactly(4).words }
78
+ it { should_not have_exactly(6).words }
79
+
80
+ it { should have_at_least(4).words }
81
+ it { should have_at_most(6).words }
82
+
83
+ # deliberate failures
84
+ it { should_not have(5).words }
85
+ it { should have(4).words }
86
+ it { should have(6).words }
87
+
88
+ it { should_not have_exactly(5).words }
89
+ it { should have_exactly(4).words }
90
+ it { should have_exactly(6).words }
91
+
92
+ it { should have_at_least(6).words }
93
+ it { should have_at_most(4).words }
94
+ end
95
+ """
96
+ When I run "rspec have_words_spec.rb"
97
+ Then the output should contain "16 examples, 8 failures"
98
+ And the output should contain "expected target not to have 5 words, got 5"
99
+ And the output should contain "expected 4 words, got 5"
100
+ And the output should contain "expected 6 words, got 5"
101
+ And the output should contain "expected at least 6 words, got 5"
102
+ And the output should contain "expected at most 4 words, got 5"
103
+
@@ -0,0 +1,280 @@
1
+ Feature: Operator Matchers
2
+
3
+ RSpec provides a number of matchers that are based on Ruby's built-in
4
+ operators. These mostly work like you expect. For example, each of these pass:
5
+
6
+ * 7.should == 7
7
+ * 25.2.should < 100
8
+ * 8.should > 7
9
+ * 17.should <= 17
10
+ * 3.should >= 2
11
+ * [1, 2, 3].should == [1, 2, 3]
12
+ * "this is a string".should =~ /^this/
13
+ * "this is a string".should_not =~ /^that/
14
+ * String.should === "this is a string"
15
+
16
+ RSpec also provides a `=~` matcher for arrays that disregards differences in
17
+ the ording between the actual and expected array. For example:
18
+
19
+ * [1, 2, 3].should =~ [2, 3, 1] # pass
20
+ * [:a, :c, :b].should =~ [:a, :c] # fail
21
+
22
+ Scenario: numeric operator matchers
23
+ Given a file named "numeric_operator_matchers_spec.rb" with:
24
+ """
25
+ describe 18 do
26
+ it { should == 18 }
27
+ it { should < 20 }
28
+ it { should > 15 }
29
+ it { should <= 19 }
30
+ it { should >= 17 }
31
+
32
+ it { should_not == 28 }
33
+ it { should_not < 15 }
34
+ it { should_not > 20 }
35
+ it { should_not <= 17 }
36
+ it { should_not >= 19 }
37
+
38
+ # deliberate failures
39
+ it { should == 28 }
40
+ it { should < 15 }
41
+ it { should > 20 }
42
+ it { should <= 17 }
43
+ it { should >= 19 }
44
+
45
+ it { should_not == 18 }
46
+ it { should_not < 20 }
47
+ it { should_not > 15 }
48
+ it { should_not <= 19 }
49
+ it { should_not >= 17 }
50
+ end
51
+ """
52
+ When I run "rspec numeric_operator_matchers_spec.rb"
53
+ Then the output should contain "20 examples, 10 failures"
54
+ And the output should contain:
55
+ """
56
+ Failure/Error: it { should == 28 }
57
+ expected: 28,
58
+ got: 18 (using ==)
59
+ """
60
+ And the output should contain:
61
+ """
62
+ Failure/Error: it { should < 15 }
63
+ expected: < 15,
64
+ got: 18
65
+ """
66
+ And the output should contain:
67
+ """
68
+ Failure/Error: it { should > 20 }
69
+ expected: > 20,
70
+ got: 18
71
+ """
72
+ And the output should contain:
73
+ """
74
+ Failure/Error: it { should <= 17 }
75
+ expected: <= 17,
76
+ got: 18
77
+ """
78
+ And the output should contain:
79
+ """
80
+ Failure/Error: it { should >= 19 }
81
+ expected: >= 19,
82
+ got: 18
83
+ """
84
+ And the output should contain:
85
+ """
86
+ Failure/Error: it { should_not == 18 }
87
+ expected not: == 18,
88
+ got: 18
89
+ """
90
+ And the output should contain:
91
+ """
92
+ Failure/Error: it { should_not < 20 }
93
+ expected not: < 20,
94
+ got: 18
95
+ """
96
+ And the output should contain:
97
+ """
98
+ Failure/Error: it { should_not > 15 }
99
+ expected not: > 15,
100
+ got: 18
101
+ """
102
+ And the output should contain:
103
+ """
104
+ Failure/Error: it { should_not <= 19 }
105
+ expected not: <= 19,
106
+ got: 18
107
+ """
108
+ And the output should contain:
109
+ """
110
+ Failure/Error: it { should_not >= 17 }
111
+ expected not: >= 17,
112
+ got: 18
113
+ """
114
+
115
+ Scenario: string operator matchers
116
+ Given a file named "string_operator_matchers_spec.rb" with:
117
+ """
118
+ describe "Strawberry" do
119
+ it { should == "Strawberry" }
120
+ it { should < "Tomato" }
121
+ it { should > "Apple" }
122
+ it { should <= "Turnip" }
123
+ it { should >= "Banana" }
124
+ it { should =~ /berry/ }
125
+
126
+ it { should_not == "Peach" }
127
+ it { should_not < "Cranberry" }
128
+ it { should_not > "Zuchini" }
129
+ it { should_not <= "Potato" }
130
+ it { should_not >= "Tomato" }
131
+ it { should_not =~ /apple/ }
132
+
133
+ it "reports that it is a string using ===" do
134
+ String.should === subject
135
+ end
136
+
137
+ # deliberate failures
138
+ it { should == "Peach" }
139
+ it { should < "Cranberry" }
140
+ it { should > "Zuchini" }
141
+ it { should <= "Potato" }
142
+ it { should >= "Tomato" }
143
+ it { should =~ /apple/ }
144
+
145
+ it { should_not == "Strawberry" }
146
+ it { should_not < "Tomato" }
147
+ it { should_not > "Apple" }
148
+ it { should_not <= "Turnip" }
149
+ it { should_not >= "Banana" }
150
+ it { should_not =~ /berry/ }
151
+
152
+ it "fails a spec asserting that it is a symbol" do
153
+ Symbol.should === subject
154
+ end
155
+ end
156
+ """
157
+ When I run "rspec string_operator_matchers_spec.rb"
158
+ Then the output should contain "26 examples, 13 failures"
159
+ And the output should contain:
160
+ """
161
+ Failure/Error: it { should == "Peach" }
162
+ expected: "Peach",
163
+ got: "Strawberry" (using ==)
164
+ """
165
+ And the output should contain:
166
+ """
167
+ Failure/Error: it { should < "Cranberry" }
168
+ expected: < "Cranberry",
169
+ got: "Strawberry"
170
+ """
171
+ And the output should contain:
172
+ """
173
+ Failure/Error: it { should > "Zuchini" }
174
+ expected: > "Zuchini",
175
+ got: "Strawberry"
176
+ """
177
+ And the output should contain:
178
+ """
179
+ Failure/Error: it { should <= "Potato" }
180
+ expected: <= "Potato",
181
+ got: "Strawberry"
182
+ """
183
+ And the output should contain:
184
+ """
185
+ Failure/Error: it { should >= "Tomato" }
186
+ expected: >= "Tomato",
187
+ got: "Strawberry"
188
+ """
189
+ And the output should contain:
190
+ """
191
+ Failure/Error: it { should =~ /apple/ }
192
+ expected: /apple/,
193
+ got: "Strawberry" (using =~)
194
+ """
195
+ And the output should contain:
196
+ """
197
+ Failure/Error: it { should_not == "Strawberry" }
198
+ expected not: == "Strawberry",
199
+ got: "Strawberry"
200
+ """
201
+ And the output should contain:
202
+ """
203
+ Failure/Error: it { should_not < "Tomato" }
204
+ expected not: < "Tomato",
205
+ got: "Strawberry"
206
+ """
207
+ And the output should contain:
208
+ """
209
+ Failure/Error: it { should_not > "Apple" }
210
+ expected not: > "Apple",
211
+ got: "Strawberry"
212
+ """
213
+ And the output should contain:
214
+ """
215
+ Failure/Error: it { should_not <= "Turnip" }
216
+ expected not: <= "Turnip",
217
+ got: "Strawberry"
218
+ """
219
+ And the output should contain:
220
+ """
221
+ Failure/Error: it { should_not >= "Banana" }
222
+ expected not: >= "Banana",
223
+ got: "Strawberry"
224
+ """
225
+ And the output should contain:
226
+ """
227
+ Failure/Error: it { should_not =~ /berry/ }
228
+ expected not: =~ /berry/,
229
+ got: "Strawberry"
230
+ """
231
+ And the output should contain:
232
+ """
233
+ Failure/Error: Symbol.should === subject
234
+ expected: "Strawberry",
235
+ got: Symbol (using ===)
236
+ """
237
+
238
+ Scenario: array operator matchers
239
+ Given a file named "array_operator_matchers_spec.rb" with:
240
+ """
241
+ describe [1, 2, 3] do
242
+ it { should == [1, 2, 3] }
243
+ it { should_not == [1, 3, 2] }
244
+
245
+ it { should =~ [1, 2, 3] }
246
+ it { should =~ [1, 3, 2] }
247
+ it { should =~ [2, 1, 3] }
248
+ it { should =~ [2, 3, 1] }
249
+ it { should =~ [3, 1, 2] }
250
+ it { should =~ [3, 2, 1] }
251
+
252
+ # deliberate failures
253
+ it { should_not == [1, 2, 3] }
254
+ it { should == [1, 3, 2] }
255
+ it { should =~ [1, 2, 1] }
256
+ end
257
+ """
258
+ When I run "rspec array_operator_matchers_spec.rb"
259
+ Then the output should contain "11 examples, 3 failures"
260
+ And the output should contain:
261
+ """
262
+ Failure/Error: it { should_not == [1, 2, 3] }
263
+ expected not: == [1, 2, 3],
264
+ got: [1, 2, 3]
265
+ """
266
+ And the output should contain:
267
+ """
268
+ Failure/Error: it { should == [1, 3, 2] }
269
+ expected: [1, 3, 2],
270
+ got: [1, 2, 3] (using ==)
271
+ """
272
+ And the output should contain:
273
+ """
274
+ Failure/Error: it { should =~ [1, 2, 1] }
275
+ expected collection contained: [1, 1, 2]
276
+ actual collection contained: [1, 2, 3]
277
+ the missing elements were: [1]
278
+ the extra elements were: [3]
279
+ """
280
+
@@ -0,0 +1,128 @@
1
+ Feature: predicate matchers
2
+
3
+ Ruby objects commonly provide predicate methods:
4
+
5
+ * 7.zero? # => false
6
+ * 0.zero? # => true
7
+ * [1].empty? # => false
8
+ * [].empty? # => true
9
+ * { :a => 5 }.has_key?(:b) # => false
10
+ * { :b => 5 }.has_key?(:b) # => true
11
+
12
+ You could use a basic equality matcher to set expectations on these:
13
+
14
+ 7.zero?.should == true # fails with "expected true, got false (using ==)"
15
+
16
+ ...but RSpec provides dynamic predicate matchers that are more readable and
17
+ provide better failure output.
18
+
19
+ For any predicate method, RSpec gives you a corresponding matcher. Simply
20
+ prefix the method with "be_" and remove the question mark. Examples:
21
+
22
+ * 7.should_not be_zero # calls 7.zero?
23
+ * [].should be_empty # calls [].empty?
24
+ * x.should be_multiple_of(3) # calls x.multiple_of?(3)
25
+
26
+ Alternately, for a predicate method that begins with "has_" like Hash#has_key?,
27
+ RSpec allows you to use an alternate form since "be_has_key" makes no sense.
28
+
29
+ * hash.should have_key(:foo) # calls hash.has_key?(:foo)
30
+ * array.should_not have_odd_values # calls array.has_odd_values?
31
+
32
+ In either case, RSpec provides nice, clear error messages, such as:
33
+
34
+ expected zero? to return true, got false
35
+
36
+ Any arguments passed to the matcher will be passed on to the predicate method.
37
+
38
+ Scenario: should be_zero (based on Fixnum#zero?)
39
+ Given a file named "should_be_zero_spec.rb" with:
40
+ """
41
+ describe 0 do
42
+ it { should be_zero }
43
+ end
44
+
45
+ describe 7 do
46
+ it { should be_zero } # deliberate failure
47
+ end
48
+ """
49
+ When I run "rspec should_be_zero_spec.rb"
50
+ Then the output should contain "2 examples, 1 failure"
51
+ And the output should contain "expected zero? to return true, got false"
52
+
53
+ Scenario: should_not be_empty (based on Array#empty?)
54
+ Given a file named "should_not_be_empty_spec.rb" with:
55
+ """
56
+ describe [1, 2, 3] do
57
+ it { should_not be_empty }
58
+ end
59
+
60
+ describe [] do
61
+ it { should_not be_empty } # deliberate failure
62
+ end
63
+ """
64
+ When I run "rspec should_not_be_empty_spec.rb"
65
+ Then the output should contain "2 examples, 1 failure"
66
+ And the output should contain "expected empty? to return false, got true"
67
+
68
+ Scenario: should have_key (based on Hash#has_key?)
69
+ Given a file named "should_have_key_spec.rb" with:
70
+ """
71
+ describe Hash do
72
+ subject { { :foo => 7 } }
73
+ it { should have_key(:foo) }
74
+ it { should have_key(:bar) } # deliberate failure
75
+ end
76
+ """
77
+ When I run "rspec should_have_key_spec.rb"
78
+ Then the output should contain "2 examples, 1 failure"
79
+ And the output should contain "expected #has_key?(:bar) to return true, got false"
80
+
81
+ Scenario: should_not have_all_string_keys (based on custom #has_all_string_keys? method)
82
+ Given a file named "should_not_have_all_string_keys_spec.rb" with:
83
+ """
84
+ class Hash
85
+ def has_all_string_keys?
86
+ keys.all? { |k| String === k }
87
+ end
88
+ end
89
+
90
+ describe Hash do
91
+ context 'with symbol keys' do
92
+ subject { { :foo => 7, :bar => 5 } }
93
+ it { should_not have_all_string_keys }
94
+ end
95
+
96
+ context 'with string keys' do
97
+ subject { { 'foo' => 7, 'bar' => 5 } }
98
+ it { should_not have_all_string_keys } # deliberate failure
99
+ end
100
+ end
101
+ """
102
+ When I run "rspec should_not_have_all_string_keys_spec.rb"
103
+ Then the output should contain "2 examples, 1 failure"
104
+ And the output should contain "expected #has_all_string_keys?(nil) to return false, got true"
105
+
106
+ Scenario: matcher arguments are passed on to the predicate method
107
+ Given a file named "predicate_matcher_argument_spec.rb" with:
108
+ """
109
+ class Fixnum
110
+ def multiple_of?(x)
111
+ (self % x).zero?
112
+ end
113
+ end
114
+
115
+ describe 12 do
116
+ it { should be_multiple_of(3) }
117
+ it { should_not be_multiple_of(7) }
118
+
119
+ # deliberate failures
120
+ it { should_not be_multiple_of(4) }
121
+ it { should be_multiple_of(5) }
122
+ end
123
+ """
124
+ When I run "rspec predicate_matcher_argument_spec.rb"
125
+ Then the output should contain "4 examples, 2 failures"
126
+ And the output should contain "expected multiple_of?(4) to return false, got true"
127
+ And the output should contain "expected multiple_of?(5) to return true, got false"
128
+
@@ -0,0 +1,7 @@
1
+ # Useful for when the output is slightly different on different versions of ruby
2
+ Then /^the output should contain "([^"]*)" or "([^"]*)"$/ do |string1, string2|
3
+ unless [string1, string2].any? { |s| combined_output =~ Regexp.compile(s) }
4
+ fail %Q{Neither "#{string1}" or "#{string2}" were found in:\n#{combined_output}}
5
+ end
6
+ end
7
+
@@ -0,0 +1,29 @@
1
+ Feature: Test::Unit integration
2
+
3
+ RSpec-expectations is a stand-alone gem that can be used without
4
+ the rest of RSpec. It can easily be used with another test
5
+ framework such as Test::Unit if you like RSpec's should/should_not
6
+ syntax but prefer the test organization of another framework.
7
+
8
+ Scenario: Basic Test::Unit usage
9
+ Given a file named "rspec_expectations_test.rb" with:
10
+ """
11
+ require 'test/unit'
12
+ require 'rspec/expectations'
13
+
14
+ class RSpecExpectationsTest < Test::Unit::TestCase
15
+ def test_passing_expectation
16
+ x = 1 + 3
17
+ x.should == 4
18
+ end
19
+
20
+ def test_failing_expectation
21
+ array = [1, 2]
22
+ array.should be_empty
23
+ end
24
+ end
25
+ """
26
+ When I run "ruby rspec_expectations_test.rb"
27
+ Then the output should contain "2 tests"
28
+ And the output should contain "1 failure" or "1 error"
29
+ And the output should contain "expected empty? to return true, got false"
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Expectations # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.0.0.beta.22'
4
+ STRING = '2.0.0.rc'
5
5
  end
6
6
  end
7
7
  end
@@ -158,6 +158,14 @@ module RSpec
158
158
  if RSpec.respond_to?(:configure)
159
159
  RSpec.configure {|c| c.include self}
160
160
  end
161
+
162
+ # Include Matchers for other test frameworks
163
+ if defined?(Test::Unit::TestCase)
164
+ Test::Unit::TestCase.send(:include, self)
165
+ end
166
+ if defined?(MiniTest::Unit::TestCase)
167
+ MiniTest::Unit::TestCase.send(:include, self)
168
+ end
161
169
  end
162
170
  end
163
171
 
@@ -16,8 +16,8 @@ module RSpec
16
16
  @before = evaluate_value_proc
17
17
  event_proc.call
18
18
  @after = evaluate_value_proc
19
-
20
- changed? && matches_before? && matches_after? && matches_amount? && matches_min? && matches_max?
19
+
20
+ (!change_expected? || changed?) && matches_before? && matches_after? && matches_amount? && matches_min? && matches_max?
21
21
  end
22
22
 
23
23
  def raise_block_syntax_error
@@ -92,6 +92,10 @@ MESSAGE
92
92
  @message || "result"
93
93
  end
94
94
 
95
+ def change_expected?
96
+ @amount != 0
97
+ end
98
+
95
99
  def changed?
96
100
  @before != @after
97
101
  end
@@ -19,6 +19,10 @@ module RSpec
19
19
  def failure_message_for_should_not
20
20
  "expected #{@actual} not to satisfy block"
21
21
  end
22
+
23
+ def description
24
+ "satisfy block"
25
+ end
22
26
  end
23
27
 
24
28
  # :call-seq:
@@ -123,6 +123,10 @@ describe "should change(actual, message).by(expected)" do
123
123
  expect { @instance.some_value += 1 }.to change(@instance, :some_value).by(1)
124
124
  end
125
125
 
126
+ it "passes when attribute is not changed and expected amount is 0" do
127
+ expect { @instance.some_value += 0 }.to change(@instance, :some_value).by(0)
128
+ end
129
+
126
130
  it "fails when the attribute is changed by unexpected amount" do
127
131
  expect do
128
132
  expect { @instance.some_value += 2 }.to change(@instance, :some_value).by(1)
@@ -1,2 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module Test
4
+ module Unit
5
+ class TestCase
6
+ end
7
+ end
8
+ end
9
+
10
+ module MiniTest
11
+ module Unit
12
+ class TestCase
13
+ end
14
+ end
15
+ end
16
+
17
+ module RSpec
18
+ describe Matchers do
19
+
20
+ let(:sample_matchers) do
21
+ [:be,
22
+ :be_close,
23
+ :be_instance_of,
24
+ :be_kind_of]
25
+ end
26
+
27
+ context "once required" do
28
+
29
+ before(:all) do
30
+ path = File.expand_path("../../../../#{path}", __FILE__)
31
+ load File.join(path, 'lib/rspec/matchers.rb')
32
+ end
33
+
34
+ it "includes itself in Test::Unit::TestCase" do
35
+ test_unit_case = Test::Unit::TestCase.new
36
+ sample_matchers.each do |sample_matcher|
37
+ test_unit_case.should respond_to(sample_matcher)
38
+ end
39
+ end
40
+
41
+ it "includes itself in MiniTest::Unit::TestCase" do
42
+ minitest_case = MiniTest::Unit::TestCase.new
43
+ sample_matchers.each do |sample_matcher|
44
+ minitest_case.should respond_to(sample_matcher)
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "should satisfy { block }" do
4
+ it "describes itself" do
5
+ satisfy.description.should eq("satisfy block")
6
+ end
7
+
4
8
  it "passes if block returns true" do
5
9
  true.should satisfy { |val| val }
6
10
  true.should satisfy do |val|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7712058
4
5
  prerelease: true
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
9
  - 0
9
- - beta
10
- - 22
11
- version: 2.0.0.beta.22
10
+ - rc
11
+ version: 2.0.0.rc
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Chelimsky
@@ -17,88 +17,91 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-09-12 00:00:00 -05:00
20
+ date: 2010-10-04 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- name: diff-lcs
25
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
27
  - - ">="
29
28
  - !ruby/object:Gem::Version
29
+ hash: 23
30
30
  segments:
31
31
  - 1
32
32
  - 1
33
33
  - 2
34
34
  version: 1.1.2
35
+ requirement: *id001
35
36
  type: :runtime
37
+ name: diff-lcs
36
38
  prerelease: false
37
- version_requirements: *id001
38
39
  - !ruby/object:Gem::Dependency
39
- name: cucumber
40
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
+ hash: 3
45
46
  segments:
46
47
  - 0
47
48
  - 6
48
49
  - 2
49
50
  version: 0.6.2
51
+ requirement: *id002
50
52
  type: :development
53
+ name: cucumber
51
54
  prerelease: false
52
- version_requirements: *id002
53
55
  - !ruby/object:Gem::Dependency
54
- name: aruba
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
57
  none: false
57
58
  requirements:
58
59
  - - ">="
59
60
  - !ruby/object:Gem::Version
61
+ hash: 25
60
62
  segments:
61
63
  - 0
62
64
  - 1
63
65
  - 1
64
66
  version: 0.1.1
67
+ requirement: *id003
65
68
  type: :development
69
+ name: aruba
66
70
  prerelease: false
67
- version_requirements: *id003
68
71
  - !ruby/object:Gem::Dependency
69
- name: rspec-core
70
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
73
  none: false
72
74
  requirements:
73
75
  - - ">="
74
76
  - !ruby/object:Gem::Version
77
+ hash: 7712058
75
78
  segments:
76
79
  - 2
77
80
  - 0
78
81
  - 0
79
- - beta
80
- - 22
81
- version: 2.0.0.beta.22
82
+ - rc
83
+ version: 2.0.0.rc
84
+ requirement: *id004
82
85
  type: :development
86
+ name: rspec-core
83
87
  prerelease: false
84
- version_requirements: *id004
85
88
  - !ruby/object:Gem::Dependency
86
- name: rspec-mocks
87
- requirement: &id005 !ruby/object:Gem::Requirement
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
90
  none: false
89
91
  requirements:
90
92
  - - ">="
91
93
  - !ruby/object:Gem::Version
94
+ hash: 7712058
92
95
  segments:
93
96
  - 2
94
97
  - 0
95
98
  - 0
96
- - beta
97
- - 22
98
- version: 2.0.0.beta.22
99
+ - rc
100
+ version: 2.0.0.rc
101
+ requirement: *id005
99
102
  type: :development
103
+ name: rspec-mocks
100
104
  prerelease: false
101
- version_requirements: *id005
102
105
  description: rspec expectations (should[_not] and matchers)
103
106
  email: dchelimsky@gmail.com;chad.humphries@gmail.com
104
107
  executables: []
@@ -111,7 +114,7 @@ files:
111
114
  - .document
112
115
  - .gitignore
113
116
  - Gemfile
114
- - History.md
117
+ - History.markdown
115
118
  - License.txt
116
119
  - README.markdown
117
120
  - Rakefile
@@ -130,7 +133,12 @@ files:
130
133
  - features/matchers/equality.feature
131
134
  - features/matchers/expect_change.feature
132
135
  - features/matchers/expect_error.feature
136
+ - features/matchers/have.feature
137
+ - features/matchers/operators.feature
138
+ - features/matchers/predicates.feature
139
+ - features/step_definitions/additional_cli_steps.rb
133
140
  - features/support/env.rb
141
+ - features/test_frameworks/test_unit.feature
134
142
  - lib/rspec-expectations.rb
135
143
  - lib/rspec/expectations.rb
136
144
  - lib/rspec/expectations/backward_compatibility.rb
@@ -218,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
226
  requirements:
219
227
  - - ">="
220
228
  - !ruby/object:Gem::Version
221
- hash: -37858944882232104
229
+ hash: 3
222
230
  segments:
223
231
  - 0
224
232
  version: "0"
@@ -227,6 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
235
  requirements:
228
236
  - - ">"
229
237
  - !ruby/object:Gem::Version
238
+ hash: 25
230
239
  segments:
231
240
  - 1
232
241
  - 3
@@ -238,7 +247,7 @@ rubyforge_project: rspec
238
247
  rubygems_version: 1.3.7
239
248
  signing_key:
240
249
  specification_version: 3
241
- summary: rspec-expectations-2.0.0.beta.22
250
+ summary: rspec-expectations-2.0.0.rc
242
251
  test_files:
243
252
  - features/README.markdown
244
253
  - features/expectations/attribute_of_subject.feature
@@ -253,7 +262,12 @@ test_files:
253
262
  - features/matchers/equality.feature
254
263
  - features/matchers/expect_change.feature
255
264
  - features/matchers/expect_error.feature
265
+ - features/matchers/have.feature
266
+ - features/matchers/operators.feature
267
+ - features/matchers/predicates.feature
268
+ - features/step_definitions/additional_cli_steps.rb
256
269
  - features/support/env.rb
270
+ - features/test_frameworks/test_unit.feature
257
271
  - spec/rspec/expectations/differ_spec.rb
258
272
  - spec/rspec/expectations/extensions/kernel_spec.rb
259
273
  - spec/rspec/expectations/fail_with_spec.rb