Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 17c5b46

Browse files
committed
Remove proc_to_lambda.
There's a very odd ruby bug that makes this unsafe to use, as its usage mutates the behavior of the block: https://bugs.ruby-lang.org/issues/9967 Unfortunately, this un-fixes rspec/rspec-mocks#714, but we've got to do it.
1 parent 910fb8b commit 17c5b46

File tree

5 files changed

+12
-66
lines changed

5 files changed

+12
-66
lines changed

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 3.0.2 Development
2+
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.1...3-0-maintenance)
3+
4+
* Revert `BlockSignature` change from 3.0.1 because of a ruby bug that
5+
caused it to change the block's behavior (https://bugs.ruby-lang.org/issues/9967).
6+
(Myron Marston, rspec-mocks#721)
7+
18
### 3.0.1 / 2014-06-19
29
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.0.0...v3.0.1)
310

lib/rspec/support.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,5 @@ def self.method_handle_for(object, method_name)
5454
end
5555
end
5656
end
57-
58-
if RUBY_PLATFORM == 'java'
59-
if Proc.method_defined?(:lambda?)
60-
def self.proc_to_lambda(block)
61-
return block if block.lambda?
62-
lambda(&block)
63-
end
64-
else
65-
def self.proc_to_lambda(block)
66-
lambda(&block)
67-
end
68-
end
69-
elsif respond_to?(:define_singleton_method)
70-
def self.proc_to_lambda(block)
71-
return block if block.lambda?
72-
73-
obj = Object.new
74-
obj.define_singleton_method(:to_lambda, &block)
75-
obj.method(:to_lambda).to_proc
76-
end
77-
else # 1.8.7
78-
def self.proc_to_lambda(block)
79-
obj = Object.new
80-
(class << obj; self; end).__send__(:define_method, :to_lambda, &block)
81-
obj.method(:to_lambda).to_proc
82-
end
83-
end
8457
end
8558
end

lib/rspec/support/method_signature_verifier.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ def classify_parameters
133133
#
134134
# @api private
135135
class BlockSignature < MethodSignature
136-
def initialize(block)
137-
super(Support.proc_to_lambda(block))
136+
if RubyFeatures.optional_and_splat_args_supported?
137+
def classify_parameters
138+
super
139+
@min_non_kw_args = @max_non_kw_args unless @max_non_kw_args == INFINITY
140+
end
138141
end
139142
end
140143

spec/rspec/support/method_signature_verifier_spec.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33

44
module RSpec
55
module Support
6-
describe BlockSignature do
7-
it 'differentiates optional vs required args', :if => RubyFeatures.optional_and_splat_args_supported? do
8-
bs = BlockSignature.new(Proc.new { |a, b| })
9-
expect(bs.min_non_kw_args).to eq(2)
10-
expect(bs.max_non_kw_args).to eq(2)
11-
12-
bs = eval("BlockSignature.new(Proc.new { |a, b=2| })")
13-
expect(bs.min_non_kw_args).to eq(1)
14-
expect(bs.max_non_kw_args).to eq(2)
15-
end
16-
end
17-
186
describe MethodSignatureVerifier do
197
describe '#verify!' do
208
let(:signature) { MethodSignature.new(test_method) }

spec/rspec/support_spec.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,5 @@ def method_missing(name, *args, &block)
7575
end
7676
end
7777
end
78-
79-
describe ".proc_to_lambda" do
80-
context "on an interpreter that provides Proc#lambda?", :if => Proc.method_defined?(:lambda?) do
81-
it "converts a proc to a lambda" do
82-
p = Proc.new { 47 }
83-
expect(p).not_to be_lambda
84-
l = Support.proc_to_lambda(p)
85-
expect(l).to be_lambda
86-
expect(l.call).to eq(47)
87-
end
88-
89-
it 'returns a lambda unchanged' do
90-
l = lambda { }
91-
expect(Support.proc_to_lambda(l)).to be(l)
92-
end
93-
end
94-
95-
context "on an interpreter that does not provide Proc#lambda?", :unless => Proc.method_defined?(:lambda?) do
96-
it 'converts a proc to a lambda' do
97-
p = Proc.new { return 47 }
98-
l = Support.proc_to_lambda(p)
99-
expect(l.call).to eq(47)
100-
end
101-
end
102-
end
10378
end
10479
end

0 commit comments

Comments
 (0)