Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 410ce6a4a90e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4dff9a55372c
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 13, 2016

  1. add more spec for ||= and &&=

    pitr-ch committed Oct 13, 2016
    1
    Copy the full SHA
    5245e44 View commit details
  2. Copy the full SHA
    4dff9a5 View commit details
Showing with 168 additions and 22 deletions.
  1. +1 −1 lib/ruby/truffle/jruby-truffle-tool/lib/truffle/tool.rb
  2. +167 −21 spec/ruby/language/optional_assignments_spec.rb
2 changes: 1 addition & 1 deletion lib/ruby/truffle/jruby-truffle-tool/lib/truffle/tool.rb
Original file line number Diff line number Diff line change
@@ -630,7 +630,7 @@ def subcommand_run(rest)
end

executable = if @options[:run][:executable]
executables = Dir.glob("#{@options[:global][:truffle_bundle_path]}/jruby+truffle/*/gems/*/{bin,exe}/*").sort
executables = Dir.glob("#{@options[:global][:truffle_bundle_path]}/jruby+truffle/2.3.0/bin/*").sort
executables.find { |path| File.basename(path) == @options[:run][:executable] } or
raise "no executable with name '#{@options[:run][:executable]}' found"
end
188 changes: 167 additions & 21 deletions spec/ruby/language/optional_assignments_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,185 @@
require File.expand_path('../../spec_helper', __FILE__)

describe 'Optional variable assignments' do
describe 'using a single variable' do
it 'assigns a new variable' do
a ||= 10
describe 'using ||=' do
describe 'using a single variable' do
it 'assigns a new variable' do
a ||= 10

a.should == 10
end
a.should == 10
end

it 're-assigns an existing variable set to false' do
a = false
a ||= 10

a.should == 10
end

it 're-assigns an existing variable set to nil' do
a = nil
a ||= 10

a.should == 10
end

it 're-assigns an existing variable set to false' do
a = false
a ||= 10
it 'does not re-assign a variable with a truthy value' do
a = 10
a ||= 20

a.should == 10
a.should == 10
end

it 'does not evaluate the right side when not needed' do
a = 10
a ||= raise('should not be executed')
a.should == 10
end

it 'does not re-assign a variable with a truthy value when using an inline rescue' do
a = 10
a ||= 20 rescue 30

a.should == 10
end
end

it 're-assigns an existing variable set to nil' do
a = nil
a ||= 10
describe 'using a accessor' do
before do
klass = Class.new { attr_accessor :b }
@a = klass.new
end

it 'assigns a new variable' do
@a.b ||= 10

@a.b.should == 10
end

a.should == 10
it 're-assigns an existing variable set to false' do
@a.b = false
@a.b ||= 10

@a.b.should == 10
end

it 're-assigns an existing variable set to nil' do
@a.b = nil
@a.b ||= 10

@a.b.should == 10
end

it 'does not re-assign a variable with a truthy value' do
@a.b = 10
@a.b ||= 20

@a.b.should == 10
end

it 'does not evaluate the right side when not needed' do
@a.b = 10
@a.b ||= raise('should not be executed')
@a.b.should == 10
end

it 'does not re-assign a variable with a truthy value when using an inline rescue' do
@a.b = 10
@a.b ||= 20 rescue 30

@a.b.should == 10
end
end
end

it 'does not re-assign a variable with a truthy value' do
a = 10
a ||= 20
describe 'using &&=' do
describe 'using a single variable' do
it 'leaves new variable unassigned' do
a &&= 10

a.should == 10
a.should == nil
end

it 'leaves false' do
a = false
a &&= 10

a.should == false
end

it 'leaves nil' do
a = nil
a &&= 10

a.should == nil
end

it 'does not evaluate the right side when not needed' do
a = nil
a &&= raise('should not be executed')
a.should == nil
end

it 'does re-assign a variable with a truthy value' do
a = 10
a &&= 20

a.should == 20
end

it 'does re-assign a variable with a truthy value when using an inline rescue' do
a = 10
a &&= 20 rescue 30

a.should == 20
end
end

it 'does not re-assign a variable with a truthy value when using an inline rescue' do
a = 10
a ||= 20 rescue 30
describe 'using a single variable' do
before do
klass = Class.new { attr_accessor :b }
@a = klass.new
end

it 'leaves new variable unassigned' do
@a.b &&= 10

@a.b.should == nil
end

it 'leaves false' do
@a.b = false
@a.b &&= 10

@a.b.should == false
end

it 'leaves nil' do
@a.b = nil
@a.b &&= 10

@a.b.should == nil
end

it 'does not evaluate the right side when not needed' do
@a.b = nil
@a.b &&= raise('should not be executed')
@a.b.should == nil
end

it 'does re-assign a variable with a truthy value' do
@a.b = 10
@a.b &&= 20

@a.b.should == 20
end

it 'does re-assign a variable with a truthy value when using an inline rescue' do
@a.b = 10
@a.b &&= 20 rescue 30

a.should == 10
@a.b.should == 20
end
end
end