File: implicit_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 (28 lines) | stat: -rw-r--r-- 755 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
22
23
24
25
26
27
28
require 'spec_helper'

describe 'implicitly convertable null object' do
  subject(:null) { null_class.new }
  let(:null_class) do
    Naught.build(&:define_implicit_conversions)
  end
  it 'implicitly splats the same way an empty array does' do
    a, b = null
    expect(a).to be_nil
    expect(b).to be_nil
  end
  it 'is implicitly convertable to String' do
    expect(instance_eval(null)).to be_nil
  end
  it 'implicitly converts to an empty array' do
    expect(null.to_ary).to eq([])
  end
  it 'implicitly converts to an empty hash' do
    expect(null.to_hash).to eq({})
  end
  it 'implicitly converts to zero' do
    expect(null.to_int).to eq(0)
  end
  it 'implicitly converts to an empty string' do
    expect(null.to_str).to eq('')
  end
end