rspec-expectations 2.99.1 → 2.99.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 737416d432579324de7ff88e00b431f9d153f74e
4
- data.tar.gz: e739ae372811bbe96988b245be5ce6d3471103f8
3
+ metadata.gz: 8c93bd32c3693d2e1fd08d028ae88b28ea444162
4
+ data.tar.gz: 47b0eed2398465eb95c5eb34bd2f15ca06f4b9d4
5
5
  SHA512:
6
- metadata.gz: e1b6c44aa256cc88f1de6042514048e0c4d4431c1f9a9634ee3d89fe45361598034a0f2006cc895805ec555d7cc2d5bfe4665e30f1e2badf75507cc53ef352c8
7
- data.tar.gz: 86df8a2dc0a99d7ca8c8a94533b5e9ed4a7f7461160b2bd28de79076d649d46870201a1efca5dc00ca095ba06304435dfdccb30f478059668692766832ac021c
6
+ metadata.gz: 408df0caac8b9314b1b27b28cac7dee690d04e5f714d42fc37329bfbc23ca399acbfcbc79616186c19c29f58b3a4a92d79ebe8e740a525aa3ac1bd3ee9b46451
7
+ data.tar.gz: e7dbed568204b09863034c56228095cc1a5fc45cbfebb454b0da7f38fcce79da325156a5ceb5ba5deac95ea59f3f81be13a02c40ef1360148ad3a192be44486b
@@ -1,3 +1,14 @@
1
+ ### 2.99.2 / 2014-07-21
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.1...2-99-maintenance)
3
+
4
+ Bug Fixes:
5
+
6
+ * Fix regression in `Expectations#method_handle_for` where proxy objects
7
+ with method delegated would wrongly not return a method handle.
8
+ (Jon Rowe, #594)
9
+ * Fix issue with detection of generic operator matchers so they work
10
+ correctly when undefined. (Myron Marston, #597)
11
+
1
12
  ### 2.99.1 / 2014-06-19
2
13
  [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v2.99.0...v2.99.1)
3
14
 
@@ -59,6 +59,14 @@ module RSpec
59
59
  if RUBY_VERSION.to_i >= 2
60
60
  def self.method_handle_for(object, method_name)
61
61
  KERNEL_METHOD_METHOD.bind(object).call(method_name)
62
+ rescue NameError => original
63
+ begin
64
+ handle = object.method(method_name)
65
+ raise original unless handle.is_a? Method
66
+ handle
67
+ rescue Exception
68
+ raise original
69
+ end
62
70
  end
63
71
  else
64
72
  def self.method_handle_for(object, method_name)
@@ -67,6 +75,14 @@ module RSpec
67
75
  else
68
76
  object.method(method_name)
69
77
  end
78
+ rescue NameError => original
79
+ begin
80
+ handle = object.method(method_name)
81
+ raise original unless handle.is_a? Method
82
+ handle
83
+ rescue Exception
84
+ raise original
85
+ end
70
86
  end
71
87
  end
72
88
  end
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '2.99.1'
5
+ STRING = '2.99.2'
6
6
  end
7
7
  end
8
8
  end
@@ -32,7 +32,7 @@ module RSpec
32
32
 
33
33
  def self.use_custom_matcher_or_delegate(operator)
34
34
  define_method(operator) do |expected|
35
- if uses_generic_implementation_of?(operator) && matcher = OperatorMatcher.get(@actual.class, operator)
35
+ if !has_non_generic_implementation_of?(operator) && matcher = OperatorMatcher.get(@actual.class, operator)
36
36
  @actual.__send__(::RSpec::Matchers.last_should, matcher.new(expected))
37
37
  else
38
38
  eval_match(@actual, operator, expected)
@@ -64,20 +64,20 @@ module RSpec
64
64
  private
65
65
 
66
66
  if Method.method_defined?(:owner) # 1.8.6 lacks Method#owner :-(
67
- def uses_generic_implementation_of?(op)
68
- Expectations.method_handle_for(@actual, op).owner == ::Kernel
67
+ def has_non_generic_implementation_of?(op)
68
+ Expectations.method_handle_for(@actual, op).owner != ::Kernel
69
69
  rescue NameError
70
70
  false
71
71
  end
72
72
  else
73
- def uses_generic_implementation_of?(op)
73
+ def has_non_generic_implementation_of?(op)
74
74
  # This is a bit of a hack, but:
75
75
  #
76
76
  # {}.method(:=~).to_s # => "#<Method: Hash(Kernel)#=~>"
77
77
  #
78
78
  # In the absence of Method#owner, this is the best we
79
79
  # can do to see if the method comes from Kernel.
80
- Expectations.method_handle_for(@actual, op).to_s.include?('(Kernel)')
80
+ !Expectations.method_handle_for(@actual, op).to_s.include?('(Kernel)')
81
81
  rescue NameError
82
82
  false
83
83
  end
@@ -30,11 +30,18 @@ module RSpec
30
30
  end
31
31
 
32
32
  class ClassWithMethodOverridden < UntamperedClass
33
- def method
33
+ def method(name)
34
34
  :baz
35
35
  end
36
36
  end
37
37
 
38
+ class ProxyClass < Struct.new(:original)
39
+ undef :=~, :method
40
+ def method_missing(name, *args, &block)
41
+ original.__send__(name, *args, &block)
42
+ end
43
+ end
44
+
38
45
  if RUBY_VERSION.to_f > 1.8
39
46
  class BasicClass < BasicObject
40
47
  def foo
@@ -57,6 +64,26 @@ module RSpec
57
64
  expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
58
65
  end
59
66
 
67
+ it 'fetches method definitions for proxy objects' do
68
+ object = ProxyClass.new([])
69
+ expect(Expectations.method_handle_for(object, :=~)).to be_a Method
70
+ end
71
+
72
+ it 'fails with `NameError` when an error is raised when fetching a method from an object that has overriden `method`' do
73
+ object = double
74
+ allow(object).to receive(:method).and_raise(Exception)
75
+ expect {
76
+ Expectations.method_handle_for(object, :some_undefined_method)
77
+ }.to raise_error(NameError)
78
+ end
79
+
80
+ it 'fails with `NameError` when a method is fetched from an object that has overriden `method` and is not a method' do
81
+ object = ProxyClass.new(double(:method => :baz))
82
+ expect {
83
+ Expectations.method_handle_for(object, :=~)
84
+ }.to raise_error(NameError)
85
+ end
86
+
60
87
  it 'fetches method definitions for basic objects', :if => (RUBY_VERSION.to_i >= 2 && RUBY_ENGINE != 'rbx') do
61
88
  object = BasicClass.new
62
89
  expect(Expectations.method_handle_for(object, :foo).call).to eq :bar
@@ -47,6 +47,19 @@ describe "should =~ array", :uses_should do
47
47
  array.should =~ array
48
48
  end
49
49
  end
50
+
51
+ context "when the array undefines `=~`" do
52
+ it 'still works' do
53
+ array_klass = Class.new(Array) { undef =~ }
54
+ array = array_klass.new([1, 2])
55
+
56
+ array.should =~ [1, 2]
57
+
58
+ expect {
59
+ array.should =~ [0, 1, 2]
60
+ }.to fail_with(/expected collection contained/)
61
+ end
62
+ end
50
63
  end
51
64
 
52
65
  describe "should_not =~ [:with, :multiple, :args]", :uses_should do
@@ -210,9 +210,9 @@ describe "operator matchers", :uses_should do
210
210
  let(:custom_klass) { Class.new }
211
211
  let(:custom_subklass) { Class.new(custom_klass) }
212
212
 
213
- after {
213
+ after do
214
214
  RSpec::Matchers::BuiltIn::OperatorMatcher.unregister(custom_klass, "=~")
215
- }
215
+ end
216
216
 
217
217
  it "allows operator matchers to be registered for types" do
218
218
  RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
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.99.1
4
+ version: 2.99.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-20 00:00:00.000000000 Z
12
+ date: 2014-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diff-lcs
@@ -240,7 +240,7 @@ rubyforge_project: rspec
240
240
  rubygems_version: 2.2.2
241
241
  signing_key:
242
242
  specification_version: 4
243
- summary: rspec-expectations-2.99.1
243
+ summary: rspec-expectations-2.99.2
244
244
  test_files:
245
245
  - features/README.md
246
246
  - features/Upgrade.md