diff --git a/spec/envcat/cli/input_spec.cr b/spec/envcat/cli/input_spec.cr index 0f9f432..0650a5f 100644 --- a/spec/envcat/cli/input_spec.cr +++ b/spec/envcat/cli/input_spec.cr @@ -3,21 +3,59 @@ require "../../../src/envcat/cli" require "digest/sha256" describe Envcat::Cli do - describe "-i json:fixtures/input/test.json -s AGE=42" do - it "overwrites value from json" do + {% for fmt in %w[json yaml toml] %} + describe "-i {{fmt.id}}:fixtures/input/test.{{fmt.id}}" do + it "parses and normalizes {{fmt.id}}" do expect_output(nil, nil) { |o, e, i| - Envcat::Cli.invoke(%w[-f kv -i json:fixtures/input/test.json -s AGE=42 AGE], o, e, i) - o.to_s.should eq("AGE=42\n") + Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.{{fmt.id}} *], o, e, i) + puts o.to_s + Digest::SHA256.hexdigest(o.to_s.split("\n").sort.join("\n")).should eq("66dc73717712ef4ed7ac7fa0cd1ccad48c67b718c038fb9c2f852c10e52e77d6") } end end - describe "-s AGE=42 -i json:fixtures/input/test.json" do - it "overwrites value from json" do - expect_output(nil, nil) { |o, e, i| - Envcat::Cli.invoke(%w[-f kv -s AGE=42 -i json:fixtures/input/test.json AGE], o, e, i) - o.to_s.should eq("AGE=42\n") + describe "-i {{fmt.id}}:fixtures/input/test.invalid" do + it "prints error and exits with code 11 if parsing fails" do + expect_output(nil, /Malformed input.*is not valid {{fmt.id.upcase}}/) { |o, e, i| + expect_raises(Exit, "11") { + Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.invalid *], o, e, i) + } + } + end + end + + describe "-i {{fmt.id}}:fixtures/input/test.notfound" do + it "prints error and exits with code 7 if input file doesn't exist" do + expect_output(nil, /No such file or directory/) { |o, e, i| + expect_raises(Exit, "7") { + Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.notfound *], o, e, i) + } + } + end + end + {% end %} + + {% for fmt in %w[env- derp] %} + describe "-i {{fmt.id}}" do + it "prints error and exits with code 3 if argument to -i is invalid" do + expect_output(nil, /Unknown input type/) { |o, e, i| + expect_raises(Exit, "3") { + Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i) + } + } + end + end + {% end %} + + {% for fmt in %w[yaml yaml: json json: toml toml:] %} + describe "-i {{fmt.id}}" do + it "prints error and exits with code 3 if argument to -i misses path" do + expect_output(nil, /Path is required/) { |o, e, i| + expect_raises(Exit, "3") { + Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i) + } } end end + {% end %} end diff --git a/spec/envcat/cli/set_spec.cr b/spec/envcat/cli/set_spec.cr index 49a6017..0f9f432 100644 --- a/spec/envcat/cli/set_spec.cr +++ b/spec/envcat/cli/set_spec.cr @@ -3,58 +3,21 @@ require "../../../src/envcat/cli" require "digest/sha256" describe Envcat::Cli do - {% for fmt in %w[json yaml toml] %} - describe "-i {{fmt.id}}:fixtures/input/test.{{fmt.id}}" do - it "parses and normalizes {{fmt.id}}" do + describe "-i json:fixtures/input/test.json -s AGE=42" do + it "overwrites value from json" do expect_output(nil, nil) { |o, e, i| - Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.{{fmt.id}} *], o, e, i) - Digest::SHA256.hexdigest(o.to_s.split("\n").sort.join("\n")).should eq("66dc73717712ef4ed7ac7fa0cd1ccad48c67b718c038fb9c2f852c10e52e77d6") + Envcat::Cli.invoke(%w[-f kv -i json:fixtures/input/test.json -s AGE=42 AGE], o, e, i) + o.to_s.should eq("AGE=42\n") } end end - describe "-i {{fmt.id}}:fixtures/input/test.invalid" do - it "prints error and exits with code 11 if parsing fails" do - expect_output(nil, /Malformed input.*is not valid {{fmt.id.upcase}}/) { |o, e, i| - expect_raises(Exit, "11") { - Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.invalid *], o, e, i) - } - } - end - end - - describe "-i {{fmt.id}}:fixtures/input/test.notfound" do - it "prints error and exits with code 7 if input file doesn't exist" do - expect_output(nil, /No such file or directory/) { |o, e, i| - expect_raises(Exit, "7") { - Envcat::Cli.invoke(%w[-f yaml -i {{fmt.id}}:fixtures/input/test.notfound *], o, e, i) - } - } - end - end - {% end %} - - {% for fmt in %w[env- derp] %} - describe "-i {{fmt.id}}" do - it "prints error and exits with code 3 if argument to -i is invalid" do - expect_output(nil, /Unknown input type/) { |o, e, i| - expect_raises(Exit, "3") { - Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i) - } - } - end - end - {% end %} - - {% for fmt in %w[yaml yaml: json json: toml toml:] %} - describe "-i {{fmt.id}}" do - it "prints error and exits with code 3 if argument to -i misses path" do - expect_output(nil, /Path is required/) { |o, e, i| - expect_raises(Exit, "3") { - Envcat::Cli.invoke(%w[-i {{fmt.id}} *], o, e, i) - } + describe "-s AGE=42 -i json:fixtures/input/test.json" do + it "overwrites value from json" do + expect_output(nil, nil) { |o, e, i| + Envcat::Cli.invoke(%w[-f kv -s AGE=42 -i json:fixtures/input/test.json AGE], o, e, i) + o.to_s.should eq("AGE=42\n") } end end - {% end %} end