rspec-expectations 2.14.2 → 2.14.3

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Mzg4MjBiNTY0NTMxM2E3ODVlNjJjYjgzYmJjMThhMTk4N2ZmZmIyOA==
5
+ data.tar.gz: !binary |-
6
+ NGRiNWI1ODQ4MTY2YTZlYTJlZGM3ZDQ3YzQwZjExMTQ2YWE5MTc5OA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTEyOTg0ZTBjMDczNGJlZTc1ZGI3YThjODY4MWViMjMzYzI2ZTk1OWQ4NjVi
10
+ NjgyMmZlZjNiODRjOTU2ODdkYTM0YzIzMjQwMjAxZTI4YzY5Y2MzYWJlZmVl
11
+ MDgwZjdjZjQ5Nzc0MDY4MzVlMTQwMTczMGE4Y2NhNzJlZDAzMjE=
12
+ data.tar.gz: !binary |-
13
+ ZGZjNzZkNjQwMDU4NWI5ZDRmYzM0NjM4M2MwMTMzNmJhODgyOWE0NGU4NzQ0
14
+ MWI2Yjc2YzUxYjNmMGZmMGQ4MzQ4ODFiYjU2NDViOGJmNGVmNjFlNGU4M2Iz
15
+ Njc3N2U0ZDUwNGJiMjVhZmRmZDViOTRmNjVhMjU1MDRjYjk3NTY=
@@ -1,3 +1,14 @@
1
+ ### 2.14.3 / 2013-09-22
2
+ [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.2...v2.14.3)
3
+
4
+ Bug fixes
5
+
6
+ * Fix operator matchers (`should` syntax) when `method` is redefined on target.
7
+ (Brandon Turner)
8
+ * Fix diffing of hashes with object based keys. (Jon Rowe)
9
+ * Fix operator matchers (`should` syntax) when operator is defined via
10
+ `method_missing` (Jon Rowe)
11
+
1
12
  ### 2.14.2 / 2013-08-14
2
13
  [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.1...v2.14.2)
3
14
 
@@ -43,5 +43,31 @@ module RSpec
43
43
  # built-in matchers that ship with rspec-expectations, and how to write your
44
44
  # own custom matchers.
45
45
  module Expectations
46
+
47
+ # @api private
48
+ KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method)
49
+
50
+ # @api private
51
+ #
52
+ # Used internally to get a method handle for a particular object
53
+ # and method name.
54
+ #
55
+ # Includes handling for a few special cases:
56
+ #
57
+ # - Objects that redefine #method (e.g. an HTTPRequest struct)
58
+ # - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)
59
+ if RUBY_VERSION.to_i >= 2
60
+ def self.method_handle_for(object, method_name)
61
+ KERNEL_METHOD_METHOD.bind(object).call(method_name)
62
+ end
63
+ else
64
+ def self.method_handle_for(object, method_name)
65
+ if ::Kernel === object
66
+ KERNEL_METHOD_METHOD.bind(object).call(method_name)
67
+ else
68
+ object.method(method_name)
69
+ end
70
+ end
71
+ end
46
72
  end
47
73
  end
@@ -1,13 +1,27 @@
1
1
  module RSpec
2
2
  module Expectations
3
3
  module Deprecation
4
+ RSPEC_LIBS = %w[
5
+ core
6
+ mocks
7
+ expectations
8
+ matchers
9
+ rails
10
+ ]
11
+
12
+ ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
13
+
14
+ LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
15
+
4
16
  # @private
5
17
  #
6
18
  # Used internally to print deprecation warnings
7
19
  def deprecate(deprecated, options={})
20
+ call_site = caller.find { |line| line !~ LIB_REGEX }
21
+
8
22
  message = "DEPRECATION: #{deprecated} is deprecated."
9
23
  message << " Use #{options[:replacement]} instead." if options[:replacement]
10
- message << " Called from #{caller(0)[2]}."
24
+ message << " Called from #{call_site}."
11
25
  warn message
12
26
  end
13
27
  end
@@ -115,7 +115,7 @@ module RSpec
115
115
  #
116
116
  # note, PP is used to ensure the ordering of the internal values of key/value e.g.
117
117
  # <# a: b: c:> not <# c: a: b:>
118
- matching_encoding("#{pp_key} => #{pp_value}", key)
118
+ matching_encoding("#{pp_key} => #{pp_value}", key.to_s)
119
119
  end.join(",\n")
120
120
  when String
121
121
  object =~ /\n/ ? object : object.inspect
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.14.2'
5
+ STRING = '2.14.3'
6
6
  end
7
7
  end
8
8
  end
@@ -22,7 +22,11 @@ module RSpec
22
22
  elsif @expected_message
23
23
  "`expect { }.not_to raise_error(message)`"
