File: explicit_conversions_spec.rb

package info (click to toggle)
ruby-naught 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ruby: 1,091; makefile: 6
file content (21 lines) | stat: -rw-r--r-- 582 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'spec_helper.rb'

describe 'explicitly convertable null object' do
  let(:null_class) do
    Naught.build(&:define_explicit_conversions)
  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