spec/heroku/scalr/app_spec.rb in heroku-scalr-0.2.3 vs spec/heroku/scalr/app_spec.rb in heroku-scalr-0.2.4
- old
+ new
@@ -8,11 +8,11 @@
mock "APIResponse", status: status, headers: {}, body: body
end
its(:name) { should == 'name' }
its(:url) { should == 'http://name.herokuapp.com/robots.txt' }
- its(:api) { should be_instance_of(Heroku::API) }
+ its(:api_key) { should == 'key' }
its(:metric) { should be_instance_of(Heroku::Scalr::Metric::Ping) }
its(:interval) { should be(30) }
its(:min_dynos) { should be(1) }
its(:max_dynos) { should be(3) }
@@ -41,22 +41,27 @@
expect { described_class.new("name", {:api_key => 'key', :interval => 9}) }.to raise_error(ArgumentError)
end
end
describe "scaling" do
+
+ let :mock_api do
+ mock "Heroku::API", get_app: mock_response(200, { "dynos" => 2 }), post_ps_scale: mock_response(200, "")
+ end
+
before do
- subject.api.stub get_app: mock_response(200, { "dynos" => 2 }), post_ps_scale: mock_response(200, "")
+ Heroku::API.stub new: mock_api
subject.metric.stub by: -1
end
it "should skip if scaled too recently" do
subject.instance_variable_set :@last_scaled_at, Time.now
subject.scale!.should be_nil
end
it "should log errors" do
- subject.api.should_receive(:get_app).and_raise(RuntimeError, "API Error")
+ mock_api.should_receive(:get_app).and_raise(RuntimeError, "API Error")
Heroku::Scalr.logger.should_receive(:error)
subject.scale!.should be_nil
end
it "should determine scale through metric" do
@@ -68,40 +73,40 @@
subject.metric.should_receive(:by).and_return(0)
subject.scale!.should be_nil
end
it "should check current number of dynos" do
- subject.api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 2 })
+ mock_api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 2 })
subject.scale!.should == 1
end
context "down" do
it "should return the new number of dynos" do
- subject.api.should_receive(:post_ps_scale).with("name", "web", 1).and_return mock_response(200, "")
+ mock_api.should_receive(:post_ps_scale).with("name", "web", 1).and_return mock_response(200, "")
subject.scale!.should == 1
end
it "should skip if min number of dynos reached" do
- subject.api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 1 })
- subject.api.should_not_receive(:post_ps_scale)
+ mock_api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 1 })
+ mock_api.should_not_receive(:post_ps_scale)
subject.scale!.should be_nil
end
end
context "up" do
before { subject.metric.stub by: 1 }
it "should return the new number of dynos" do
- subject.api.should_receive(:post_ps_scale).with("name", "web", 3).and_return mock_response(200, "")
+ mock_api.should_receive(:post_ps_scale).with("name", "web", 3).and_return mock_response(200, "")
subject.scale!.should == 3
end
it "should skip if max number of dynos reached" do
- subject.api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 3 })
- subject.api.should_not_receive(:post_ps_scale)
+ mock_api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 3 })
+ mock_api.should_not_receive(:post_ps_scale)
subject.scale!.should be_nil
end
end
\ No newline at end of file