Created
May 23, 2012 23:43
-
-
Save jkotchoff/2778499 to your computer and use it in GitHub Desktop.
Ruby on Rails Interview Question (1)
This file contains hidden or 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
require 'rspec' | |
def format_money(amount) | |
'-1' #TODO | |
end | |
describe "format_money" do | |
context "when the amount is a simple fraction" do | |
subject{ 0.4 } | |
specify{ format_money(subject).should == "$0.40" } | |
end | |
context "when the amount is a negative fraction" do | |
subject{ -0.4 } | |
specify{ format_money(subject).should == "-$0.40" } | |
end | |
context "when the amount is a tricky fraction" do | |
subject{ 0.9 / 100 } | |
specify{ format_money(subject).should == "$0.009" } | |
end | |
context "when the amount is a tricky negative fraction" do | |
subject{ 0.9 / 100 * -1 } | |
specify{ format_money(subject).should == "-$0.009" } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment