Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Ruby on Rails Interview Question (1)

View interview_q1_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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
Something went wrong with that request. Please try again.