aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/spec_helper.cr2
-rw-r--r--spec/xdg_basedir_spec.cr50
2 files changed, 52 insertions, 0 deletions
diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr
new file mode 100644
index 0000000..38f3f4a
--- /dev/null
+++ b/spec/spec_helper.cr
@@ -0,0 +1,2 @@
+require "spec"
+require "../src/xdg_basedir"
diff --git a/spec/xdg_basedir_spec.cr b/spec/xdg_basedir_spec.cr
new file mode 100644
index 0000000..1895439
--- /dev/null
+++ b/spec/xdg_basedir_spec.cr
@@ -0,0 +1,50 @@
+require "./spec_helper"
+
+# NOTE: these tests are non-exhaustive and may fail, as they depend on the
+# state of the filesystem and environment
+describe XDGBasedir do
+
+ it "finds previously written files using full_path" do
+ p = XDGBasedir.full_path "xdg_basedir_test_file_1", :data, "w"
+ unless p
+ next
+ end
+ File.write p, "content"
+
+ p = XDGBasedir.full_path "xdg_basedir_test_file_1", :data, "r"
+ unless p
+ next
+ end
+
+ s = File.read p
+ f = File.new p
+ f.delete
+
+ s.should eq("content")
+ end
+
+ it "finds previously written files using dir methods" do
+ d = XDGBasedir.write_dir :config
+ unless d
+ next
+ end
+ File.write "#{d}xdg_basedir_test_file_2" , "content"
+
+ l = XDGBasedir.read_dirs :config
+ unless l
+ next
+ end
+
+ s = File.read "#{l[0]}xdg_basedir_test_file_2"
+ f = File.new "#{d}xdg_basedir_test_file_2"
+ f.delete
+
+ s.should eq("content")
+ end
+
+ it "fails on bad arguments" do
+ expect_raises(ArgumentError) { XDGBasedir.write_dir :bad }
+ expect_raises(ArgumentError) { XDGBasedir.read_dirs :bad }
+ expect_raises(ArgumentError) { XDGBasedir.full_path "rel_path", :bad }
+ end
+end