spec/figaro/tasks_spec.rb in figaro-0.6.1 vs spec/figaro/tasks_spec.rb in figaro-0.6.2
- old
+ new
@@ -1,61 +1,71 @@
require "spec_helper"
-describe Figaro::Tasks do
- describe ".heroku" do
- it "configures Heroku" do
- Figaro.stub(:vars => "FOO=bar")
+module Figaro::Tasks
+ describe Heroku do
+ subject(:heroku) { Heroku.new }
- Figaro::Tasks.should_receive(:`).once.with("heroku config:get RAILS_ENV").
- and_return("development\n")
- Figaro::Tasks.should_receive(:`).once.with("heroku config:add FOO=bar")
+ describe "#invoke" do
+ it "configures Heroku" do
+ heroku.stub(:vars => "FOO=bar")
- Figaro::Tasks.heroku
+ heroku.should_receive(:heroku).once.with("config:set FOO=bar")
+
+ heroku.invoke
+ end
end
- it "configures a specific Heroku app" do
- Figaro.stub(:vars => "FOO=bar")
+ describe "#vars" do
+ it "returns Figaro's vars for Heroku's environment" do
+ heroku.stub(:environment => "staging")
+ Figaro.stub(:vars).with("staging").and_return("FOO=bar")
- Figaro::Tasks.should_receive(:`).once.
- with("heroku config:get RAILS_ENV --app my-app").
- and_return("development\n")
- Figaro::Tasks.should_receive(:`).once.
- with("heroku config:add FOO=bar --app my-app")
-
- Figaro::Tasks.heroku("my-app")
+ expect(heroku.vars).to eq("FOO=bar")
+ end
end
- it "respects the Heroku's remote Rails environment" do
- Figaro::Tasks.stub(:`).with("heroku config:get RAILS_ENV").
- and_return("production\n")
+ describe "#environment" do
+ it "returns Heroku's environment" do
+ heroku.stub(:heroku).with("run 'echo $RAILS_ENV'").and_return(<<-OUT)
+Running `echo $RAILS_ENV` attached to terminal... up, run.1234
+staging
+OUT
- Figaro.should_receive(:vars).once.with("production").and_return("FOO=bar")
- Figaro::Tasks.should_receive(:`).once.with("heroku config:add FOO=bar")
-
- Figaro::Tasks.heroku
+ expect(heroku.environment).to eq("staging")
+ end
end
- it "defaults to the local Rails environment if not set remotely" do
- Figaro::Tasks.stub(:`).with("heroku config:get RAILS_ENV").
- and_return("\n")
+ describe "#heroku" do
+ it "runs a command on Heroku" do
+ heroku.should_receive(:`).once.with("heroku info")
- Figaro.should_receive(:vars).once.with(nil).and_return("FOO=bar")
- Figaro::Tasks.should_receive(:`).once.with("heroku config:add FOO=bar")
+ heroku.heroku("info")
+ end
- Figaro::Tasks.heroku
- end
+ it "runs a command on a specific Heroku app" do
+ heroku = Heroku.new("my-app")
- describe "figaro:heroku", :rake => true do
- it "configures Heroku" do
- Figaro::Tasks.should_receive(:heroku).once.with(nil)
+ heroku.should_receive(:`).once.with("heroku info --app my-app")
- task.invoke
+ heroku.heroku("info")
end
+ end
+ end
- it "configures a specific Heroku app" do
- Figaro::Tasks.should_receive(:heroku).once.with("my-app")
+ describe "figaro:heroku", :rake => true do
+ subject(:heroku) { mock(:heroku) }
- task.invoke("my-app")
- end
+ it "configures Heroku" do
+ Figaro::Tasks::Heroku.stub(:new).with(nil).and_return(heroku)
+ heroku.should_receive(:invoke).once
+
+ task.invoke
+ end
+
+ it "configures a specific Heroku app" do
+ Figaro::Tasks::Heroku.stub(:new).with("my-app").and_return(heroku)
+ heroku.should_receive(:invoke).once
+
+ task.invoke("my-app")
end
end
end