24
24
  end
25
- RSpec.deprecate(what_to_deprecate, :replacement => "`expect { }.not_to raise_error()`")
25
+
26
+ RSpec.deprecate(
27
+ what_to_deprecate,
28
+ :replacement => "`expect { }.not_to raise_error` (with no args)"
29
+ )
26
30
  end
27
31
  @raised_expected_error = false
28
32
  @with_expected_message = false
@@ -60,11 +60,13 @@ module RSpec
60
60
  "#{@operator} #{@expected.inspect}"
61
61
  end
62
62
 
63
- private
63
+ private
64
64
 
65
65
  if Method.method_defined?(:owner) # 1.8.6 lacks Method#owner :-(
66
66
  def uses_generic_implementation_of?(op)
67
- @actual.method(op).owner == ::Kernel
67
+ Expectations.method_handle_for(@actual, op).owner == ::Kernel
68
+ rescue NameError
69
+ false
68
70
  end
69
71
  else
70
72
  def uses_generic_implementation_of?(op)
@@ -74,7 +76,9 @@ module RSpec
74
76
  #
75
77
  # In the absence of Method#owner, this is the best we
76
78
  # can do to see if the method comes from Kernel.
77
- @actual.method(op).to_s.include?('(Kernel)')
79
+ Expectations.method_handle_for(@actual, op).to_s.include?('(Kernel)')
80
+ rescue NameError
81
+ false
78
82
  end
79
83
  end
80
84
 
@@ -148,6 +148,17 @@ EOD
148
148
  expect(diff).to eq expected_diff
149
149
  end
150
150
 
151
+ it "outputs unified diff message of two hashes with object keys" do
152
+ expected_diff = %Q{
153
+ @@ -1,2 +1,2 @@
154
+ -["a", "c"] => "b"
155
+ +["d", "c"] => "b"
156
+ }
157
+
158
+ diff = differ.diff_as_object({ ['d','c'] => 'b'}, { ['a','c'] => 'b' })
159
+ expect(diff).to eq expected_diff
160
+ end
161
+
151
162
  it "outputs unified diff of single line strings" do
152
163
  expected = "this is one string"
153
164
  actual = "this is another string"
@@ -0,0 +1,50 @@
1
+ module RSpec
2
+ describe Expectations do
3
+ describe '.method_handle_for(object, method_name)' do
4
+
5
+ class UntamperedClass
6
+ def foo
7
+ :bar
8
+ end
9
+ end
10
+
11
+ class ClassWithMethodOverridden < UntamperedClass
12
+ def method
13
+ :baz
14
+ end
15
+ end
16
+
17
+ if RUBY_VERSION.to_f > 1.8
18
+ class BasicClass < BasicObject
19
+ def foo
20
+ :bar
21
+ end
22
+ end
23
+
24
+ class BasicClassWithKernel < BasicClass
25
+ include ::Kernel
26
+ end
27
+ end
28
+
29
+ it 'fetches method definitions for vanilla objects' do
30
+ object = UntamperedClass.new
31
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
32
+ end
33
+
34
+ it 'fetches method definitions for objects with method redefined' do
35
+ object = ClassWithMethodOverridden.new
36
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
37
+ end
38
+
39
+ it 'fetches method definitions for basic objects', :if => RUBY_VERSION.to_i >= 2 do
40
+ object = BasicClass.new
41
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
42
+ end
43
+
44
+ it 'fetches method definitions for basic objects with kernel mixed in', :if => RUBY_VERSION.to_f > 1.8 do
45
+ object = BasicClassWithKernel.new
46
+ expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
+ class MethodOverrideObject
4
+ def method
5
+ :foo
6
+ end
7
+ end
8
+
9
+ class MethodMissingObject < Struct.new(:original)
10
+ undef ==
11
+
12
+ def method_missing(name, *args, &block)
13
+ original.__send__ name, *args, &block
14
+ end
15
+ end
16
+
3
17
  describe "operator matchers", :uses_should do
4
18
  describe "should ==" do
5
19
  it "delegates message to target" do
@@ -18,6 +32,21 @@ describe "operator matchers", :uses_should do
18
32
  RSpec::Expectations.should_receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
19
33
  subject.should == "orange"
20
34
  end
35
+
36
+ it "works when #method is overriden" do
37
+ myobj = MethodOverrideObject.new
38
+ expect {
39
+ myobj.should == myobj
40
+ }.to_not raise_error
41
+ end
42
+
43
+ it "works when implemented via method_missing" do
44
+ obj = Object.new
45
+
46
+ myobj = MethodMissingObject.new(obj)
47
+ myobj.should == obj
48
+ myobj.should_not == Object.new
49
+ end
21
50
  end
22
51
 
