#! /usr/bin/ruby #encoding: utf-8 require 'minitest/autorun' require_relative '../../lib/y_support/misc/null_object' describe "y_support/null_object" do 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 [ [], "#", 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.new( :kokotina ).inspect end end # context NullObject end