From dcabd0951918c26446720ea50c8bc87f881c766a Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me>
Date: Thu, 17 Aug 2023 12:48:37 -0400
Subject: [PATCH] Added EMPTY_PATH constant and tests

---
 lib/apex/frame/immutable_path.rb |  8 +++++++-
 spec/apex/frame/path_spec.rb     | 13 +++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/lib/apex/frame/immutable_path.rb b/lib/apex/frame/immutable_path.rb
index 9c75a9a..6a7ab77 100644
--- a/lib/apex/frame/immutable_path.rb
+++ b/lib/apex/frame/immutable_path.rb
@@ -4,11 +4,13 @@ require 'apex/frame/path'
 module Apex
   public
   class ImmutablePath
+
     include Path
 
+    protected
     def initialize(*hops)
-      raise ArgumentError.new("Must be called with atleast one argument") if (hops.nil?) || (hops.length <= 0)
       @path_array = []
+      puts @path_array
       last_seen = true
       hops.each do |hop|
         raise ArgumentError.new("All arguments must not be nil: #{hops.to_s}") if (hop.nil?)
@@ -20,6 +22,7 @@ module Apex
 
       @path_array.freeze
       freeze
+      puts @path_array
     end
 
     public
@@ -112,5 +115,8 @@ module Apex
     def seen_hops
         @path_array.select { |hop| hop.seen  }
     end
+
+    public
+    EMPTY_PATH = ImmutablePath.new().freeze
   end
 end
diff --git a/spec/apex/frame/path_spec.rb b/spec/apex/frame/path_spec.rb
index be8a5ad..9ab4efb 100644
--- a/spec/apex/frame/path_spec.rb
+++ b/spec/apex/frame/path_spec.rb
@@ -1,12 +1,17 @@
 require_relative '../../../lib/apex/frame/path'
 
 describe Apex::Path do
+  describe "::EMPTY_PATH" do
+    it "must not be nil" do
+      expect(Apex::ImmutablePath::EMPTY_PATH).to_not be_nil
+    end
+  end
+
   describe ".new" do
     context "Given no arguments" do
-      it "throws an ArgumentError" do
-        expect {
-          path = Apex::ImmutablePath.new()
-        }.to raise_error(ArgumentError)
+      it "creates an empty path" do
+        path = Apex::ImmutablePath.new()
+        expect(path).to eql(Apex::ImmutablePath::EMPTY_PATH)
       end
     end
     context "Given a single nil argument" do
-- 
GitLab