Skip to content

Commit

Permalink
Fix bug in Cheers::Color#to_s
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeric committed May 25, 2012
1 parent 6bfa503 commit f4d7ec2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cheers/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def initialize(color = '#000000')

#
def to_s
return '#' + r.to_s(16) + g.to_s(16) + b.to_s(16)
return '#' + r.to_s(16).rjust(2, '0') +
g.to_s(16).rjust(2, '0') +
b.to_s(16).rjust(2, '0')
end

def to_hsv
Expand Down
7 changes: 7 additions & 0 deletions spec/cheers/color_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
end
end

describe '#to_s' do
it 'returns a hexadecimal representation of the color' do
color = Cheers::Color.new('#00007d')
color.to_s.should == '#00007d'
end
end

describe '#similar?' do
it 'returns true if the colors are similar' do
bright_white = Cheers::Color.new '#ffffff'
Expand Down

0 comments on commit f4d7ec2

Please sign in to comment.