File: singleton_null_object_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 (33 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
29
30
31
32
33
require 'spec_helper'

describe 'singleton null object' do
  subject(:null_class) do
    Naught.build(&:singleton)
  end

  it 'does not respond to .new' do
    expect { null_class.new }.to raise_error(NoMethodError)
  end

  it 'has only one instance' do
    null1 = null_class.instance
    null2 = null_class.instance
    expect(null1).to be(null2)
  end

  it 'can be cloned' do
    null = null_class.instance
    expect(null.clone).to be(null)
  end

  it 'can be duplicated' do
    null = null_class.instance
    expect(null.dup).to be(null)
  end
  it 'aliases .instance to .get' do
    expect(null_class.get).to be null_class.instance
  end
  it 'permits arbitrary arguments to be passed to .get' do
    null_class.get(42, :foo => 'bar')
  end
end