From 8ec0c461ae5a8b42dcab67e85d0cbc46df07459d Mon Sep 17 00:00:00 2001 From: James Mac William Date: Fri, 13 Oct 2017 14:37:27 -0400 Subject: [PATCH 1/4] Add spec for multiple assignment conditional - add specs for multiple assignments within conditional - for ruby 2.4 this will no longer throw an error, only a warning --- language/if_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/language/if_spec.rb b/language/if_spec.rb index bd4fdcae81..79098cde40 100644 --- a/language/if_spec.rb +++ b/language/if_spec.rb @@ -1,6 +1,24 @@ require File.expand_path('../../spec_helper', __FILE__) describe "The if expression" do + ruby_version_is '2.4' do + it 'allows multiple assignments in conditional expression with non-nil values' do + c = [] + if (a,b = [1,2]) + c << 123 + end + c.should == [123] + end + + it 'allows multiple assignments in conditional with nil value' do + c = [] + if (a,b = nil) + c << 123 + end + c.should_not == [123] + end + end + it "evaluates body if expression is true" do a = [] if true From 546e826b63b10c76a3834e8081d504ee42f42903 Mon Sep 17 00:00:00 2001 From: James Mac William Date: Fri, 13 Oct 2017 16:32:08 -0400 Subject: [PATCH 2/4] catch error to get other ruby versions passing --- language/if_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/language/if_spec.rb b/language/if_spec.rb index 79098cde40..c652be234c 100644 --- a/language/if_spec.rb +++ b/language/if_spec.rb @@ -4,16 +4,22 @@ ruby_version_is '2.4' do it 'allows multiple assignments in conditional expression with non-nil values' do c = [] - if (a,b = [1,2]) - c << 123 + begin + if (a,b = [1,2]) + c << 123 + end + rescue SyntaxError end c.should == [123] end it 'allows multiple assignments in conditional with nil value' do c = [] - if (a,b = nil) - c << 123 + begin + if (a,b = nil) + c << 123 + end + rescue SyntaxError end c.should_not == [123] end From 5dd44fd2fd2a191555b5e2db8e92d68771f8f9ca Mon Sep 17 00:00:00 2001 From: James Mac William Date: Mon, 16 Oct 2017 08:59:10 -0400 Subject: [PATCH 3/4] use scratchpad for mult. assign test --- language/if_spec.rb | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/language/if_spec.rb b/language/if_spec.rb index c652be234c..b26631f174 100644 --- a/language/if_spec.rb +++ b/language/if_spec.rb @@ -2,26 +2,21 @@ describe "The if expression" do ruby_version_is '2.4' do - it 'allows multiple assignments in conditional expression with non-nil values' do - c = [] - begin - if (a,b = [1,2]) - c << 123 - end - rescue SyntaxError + describe "multiple assignments in conditional expression" do + before(:each) { ScratchPad.record([]) } + after(:each) { ScratchPad.clear } + + it 'with non-nil values' do + collector = proc { |i| ScratchPad << i } + eval "if (a, b = [1, 2]); collector[123]; end" + ScratchPad.recorded.should == [123] end - c.should == [123] - end - it 'allows multiple assignments in conditional with nil value' do - c = [] - begin - if (a,b = nil) - c << 123 - end - rescue SyntaxError + it 'with nil values' do + collector = proc { |i| ScratchPad << i } + eval "if (a, b = nil); collector[123]; end" + ScratchPad.recorded.should == [] end - c.should_not == [123] end end From 741fc150ea2149118ceb201f2ca1c15d75efc9fc Mon Sep 17 00:00:00 2001 From: James Mac William Date: Mon, 16 Oct 2017 09:21:06 -0400 Subject: [PATCH 4/4] remove extra proc, clean up desc --- language/if_spec.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/language/if_spec.rb b/language/if_spec.rb index b26631f174..6a6d2dc739 100644 --- a/language/if_spec.rb +++ b/language/if_spec.rb @@ -2,19 +2,17 @@ describe "The if expression" do ruby_version_is '2.4' do - describe "multiple assignments in conditional expression" do + describe "accepts multiple assignments in conditional expression" do before(:each) { ScratchPad.record([]) } after(:each) { ScratchPad.clear } it 'with non-nil values' do - collector = proc { |i| ScratchPad << i } - eval "if (a, b = [1, 2]); collector[123]; end" + eval "if (a, b = [1, 2]); ScratchPad << 123; end" ScratchPad.recorded.should == [123] end it 'with nil values' do - collector = proc { |i| ScratchPad << i } - eval "if (a, b = nil); collector[123]; end" + eval "if (a, b = nil); ScratchPad << 123; end" ScratchPad.recorded.should == [] end end