From a015f307691b292b3ba13a0041c47674b7fdc7fa Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 17 Feb 2019 21:24:31 -0700 Subject: [PATCH] Add tests for Source#spec and update #to_s tests --- spec/source_spec.cr | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/spec/source_spec.cr b/spec/source_spec.cr index 847f259..a4643e1 100644 --- a/spec/source_spec.cr +++ b/spec/source_spec.cr @@ -17,12 +17,41 @@ describe Spectator::Source do end end + describe "#path" do + context "with a relative file" do + it "is shortened" do + file = "test.cr" + absolute = File.join(Dir.current, file) + source = Spectator::Source.new(absolute, __LINE__) + source.path.should eq(file) + end + end + + context "with a different directory" do + it "is the absolute path" do + file = "/foo/bar/baz.cr" + source = Spectator::Source.new(file, __LINE__) + source.path.should eq(file) + end + end + end + describe "#to_s" do - it "is formatted correctly" do + it "contains #path" do file = __FILE__ + source = Spectator::Source.new(file, __LINE__) + source.to_s.should contain(source.path) + end + + it "contains #line" do line = __LINE__ - source = Spectator::Source.new(file, line) - source.to_s.should eq("#{file}:#{line}") + source = Spectator::Source.new(__FILE__, line) + source.to_s.should contain(line.to_s) + end + + it "is formatted correctly" do + source = Spectator::Source.new(__FILE__, __LINE__) + source.to_s.should match(/^(.+?)\:(\d+)$/) end end end