Skip to content

Instantly share code, notes, and snippets.

@shingara
Created July 26, 2012 10:00
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 shingara/daab3c0f31340c2f6460 to your computer and use it in GitHub Desktop.
Save shingara/daab3c0f31340c2f6460 to your computer and use it in GitHub Desktop.
require 'rspec'
require 'virtus'
class MyObject
include Virtus
attribute :int, Integer
attribute :float, Float
end
o = MyObject.new(
:int => "334490140000101135",
:float => "334490140000101135"
)
describe "Coercion" do
it 'should have good conversion in int' do
o.int.should == 334490140000101135
end
it 'should have good conversion in float' do
o.float.should == 334490140000101135.0
end
end
# $ rspec virtus_coercion_bug.rb [11:59:47]
# F.
# Failures:
# 1) Coercion should have good conversion in int
# Failure/Error: o.int.should == 334490140000101135
# expected: 334490140000101135
# got: 334490140000101120 (using ==)
# # ./virtus_coercion_bug.rb:17:in `block (2 levels) in <top (required)>'
# Finished in 0.00043 seconds
# 2 examples, 1 failure
# Failed examples:
#
# rspec ./virtus_coercion_bug.rb:16 # Coercion should have good conversion in int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment