spec/octopolo/scripts/deployable_spec.rb in octopolo-0.1.0 vs spec/octopolo/scripts/deployable_spec.rb in octopolo-0.1.1
- old
+ new
@@ -7,17 +7,49 @@
let(:cli) { stub(:Cli) }
let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => true) }
before { Deployable.any_instance.stub(:cli => cli, :config => config) }
context "#execute" do
- context "with a PR passed in via the command args" do
- subject { Deployable.new 42 }
+ subject { Deployable.new 42}
+ it "calls merge_and_label" do
+ expect(subject).to receive(:merge_and_label)
+ subject.execute
+ end
+ context "#merge_and_label" do
+ before do
+ allow(PullRequestMerger).to receive(:perform)
+ end
+
+ context "deployable_label is set to true" do
+ it "calls ensure_label_was_created" do
+ expect(subject).to receive(:ensure_label_was_created)
+ subject.execute
+ end
+ end
+
+ context "deployable_label is set to false " do
+ let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => false) }
+ it "skips add_to_pull when deployable_label is false" do
+ expect(subject).to_not receive(:ensure_label_was_created)
+ subject.execute
+ end
+ end
+ end
+ end
+
+ context "#ensure_label_was_created" do
+ subject { Deployable.new 42}
+ let(:pull_request) {Octopolo::GitHub::PullRequest.new('foo', subject.pull_request_id, nil)}
+ before do
+ allow_any_instance_of(Octopolo::GitHub::PullRequest).to receive(:add_labels)
+ end
+
+ context "with a PR passed in via the command args" do
it "delegates the work to PullRequestMerger" do
- allow(Octopolo::GitHub::Label).to receive(:add_to_pull)
- PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"])
- subject.execute
+ expect(PullRequestMerger).to receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"]) {true}
+ subject.ensure_label_was_created
end
end
context "with no PR passed in from the command args" do
subject { Deployable.new }
@@ -28,12 +60,11 @@
.with("Pull Request ID: ")
.and_return("42")
end
it "delegates the work to PullRequestMerger" do
- allow(Octopolo::GitHub::Label).to receive(:add_to_pull)
- PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"])
+ expect(PullRequestMerger).to receive(:perform).with(Git::DEPLOYABLE_PREFIX, 42, :user_notifications => ["NickLaMuro"]) {true}
subject.execute
end
end
context "with no PR passed in from the cli" do
@@ -47,29 +78,18 @@
expect{ subject.execute }.to raise_error(ArgumentError)
end
end
end
- context "with various values for deployable_label" do
- let(:deployable_label) {Octopolo::GitHub::Label.new("deployable", "428BCA")}
- subject { Deployable.new 42 }
- before do
- allow(PullRequestMerger).to receive(:perform)
- end
+ context "when it creates a label successfully" do
- it "calls add_to_pull when deployable_label is true" do
- expect(Octopolo::GitHub::Label).to receive(:add_to_pull).with(42,deployable_label)
- subject.execute
+ it "calls remove_label when pull_request_merge fails" do
+ allow(PullRequestMerger).to receive(:perform) {nil}
+ expect_any_instance_of(Octopolo::GitHub::PullRequest).to receive(:remove_labels)
+ subject.ensure_label_was_created
end
-
- context "deployable_label is set to false " do
- let(:config) { stub(:user_notifications => ['NickLaMuro'], :github_repo => 'foo', :deployable_label => false) }
- it "skips add_to_pull when deployable_label is false" do
- expect(Octopolo::GitHub::Label).to_not receive(:add_to_pull).with(42,deployable_label)
- subject.execute
- end
- end
end
end
+
end
end
end