Created
September 13, 2012 14:28
-
-
Save thiagofm/3714658 to your computer and use it in GitHub Desktop.
PriceCalculator_spec.rb
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 'spec_helper' | |
describe FaleMais::PriceCalculator do | |
context "#object" do | |
it "should be a subclass of Object" do | |
Object.constants.should include(:FaleMais) | |
end | |
it "should be instantiable" do | |
FaleMais::PriceCalculator.new.should be_an_instance_of FaleMais::PriceCalculator | |
end | |
it "should accept options" do | |
FaleMais::PriceCalculator.new(:plan => '30').should be_an_instance_of FaleMais::PriceCalculator | |
end | |
it "should initialize instance variables with options" do | |
options = { :plan => '30', :source => '011', :destination => '016' } | |
calculator = FaleMais::PriceCalculator.new(options) | |
options.keys.map do |key| | |
key.to_s.insert(0, '@').to_sym | |
end.each do |option| | |
calculator.instance_variables.should include option | |
end | |
end | |
it "should be possible to assign variables after it's instantiated" do | |
calculator = FaleMais::PriceCalculator.new | |
calculator.plan = '30' | |
calculator.instance_variables.should include :@plan | |
end | |
end | |
context "#price" do | |
before(:each) do | |
@options = { :plan => '120', :source => '018', :destination => '011', :time => '200' } | |
@calculator = FaleMais::PriceCalculator.new(@options) | |
end | |
it "should return the correct price per minute" do | |
FaleMais::PriceCalculator.minute_pricing('011','016').should == 1.9 | |
end | |
it "should calculate the price" do | |
lambda { @calculator.calculate }.should_not raise_error | |
end | |
it "should yield the right result" do | |
@calculator.calculate | |
@calculator.price.should be_close 167.20, 0.01 | |
end | |
it "should calculate the price without any plan" do | |
@calculator.calculate | |
@calculator.price_without_plan.should be_close 380.0, 0.01 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment