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

Proc#lambda? isn’t available on 1.8.7 for JRuby. #84

Merged
merged 1 commit into from
Jun 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/rspec/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ def self.method_handle_for(object, method_name)
end

if RUBY_PLATFORM == 'java'
def self.proc_to_lambda(block)
return block if block.lambda?
lambda(&block)
if Proc.method_defined?(:lambda?)
def self.proc_to_lambda(block)
return block if block.lambda?
lambda(&block)
end
else
def self.proc_to_lambda(block)
lambda(&block)
end
end
elsif respond_to?(:define_singleton_method)
def self.proc_to_lambda(block)
Expand Down
30 changes: 20 additions & 10 deletions spec/rspec/support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,28 @@ def method_missing(name, *args, &block)
end
end

describe ".proc_to_lambda", :if => Proc.method_defined?(:lambda?) do
it "converts a proc to a lambda" do
p = Proc.new { 47 }
expect(p).not_to be_lambda
l = Support.proc_to_lambda(p)
expect(l).to be_lambda
expect(l.call).to eq(47)
describe ".proc_to_lambda" do
context "on an interpreter that provides Proc#lambda?", :if => Proc.method_defined?(:lambda?) do
it "converts a proc to a lambda" do
p = Proc.new { 47 }
expect(p).not_to be_lambda
l = Support.proc_to_lambda(p)
expect(l).to be_lambda
expect(l.call).to eq(47)
end

it 'returns a lambda unchanged' do
l = lambda { }
expect(Support.proc_to_lambda(l)).to be(l)
end
end

it 'returns a lambda unchanged' do
l = lambda { }
expect(Support.proc_to_lambda(l)).to be(l)
context "on an interpreter that does not provide Proc#lambda?", :unless => Proc.method_defined?(:lambda?) do
it 'converts a proc to a lambda' do
p = Proc.new { return 47 }
l = Support.proc_to_lambda(p)
expect(l.call).to eq(47)
end
end
end
end
Expand Down