halogenandtoast/alchemist — pull request #17 by janjiss (2013-03-14 09:05:46+00:00)
Title: Added to_i method

Hey guys, ran in to the problem like this in my tests when i tried to compare integer values and conversion values:

NoMethodError: undefined method `to' for 41199:Fixnum
./spec/data/walk_data_spec.rb:21:in `block (3 levels) in '

NoMethodError: undefined method `to' for 25600:Fixnum
./spec/data/walk_data_spec.rb:25:in `block (3 levels) in '

NoMethodError: undefined method `to' for 7:Fixnum
./spec/data/walk_data_spec.rb:29:in `block (3 levels) in '

My test code looks like this:

subject.distance.should == 41199

subject.distance.should == 25600

subject.distance.should == 7

My code in conversion code looks like this

def distance
case distance_units.to_s
when "km"
distance_result = @distance.km.to.meters
when "m"
distance_result = @distance
when "feet"
distance_result = @distance.feet.to.meters
when "miles"
distance_result = @distance.miles.to.meters
else
distance_result = @distance
end
# Distance always needs to return metric units
distance_result.to_i
end

@distance is float

I guess this is happening because Alchemist converts values to different class and it is not the same as a fixnum class, so it complains.

Added to_i method and alchemist tests are passing. My apps tests are passing as well

System used:

Ubuntu 12.10 x64
gem 'rails', '3.2.12'
gem 'rspec', '~> 2.12.0'
gem 'rspec-rails', '~> 2.12.0'

Is this okay?