Skip to content

Commit

Permalink
fix and cleanup env tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jul 1, 2015
1 parent 348a847 commit 5c50018
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions plugins/env/test/hooks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
let(:project) { stage.project }

describe :after_deploy_setup do
def fire
Samson::Hooks.fire(:after_deploy_setup, Dir.pwd, stage)
end

around { |test| Dir.mktmpdir { |dir| Dir.chdir(dir) { test.call } } }

before do
Expand All @@ -19,25 +23,25 @@

it "does not modify when no variables were specified" do
EnvironmentVariable.delete_all
project.environment_variables(:reload)
fire
File.exist?(".env").must_equal false
end

it "writes to .env" do
Samson::Hooks.fire(:after_deploy_setup, Dir.pwd, stage)
fire
File.read(".env").must_equal "HELLO=\"world\"\nWORLD=\"hello\"\n"
end

it "overwrites .env by ignoring not required" do
File.write(".env", "# a comment ...\nHELLO=foo")
Samson::Hooks.fire(:after_deploy_setup, Dir.pwd, stage)
fire
File.read(".env").must_equal "HELLO=\"world\"\n"
end

it "fails when .env has an unsatisfied required key" do
File.write(".env", "FOO=foo")
assert_raises Samson::Hooks::UserError do
Samson::Hooks.fire(:after_deploy_setup, Dir.pwd, stage)
end
assert_raises(Samson::Hooks::UserError) { fire }
end
end

Expand Down Expand Up @@ -66,10 +70,6 @@
))
end

def fire
Samson::Hooks.fire(:after_deploy_setup, Dir.pwd, stage)
end

it "works without ENV.json" do
File.unlink("ENV.json")
project.environment_variables.create!(name: "OTHER", value: "Y")
Expand Down

0 comments on commit 5c50018

Please sign in to comment.