twitter-status-bot/.gems/gems/naught-1.0.0/spec/explicit_conversions_spec.rb

24 lines
602 B
Ruby
Raw Normal View History

2014-09-03 08:49:59 +00:00
require 'spec_helper.rb'
describe 'explicitly convertable null object' do
let(:null_class) do
Naught.build do |b|
b.define_explicit_conversions
end
end
subject(:null) { null_class.new }
it 'defines common explicit conversions to return zero values' do
expect(null.to_s).to eq('')
expect(null.to_a).to eq([])
expect(null.to_i).to eq(0)
expect(null.to_f).to eq(0.0)
if RUBY_VERSION >= '2.0'
expect(null.to_h).to eq({})
elsif RUBY_VERSION >= '1.9'
expect(null.to_c).to eq(Complex(0))
expect(null.to_r).to eq(Rational(0))
end
end
end