Sha256: 8adbc9d9535d9e43372a1ec9e4f39b50462e05aa4daa197b9745c9458acca88a

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

#! /usr/bin/ruby
#encoding: utf-8

require 'minitest/autorun'

describe "y_support/null_object" do
  before do
    require './../lib/y_support/null_object'
  end

  describe Object do
    it "should have #null_object? (alias #null?)" do
      assert ( class Koko < NullObject; self end ).new.null_object?
      assert ( class Koko < NullObject; self end ).new.null?
      assert_equal [ false, false ], [ nil.null_object?, nil.null? ]
      assert NullObject.new( :koko ).null?( :koko )
      assert ! NullObject.new( :koko ).null?( :pipi )
    end

    it "should have #Maybe() constructor for something / NullObject" do
      assert_equal NullObject, Maybe(nil).class
      assert_equal 42, Maybe(42)
    end
    
    it "should have #Null() constructor always returning NullObject" do
      assert_equal NullObject, Null().class
    end
  end # context Object
  
  describe "NullObject" do
    it "should NullObject exist and comply" do
      n = NullObject.new
      [n.to_a, n.to_s, n.to_f, n.to_i].must_equal [ [], "#<NullObject>", 0.0, 0 ]
      assert_equal [false, true], [n.present?, n.empty?]
      NullObject.new.must_have_attr_reader( :recorded_messages )
      assert_respond_to NullObject.new, :arbitrary_message
      n = NullObject.new :x
      n.arbitrary_message( :a, :b ) { "hello" }
      assert_equal :x, n.null_object_signature
      assert_equal "#<NullObject kokotina>", NullObject.new( :kokotina ).inspect
    end
  end # context NullObject
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
y_support-2.4.6 test/null_object_test.rb
y_support-2.4.5 test/null_object_test.rb
y_support-2.4.4 test/null_object_test.rb
y_support-2.1.18 test/null_object_test.rb
y_support-2.1.17 test/null_object_test.rb
y_support-2.1.16 test/null_object_test.rb
y_support-2.1.13 test/null_object_test.rb
y_support-2.1.12 test/null_object_test.rb