23
52
  describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
@@ -1,5 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module WrapDeprecationCallSite
4
+ def expect_deprecation_with_call_site(file, line)
5
+ actual_call_site = nil
6
+ allow(RSpec.configuration.reporter).to receive(:deprecation) do |options|
7
+ actual_call_site = options[:call_site]
8
+ end
9
+
10
+ yield
11
+
12
+ expect(actual_call_site).to match([file, line].join(':'))
13
+ end
14
+ end
15
+
3
16
  describe "expect { ... }.to raise_error" do
4
17
  it_behaves_like("an RSpec matcher", :valid_value => lambda { raise "boom" },
5
18
  :invalid_value => lambda { }) do
@@ -146,15 +159,28 @@ describe "expect { ... }.to raise_error(message)" do
146
159
  end
147
160
 
148
161
  describe "expect { ... }.not_to raise_error(message)" do
162
+ include WrapDeprecationCallSite
163
+
149
164
  before do
150
165
  allow(RSpec).to receive(:deprecate)
151
166
  end
152
167
 
153
168
  it "is deprecated" do
154
- expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(message\)/, :replacement =>"`expect { }.not_to raise_error()`")
169
+ expect(RSpec).to receive(:deprecate).with(
170
+ /not_to raise_error\(message\)/,
171
+ :replacement =>"`expect { }.not_to raise_error` (with no args)"
172
+ )
155
173
  expect {raise 'blarg'}.not_to raise_error('blah')
156
174
  end
157
175
 
176
+ it 'reports the line number of the deprecated syntax' do
177
+ allow(RSpec).to receive(:deprecate).and_call_original
178
+
179
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
180
+ expect {raise 'blarg'}.not_to raise_error('blah')
181
+ end
182
+ end
183
+
158
184
  it "passes if RuntimeError error is raised with the different message" do
159
185
  expect {raise 'blarg'}.not_to raise_error('blah')
160
186
  end
@@ -201,15 +227,27 @@ describe "expect { ... }.to raise_error(NamedError)" do
201
227
  end
202
228
 
203
229
  describe "expect { ... }.not_to raise_error(NamedError)" do
230
+ include WrapDeprecationCallSite
231
+
204
232
  before do
205
233
  allow(RSpec).to receive(:deprecate)
206
234
  end
207
235
 
208
236
  it "is deprecated" do
209
- expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass\)/, :replacement => "`expect { }.not_to raise_error()`")
237
+ expect(RSpec).to receive(:deprecate).with(
238
+ /not_to raise_error\(SpecificErrorClass\)/,
239
+ :replacement =>"`expect { }.not_to raise_error` (with no args)"
240
+ )
210
241
  expect { }.not_to raise_error(NameError)
211
242
  end
212
243
 
244
+ it 'reports the line number of the deprecated syntax' do
245
+ allow(RSpec).to receive(:deprecate).and_call_original
246
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
247
+ expect { }.not_to raise_error(NameError)
248
+ end
249
+ end
250
+
213
251
  it "passes if nothing is raised" do
214
252
  expect { }.not_to raise_error(NameError)
215
253
  end
@@ -250,15 +288,27 @@ describe "expect { ... }.to raise_error(NamedError, error_message) with String"
250
288
  end
251
289
 
252
290
  describe "expect { ... }.not_to raise_error(NamedError, error_message) with String" do
291
+ include WrapDeprecationCallSite
292
+
253
293
  before do
254
294
  allow(RSpec).to receive(:deprecate)
255
295
  end
256
296
 
257
297
  it "is deprecated" do
258
- expect(RSpec).to receive(:deprecate).with(/not_to raise_error\(SpecificErrorClass, message\)/, :replacement =>"`expect { }.not_to raise_error()`")
298
+ expect(RSpec).to receive(:deprecate).with(
299
+ /not_to raise_error\(SpecificErrorClass, message\)/,
300
+ :replacement =>"`expect { }.not_to raise_error` (with no args)"
301
+ )
259
302
  expect {}.not_to raise_error(RuntimeError, "example message")
260
303
  end
261
304
 
305
+ it 'reports the line number of the deprecated syntax' do
306
+ allow(RSpec).to receive(:deprecate).and_call_original
307
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) do
308
+ expect {}.not_to raise_error(RuntimeError, "example message")
309
+ end
310
+ end
311
+
262
312
  it "passes if nothing is raised" do
263
313
  expect {}.not_to raise_error(RuntimeError, "example message")
264
314
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 2.14.2
4
+ version: 2.14.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steven Baker
@@ -10,10 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-08-15 00:00:00.000000000 Z
12
+ date: 2013-09-23 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ name: diff-lcs
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ! '>='
19
19
  - !ruby/object:Gem::Version
