diff --git a/lib/apex/frame/immutable_path.rb b/lib/apex/frame/immutable_path.rb index 9c75a9a43485a5f35e2b0dd16a1fa9185d47d188..6a7ab77f1f9b97357c925d5b6940bf108f23c133 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 be8a5add70d6e8eb346d8c34cb5acb92f967609a..9ab4efb0bab966f1c90175084b936ee51d279130 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