spec/cfoundry/v2/app_spec.rb in cfoundry-4.5.3 vs spec/cfoundry/v2/app_spec.rb in cfoundry-4.6.0
- old
+ new
@@ -3,11 +3,11 @@
module CFoundry
module V2
describe App do
let(:client) { build(:client) }
- subject { build(:app, :client => client) }
+ subject { build(:app, :client => client, :name => 'foo-app') }
describe "#events" do
let(:events) { [build(:app_event)] }
it "has events" do
@@ -255,13 +255,45 @@
end
describe "#health" do
describe "when staging failed for an app" do
it "returns 'STAGING FAILED' as state" do
- client.base.stub(:instances).with(subject.guid) { raise CFoundry::StagingError }
+ AppInstance.stub(:for_app) { raise CFoundry::StagingError }
subject.stub(:state) { "STARTED" }
expect(subject.health).to eq("STAGING FAILED")
+ end
+ end
+ end
+
+ describe "#percent_running" do
+ before do
+ subject.stub(:state) { "STARTED" }
+ subject.total_instances = instances.count
+ AppInstance.stub(:for_app).with(client, subject.guid, subject.name) { instances }
+ end
+
+ let(:instances) do
+ (1..3).map { double(AppInstance, state: "RUNNING") }
+ end
+
+ it "returns the percent of instances running as an integer" do
+ expect(subject.percent_running).to eq(100)
+ end
+
+ context "when half the instances are running" do
+ let(:instances) { [double(AppInstance, state: "RUNNING"), double(AppInstance, state: "STOPPED")] }
+
+ it "returns 50" do
+ expect(subject.percent_running).to eq(50)
+ end
+ end
+
+ context "when staging has failed" do
+ before { AppInstance.stub(:for_app) { raise CFoundry::StagingError } }
+
+ it "returns 0" do
+ expect(subject.percent_running).to eq(0)
end
end
end
describe "#host" do