Skip to content

Commit

Permalink
Fixed specs to ensure #truthy? returns only true or false.
Browse files Browse the repository at this point in the history
The specs don't read as nicely now, but they're more correct. Priorities.
  • Loading branch information
ymendel committed Aug 12, 2008
1 parent 9599948 commit c53516c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions spec/truthy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,71 @@
describe 'truthiness' do

specify 'false should not be truthy' do
false.should_not be_truthy
false.truthy?.should == false
end

specify 'nil should not be truthy' do
nil.should_not be_truthy
nil.truthy?.should == false
end

specify 'true should be truthy' do
true.should be_truthy
true.truthy?.should == true
end

specify 'a string should be truthy' do
'this is a string'.should be_truthy
'this is a string'.truthy?.should == true
end

specify 'even an empty string should be truthy' do
''.should be_truthy
''.truthy?.should == true
end

specify 'a string containing nothing but whitespace should still be truthy' do
' '.should be_truthy
' '.truthy?.should == true
end

specify 'a number should be truthy' do
1.should be_truthy
1.truthy?.should == true
end

specify 'zero is truthy' do
0.should be_truthy
0.truthy?.should == true
end

specify 'infinity is totally truthy' do
(1.0/0.0).should be_truthy
(1.0/0.0).truthy?.should == true
end

specify 'even a negative number is truthy' do
-5.should be_truthy
-5.truthy?.should == true
end

specify 'an array should be truthy' do
['a', 1].should be_truthy
['a', 1].truthy?.should == true
end

specify 'an empty array is truthy' do
[].should be_truthy
[].truthy?.should == true
end

specify 'an array containing only non-truthy elements: still truthy' do
[nil, false].should be_truthy
[nil, false].truthy?.should == true
end

specify 'a hash is truthy' do
{ 'a' => 1 }.should be_truthy
{ 'a' => 1 }.truthy?.should == true
end

specify 'an empty hash is truthy' do
{}.should be_truthy
{}.truthy?.should == true
end

specify 'an hash containing only non-truthy things: still truthy' do
{ nil => false }.should be_truthy
{ nil => false }.truthy?.should == true
end

specify 'an object is truthy' do
Object.new.should be_truthy
Object.new.truthy?.should == true
end

end

0 comments on commit c53516c

Please sign in to comment.