Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic specs for optional variable assignments.
- Loading branch information
Yorick Peterse
committed
Jan 5, 2015
1 parent
29cfd36
commit f384d1c
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |