Skip to content

Instantly share code, notes, and snippets.

@jbpros
Forked from sixtyfive/gist:1226165
Created September 19, 2011 09:28
Show Gist options
  • Save jbpros/1226208 to your computer and use it in GitHub Desktop.
Save jbpros/1226208 to your computer and use it in GitHub Desktop.
# activity.rb
def full_duration
return (duration_in_minutes.to_f / 60).round(1)
end
# activity_spec.rb
describe "full_duration()" do
context "when duration_in_minutes is saved in the database" do
let(:duration_in_rounded_fractional_hours) { mock "duration in rounded fractional hours" }
let(:duration_in_fractional_hours) { mock "duration in fractional hours", :round => duration_in_rounded_fractional_hours }
let(:duration_in_minutes_as_float) { mock "duration in minutes as float", :/ => duration_in_fractional_hours }
let(:duration_in_minutes) { mock "duration in minutes", :to_f => duration_in_minutes_as_float }
before :each do
activity.stub :duration_in_minutes => duration_in_minutes
end
it "gets the duration_in_minutes from the database" do
activity.should_receive :duration_in_minutes
activity.full_duration
end
it "converts the duration minutes from an integer to a float" do
duration_in_minutes.should_receive :to_f
activity.full_duration
end
it "converts the minutes into fractional hours" do
duration_in_minutes_as_float.should_receive :/
activity.full_duration
end
it "rounds the fractional hours with a precision of 1" do
duration_in_fractional_hours.should_receive(:round).with(1)
activity.full_duration
end
it "returns the duration in rounded fractional hours" do
activity.full_duration.should equal duration_in_rounded_fractional_hours
end
end
context "started_on and ended_on refer to days only" do
end
context "started_on and ended_on refer to times" do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment