Skip to content

Instantly share code, notes, and snippets.

@jkotchoff
Created May 23, 2012 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkotchoff/2778499 to your computer and use it in GitHub Desktop.
Save jkotchoff/2778499 to your computer and use it in GitHub Desktop.
Ruby on Rails Interview Question (1)
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