rspec-expectations 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +24 -1
- data/README.md +36 -2
- data/features/built_in_matchers/be.feature +52 -14
- data/features/syntax_configuration.feature +68 -0
- data/lib/rspec/expectations.rb +2 -0
- data/lib/rspec/expectations/expectation_target.rb +52 -0
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/syntax.rb +105 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +12 -5
- data/lib/rspec/matchers/built_in/base_matcher.rb +16 -7
- data/lib/rspec/matchers/built_in/be.rb +27 -25
- data/lib/rspec/matchers/built_in/be_instance_of.rb +3 -5
- data/lib/rspec/matchers/built_in/be_kind_of.rb +3 -5
- data/lib/rspec/matchers/built_in/be_within.rb +17 -11
- data/lib/rspec/matchers/built_in/cover.rb +5 -6
- data/lib/rspec/matchers/built_in/eq.rb +4 -8
- data/lib/rspec/matchers/built_in/eql.rb +3 -5
- data/lib/rspec/matchers/built_in/equal.rb +6 -10
- data/lib/rspec/matchers/built_in/exist.rb +11 -13
- data/lib/rspec/matchers/built_in/include.rb +5 -6
- data/lib/rspec/matchers/built_in/match.rb +3 -4
- data/lib/rspec/matchers/built_in/match_array.rb +7 -14
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +1 -3
- data/lib/rspec/matchers/built_in/yield.rb +2 -5
- data/lib/rspec/matchers/configuration.rb +66 -0
- data/spec/rspec/expectations/expectation_target_spec.rb +65 -0
- data/spec/rspec/expectations/extensions/kernel_spec.rb +22 -0
- data/spec/rspec/matchers/base_matcher_spec.rb +8 -6
- data/spec/rspec/matchers/be_spec.rb +2 -2
- data/spec/rspec/matchers/be_within_spec.rb +9 -1
- data/spec/rspec/matchers/configuration_spec.rb +160 -0
- data/spec/rspec/matchers/eq_spec.rb +16 -4
- data/spec/rspec/matchers/equal_spec.rb +7 -7
- data/spec/rspec/matchers/match_array_spec.rb +12 -0
- data/spec/rspec/matchers/yield_spec.rb +3 -3
- data/spec/support/in_sub_process.rb +31 -0
- metadata +16 -9
- data/lib/rspec/expectations/extensions/kernel.rb +0 -26
- data/lib/rspec/matchers/block_aliases.rb +0 -21
- data/spec/rspec/matchers/compatibility_spec.rb +0 -28
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
module RSpec
|
3
3
|
module Matchers
|
4
4
|
describe "equal" do
|
5
|
-
|
5
|
+
|
6
6
|
def inspect_object(o)
|
7
7
|
"#<#{o.class}:#{o.object_id}> => #{o.inspect}"
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "matches when actual.equal?(expected)" do
|
11
11
|
1.should equal(1)
|
12
12
|
end
|
@@ -14,18 +14,18 @@ module RSpec
|
|
14
14
|
it "does not match when !actual.equal?(expected)" do
|
15
15
|
"1".should_not equal("1")
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "describes itself" do
|
19
19
|
matcher = equal(1)
|
20
20
|
matcher.matches?(1)
|
21
21
|
matcher.description.should == "equal 1"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "provides message on #failure_message" do
|
25
25
|
expected, actual = "1", "1"
|
26
26
|
matcher = equal(expected)
|
27
27
|
matcher.matches?(actual)
|
28
|
-
|
28
|
+
|
29
29
|
matcher.failure_message_for_should.should == <<-MESSAGE
|
30
30
|
|
31
31
|
expected #{inspect_object(expected)}
|
@@ -33,12 +33,12 @@ expected #{inspect_object(expected)}
|
|
33
33
|
|
34
34
|
Compared using equal?, which compares object identity,
|
35
35
|
but expected and actual are not the same object. Use
|
36
|
-
'actual.should
|
36
|
+
'actual.should eq(expected)' if you don't care about
|
37
37
|
object identity in this example.
|
38
38
|
|
39
39
|
MESSAGE
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "provides message on #negative_failure_message" do
|
43
43
|
expected = actual = "1"
|
44
44
|
matcher = equal(expected)
|
@@ -14,6 +14,18 @@ class UnsortableObject
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "using match_array with expect" do
|
18
|
+
it "passes a valid positive expectation" do
|
19
|
+
expect([1, 2]).to match_array [2, 1]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails an invalid positive expectation" do
|
23
|
+
expect {
|
24
|
+
expect([1, 2, 3]).to match_array [2, 1]
|
25
|
+
}.to fail_with(/expected collection contained/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
17
29
|
describe "array.should =~ other_array" do
|
18
30
|
it "passes if target contains all items" do
|
19
31
|
[1,2,3].should =~ [1,2,3]
|
@@ -291,18 +291,18 @@ describe "yield_successive_args matcher" do
|
|
291
291
|
|
292
292
|
describe "expect {...}.to yield_successive_args([:a, 1], [:b, 2])" do
|
293
293
|
it 'passes when the block successively yields the given args' do
|
294
|
-
expect { |b|
|
294
|
+
expect { |b| [ [:a, 1], [:b, 2] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
295
295
|
end
|
296
296
|
|
297
297
|
it 'fails when the block does not yield that many times' do
|
298
298
|
expect {
|
299
|
-
expect { |b|
|
299
|
+
expect { |b| [[:a, 1]].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
300
300
|
}.to fail_with(/but yielded with unexpected arguments/)
|
301
301
|
end
|
302
302
|
|
303
303
|
it 'fails when the block yields the right number of times but with different arguments' do
|
304
304
|
expect {
|
305
|
-
expect { |b|
|
305
|
+
expect { |b| [ [:a, 1], [:b, 3] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
|
306
306
|
}.to fail_with(/but yielded with unexpected arguments/)
|
307
307
|
end
|
308
308
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module InSubProcess
|
2
|
+
# Useful as a way to isolate a global change to a subprocess.
|
3
|
+
def in_sub_process
|
4
|
+
readme, writeme = IO.pipe
|
5
|
+
|
6
|
+
pid = Process.fork do
|
7
|
+
value = nil
|
8
|
+
begin
|
9
|
+
yield
|
10
|
+
rescue => e
|
11
|
+
value = e
|
12
|
+
end
|
13
|
+
|
14
|
+
writeme.write Marshal.dump(value)
|
15
|
+
|
16
|
+
readme.close
|
17
|
+
writeme.close
|
18
|
+
exit! # prevent at_exit hooks from running (e.g. minitest)
|
19
|
+
end
|
20
|
+
|
21
|
+
writeme.close
|
22
|
+
Process.waitpid(pid)
|
23
|
+
|
24
|
+
if exception = Marshal.load(readme.read)
|
25
|
+
raise exception
|
26
|
+
end
|
27
|
+
|
28
|
+
readme.close
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.11.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: diff-lcs
|
@@ -87,16 +87,16 @@ files:
|
|
87
87
|
- lib/rspec/expectations/deprecation.rb
|
88
88
|
- lib/rspec/expectations/differ.rb
|
89
89
|
- lib/rspec/expectations/errors.rb
|
90
|
+
- lib/rspec/expectations/expectation_target.rb
|
90
91
|
- lib/rspec/expectations/extensions.rb
|
91
92
|
- lib/rspec/expectations/extensions/array.rb
|
92
|
-
- lib/rspec/expectations/extensions/kernel.rb
|
93
93
|
- lib/rspec/expectations/extensions/object.rb
|
94
94
|
- lib/rspec/expectations/fail_with.rb
|
95
95
|
- lib/rspec/expectations/handler.rb
|
96
|
+
- lib/rspec/expectations/syntax.rb
|
96
97
|
- lib/rspec/expectations/version.rb
|
97
98
|
- lib/rspec/matchers.rb
|
98
99
|
- lib/rspec/matchers/be_close.rb
|
99
|
-
- lib/rspec/matchers/block_aliases.rb
|
100
100
|
- lib/rspec/matchers/built_in.rb
|
101
101
|
- lib/rspec/matchers/built_in/base_matcher.rb
|
102
102
|
- lib/rspec/matchers/built_in/be.rb
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/rspec/matchers/built_in/throw_symbol.rb
|
122
122
|
- lib/rspec/matchers/built_in/yield.rb
|
123
123
|
- lib/rspec/matchers/compatibility.rb
|
124
|
+
- lib/rspec/matchers/configuration.rb
|
124
125
|
- lib/rspec/matchers/dsl.rb
|
125
126
|
- lib/rspec/matchers/extensions/instance_eval_with_args.rb
|
126
127
|
- lib/rspec/matchers/generated_descriptions.rb
|
@@ -165,8 +166,10 @@ files:
|
|
165
166
|
- features/implicit_docstrings.feature
|
166
167
|
- features/step_definitions/additional_cli_steps.rb
|
167
168
|
- features/support/env.rb
|
169
|
+
- features/syntax_configuration.feature
|
168
170
|
- features/test_frameworks/test_unit.feature
|
169
171
|
- spec/rspec/expectations/differ_spec.rb
|
172
|
+
- spec/rspec/expectations/expectation_target_spec.rb
|
170
173
|
- spec/rspec/expectations/extensions/kernel_spec.rb
|
171
174
|
- spec/rspec/expectations/fail_with_spec.rb
|
172
175
|
- spec/rspec/expectations/handler_spec.rb
|
@@ -177,7 +180,7 @@ files:
|
|
177
180
|
- spec/rspec/matchers/be_spec.rb
|
178
181
|
- spec/rspec/matchers/be_within_spec.rb
|
179
182
|
- spec/rspec/matchers/change_spec.rb
|
180
|
-
- spec/rspec/matchers/
|
183
|
+
- spec/rspec/matchers/configuration_spec.rb
|
181
184
|
- spec/rspec/matchers/cover_spec.rb
|
182
185
|
- spec/rspec/matchers/description_generation_spec.rb
|
183
186
|
- spec/rspec/matchers/dsl_spec.rb
|
@@ -202,6 +205,7 @@ files:
|
|
202
205
|
- spec/rspec/matchers/yield_spec.rb
|
203
206
|
- spec/spec_helper.rb
|
204
207
|
- spec/support/classes.rb
|
208
|
+
- spec/support/in_sub_process.rb
|
205
209
|
- spec/support/matchers.rb
|
206
210
|
- spec/support/ruby_version.rb
|
207
211
|
homepage: http://github.com/rspec/rspec-expectations
|
@@ -220,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
224
|
version: '0'
|
221
225
|
segments:
|
222
226
|
- 0
|
223
|
-
hash:
|
227
|
+
hash: 2819654037547751839
|
224
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
229
|
none: false
|
226
230
|
requirements:
|
@@ -229,13 +233,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
233
|
version: '0'
|
230
234
|
segments:
|
231
235
|
- 0
|
232
|
-
hash:
|
236
|
+
hash: 2819654037547751839
|
233
237
|
requirements: []
|
234
238
|
rubyforge_project: rspec
|
235
239
|
rubygems_version: 1.8.24
|
236
240
|
signing_key:
|
237
241
|
specification_version: 3
|
238
|
-
summary: rspec-expectations-2.
|
242
|
+
summary: rspec-expectations-2.11.0
|
239
243
|
test_files:
|
240
244
|
- features/README.md
|
241
245
|
- features/Upgrade.md
|
@@ -269,8 +273,10 @@ test_files:
|
|
269
273
|
- features/implicit_docstrings.feature
|
270
274
|
- features/step_definitions/additional_cli_steps.rb
|
271
275
|
- features/support/env.rb
|
276
|
+
- features/syntax_configuration.feature
|
272
277
|
- features/test_frameworks/test_unit.feature
|
273
278
|
- spec/rspec/expectations/differ_spec.rb
|
279
|
+
- spec/rspec/expectations/expectation_target_spec.rb
|
274
280
|
- spec/rspec/expectations/extensions/kernel_spec.rb
|
275
281
|
- spec/rspec/expectations/fail_with_spec.rb
|
276
282
|
- spec/rspec/expectations/handler_spec.rb
|
@@ -281,7 +287,7 @@ test_files:
|
|
281
287
|
- spec/rspec/matchers/be_spec.rb
|
282
288
|
- spec/rspec/matchers/be_within_spec.rb
|
283
289
|
- spec/rspec/matchers/change_spec.rb
|
284
|
-
- spec/rspec/matchers/
|
290
|
+
- spec/rspec/matchers/configuration_spec.rb
|
285
291
|
- spec/rspec/matchers/cover_spec.rb
|
286
292
|
- spec/rspec/matchers/description_generation_spec.rb
|
287
293
|
- spec/rspec/matchers/dsl_spec.rb
|
@@ -306,6 +312,7 @@ test_files:
|
|
306
312
|
- spec/rspec/matchers/yield_spec.rb
|
307
313
|
- spec/spec_helper.rb
|
308
314
|
- spec/support/classes.rb
|
315
|
+
- spec/support/in_sub_process.rb
|
309
316
|
- spec/support/matchers.rb
|
310
317
|
- spec/support/ruby_version.rb
|
311
318
|
has_rdoc:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
# Passes if +matcher+ returns true. Available on every +Object+.
|
3
|
-
# @example
|
4
|
-
# actual.should eq(expected)
|
5
|
-
# actual.should be > 4
|
6
|
-
# @param [Matcher]
|
7
|
-
# matcher
|
8
|
-
# @param [String] message optional message to display when the expectation fails
|
9
|
-
# @return [Boolean] true if the expectation succeeds (else raises)
|
10
|
-
# @see RSpec::Matchers
|
11
|
-
def should(matcher=nil, message=nil, &block)
|
12
|
-
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Passes if +matcher+ returns false. Available on every +Object+.
|
16
|
-
# @example
|
17
|
-
# actual.should_not eq(expected)
|
18
|
-
# @param [Matcher]
|
19
|
-
# matcher
|
20
|
-
# @param [String] message optional message to display when the expectation fails
|
21
|
-
# @return [Boolean] false if the negative expectation succeeds (else raises)
|
22
|
-
# @see RSpec::Matchers
|
23
|
-
def should_not(matcher=nil, message=nil, &block)
|
24
|
-
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
|
25
|
-
end
|
26
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rspec/expectations/extensions/kernel'
|
2
|
-
module RSpec
|
3
|
-
module Matchers
|
4
|
-
module BlockAliases
|
5
|
-
alias_method :to, :should
|
6
|
-
alias_method :to_not, :should_not
|
7
|
-
alias_method :not_to, :should_not
|
8
|
-
end
|
9
|
-
|
10
|
-
# Extends the submitted block with aliases to and to_not
|
11
|
-
# for should and should_not.
|
12
|
-
#
|
13
|
-
# @example
|
14
|
-
# expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
|
15
|
-
# expect { this_block }.to raise_error
|
16
|
-
def expect(&block)
|
17
|
-
block.extend BlockAliases
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec::Matchers.define :have_public_instance_method do |method|
|
4
|
-
match do |klass|
|
5
|
-
klass.public_instance_methods.any? {|m| [method, method.to_sym].include?(m)}
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
(RSpec::Matchers.constants.sort).each do |c|
|
10
|
-
if (Class === (klass = RSpec::Matchers.const_get(c)))
|
11
|
-
describe klass do
|
12
|
-
if klass.public_instance_methods.any? {|m| ['failure_message_for_should',:failure_message_for_should].include?(m)}
|
13
|
-
describe "called with should" do
|
14
|
-
subject { klass }
|
15
|
-
it { should have_public_instance_method('failure_message_for_should')}
|
16
|
-
it { should have_public_instance_method('failure_message')}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
if klass.public_instance_methods.any? {|m| ['failure_message_for_should_not',:failure_message_for_should_not].include?(m)}
|
20
|
-
describe "called with should not" do
|
21
|
-
subject { klass }
|
22
|
-
it { should have_public_instance_method('failure_message_for_should_not')}
|
23
|
-
it { should have_public_instance_method('negative_failure_message')}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|