Skip to content

Commit

Permalink
Basic specs for optional variable assignments.
Browse files Browse the repository at this point in the history
Currently the rescue spec still fails, see #3272 for more information.

Closes #3273.
  • Loading branch information
Yorick Peterse committed Jan 5, 2015
1 parent 29cfd36 commit f384d1c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions spec/ruby/language/optional_assignments_spec.rb
@@ -0,0 +1,39 @@
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

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 'does not re-assign a variable with a truthy value' do
a = 10
a ||= 20

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
end
1 change: 1 addition & 0 deletions spec/tags/ruby/language/optional_assignments_tags.txt
@@ -0,0 +1 @@
fails:Optional variable assignments using a single variable does not re-assign a variable with a truthy value when using an inline rescue

0 comments on commit f384d1c

Please sign in to comment.