@@ -21,10 +21,9 @@ dependencies:
21
21
  - - <
22
22
  - !ruby/object:Gem::Version
23
23
  version: '2.0'
24
- none: false
24
+ type: :runtime
25
25
  prerelease: false
26
- name: diff-lcs
27
- requirement: !ruby/object:Gem::Requirement
26
+ version_requirements: !ruby/object:Gem::Requirement
28
27
  requirements:
29
28
  - - ! '>='
30
29
  - !ruby/object:Gem::Version
@@ -32,56 +31,48 @@ dependencies:
32
31
  - - <
33
32
  - !ruby/object:Gem::Version
34
33
  version: '2.0'
35
- none: false
36
- type: :runtime
37
34
  - !ruby/object:Gem::Dependency
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- version: 10.0.0
43
- none: false
44
- prerelease: false
45
35
  name: rake
46
36
  requirement: !ruby/object:Gem::Requirement
47
37
  requirements:
48
38
  - - ~>
49
39
  - !ruby/object:Gem::Version
50
40
  version: 10.0.0
51
- none: false
52
41
  type: :development
53
- - !ruby/object:Gem::Dependency
42
+ prerelease: false
54
43
  version_requirements: !ruby/object:Gem::Requirement
55
44
  requirements:
56
45
  - - ~>
57
46
  - !ruby/object:Gem::Version
58
- version: 1.1.9
59
- none: false
60
- prerelease: false
47
+ version: 10.0.0
48
+ - !ruby/object:Gem::Dependency
61
49
  name: cucumber
62
50
  requirement: !ruby/object:Gem::Requirement
63
51
  requirements:
64
52
  - - ~>
65
53
  - !ruby/object:Gem::Version
66
54
  version: 1.1.9
67
- none: false
68
55
  type: :development
69
- - !ruby/object:Gem::Dependency
56
+ prerelease: false
70
57
  version_requirements: !ruby/object:Gem::Requirement
71
58
  requirements:
72
59
  - - ~>
73
60
  - !ruby/object:Gem::Version
74
- version: '0.5'
75
- none: false
76
- prerelease: false
61
+ version: 1.1.9
62
+ - !ruby/object:Gem::Dependency
77
63
  name: aruba
78
64
  requirement: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ~>
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0.5'
83
- none: false
84
69
  type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
85
76
  description: rspec expectations (should[_not] and matchers)
86
77
  email: rspec-users@rubyforge.org
87
78
  executables: []
@@ -182,6 +173,7 @@ files:
182
173
  - spec/rspec/expectations/fail_with_spec.rb
183
174
  - spec/rspec/expectations/handler_spec.rb
184
175
  - spec/rspec/expectations/syntax_spec.rb
176
+ - spec/rspec/expectations_spec.rb
185
177
  - spec/rspec/matchers/base_matcher_spec.rb
186
178
  - spec/rspec/matchers/be_close_spec.rb
187
179
  - spec/rspec/matchers/be_instance_of_spec.rb
@@ -222,6 +214,7 @@ files:
222
214
  homepage: http://github.com/rspec/rspec-expectations
223
215
  licenses:
224
216
  - MIT
217
+ metadata: {}
225
218
  post_install_message:
226
219
  rdoc_options:
227
220
  - --charset=UTF-8
@@ -232,25 +225,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
225
  - - ! '>='
233
226
  - !ruby/object:Gem::Version
234
227
  version: '0'
235
- segments:
236
- - 0
237
- hash: 2244321019137391681
238
- none: false
239
228
  required_rubygems_version: !ruby/object:Gem::Requirement
240
229
  requirements:
241
230
  - - ! '>='
242
231
  - !ruby/object:Gem::Version
243
232
  version: '0'
244
- segments:
245
- - 0
246
- hash: 2244321019137391681
247
- none: false
248
233
  requirements: []
249
234
  rubyforge_project: rspec
250
- rubygems_version: 1.8.24
235
+ rubygems_version: 2.0.7
251
236
  signing_key:
252
- specification_version: 3
253
- summary: rspec-expectations-2.14.2
237
+ specification_version: 4
238
+ summary: rspec-expectations-2.14.3
254
239
  test_files:
255
240
  - features/README.md
256
241
  - features/Upgrade.md
@@ -293,6 +278,7 @@ test_files:
293
278
  - spec/rspec/expectations/fail_with_spec.rb
294
279
  - spec/rspec/expectations/handler_spec.rb
295
280
  - spec/rspec/expectations/syntax_spec.rb
281
+ - spec/rspec/expectations_spec.rb
296
282
  - spec/rspec/matchers/base_matcher_spec.rb
297
283
  - spec/rspec/matchers/be_close_spec.rb
298
284
  - spec/rspec/matchers/be_instance_of_spec.rb