spec/octopolo/scripts/deployable_spec.rb in octopolo-1.0.2 vs spec/octopolo/scripts/deployable_spec.rb in octopolo-1.1.0

- old
+ new

@@ -8,11 +8,11 @@ let(:cli) { stub(prompt: 42) } let(:config) { stub(user_notifications: ['NickLaMuro'], github_repo: 'grumpy_cat', deployable_label: true) } - let(:pull_request) { stub(add_labels: true, remove_labels: true) } + let(:pull_request) { stub(add_labels: true, remove_labels: true, number: 7) } before do allow(subject).to receive(:cli) { cli } allow(subject).to receive(:config) { config } allow(Octopolo::GitHub::PullRequest).to receive(:new) { pull_request } allow(PullRequestMerger).to receive(:perform) { true } @@ -31,13 +31,29 @@ end context "without a PR ID passed in with the command" do subject { described_class.new } - it "prompts for a PR ID" do - cli.should_receive(:prompt) - .with("Pull Request ID: ") - .and_return("42") + context "with an existing PR for the current branch" do + before do + GitHub::PullRequest.should_receive(:current) { pull_request } + end + + it "takes the pull requests ID from the current branch" do + PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, pull_request.number, :user_notifications => config.user_notifications) + end + end + + context "without an existing PR for the current branch" do + before do + GitHub::PullRequest.should_receive(:current) { nil } + end + + it "prompts for a PR ID" do + cli.should_receive(:prompt) + .with("Pull Request ID: ") + .and_return("42") + end end end context "with labelling enabled" do it "adds the deployable label" do