spec/octopolo/github/pull_request_spec.rb in octopolo-0.1.0 vs spec/octopolo/github/pull_request_spec.rb in octopolo-0.1.1

- old
+ new

@@ -1,7 +1,7 @@ require "spec_helper" -require_relative "../../../lib/octopolo/github/pull_request" +require_relative "../../../lib/octopolo/github" module Octopolo module GitHub describe PullRequest do let(:repo_name) { "account/repo" } @@ -282,9 +282,50 @@ it "passes on to PullRequestCreator and returns a new PullRequest" do PullRequestCreator.should_receive(:perform).with(repo_name, options) { creator } PullRequest.should_receive(:new).with(repo_name, number, pull_request_data) { pull_request } PullRequest.create(repo_name, options).should == pull_request + end + end + + context "labeling" do + let(:label1) { Label.new(name: "low-risk", color: "343434") } + let(:label2) { Label.new(name: "high-risk", color: '565656') } + let(:pull_request) { PullRequest.new repo_name, pr_number } + + context "#add_labels" do + it "sends the correct arguments to add_labels_to_pull for multiple labels" do + allow(Label).to receive(:build_label_array) {[label1,label2]} + expect(GitHub).to receive(:add_labels_to_pull).with(repo_name, pr_number, ["low-risk","high-risk"]) + pull_request.add_labels([label1, label2]) + end + + it "sends the correct arguments to add_labels_to_pull for a single label" do + allow(Label).to receive(:build_label_array) {[label1]} + expect(GitHub).to receive(:add_labels_to_pull).with(repo_name, pr_number, ["low-risk"]) + pull_request.add_labels(label1) + end + end + + context "#remove_from_pull" do + + it "sends the correct arguments to remove_label" do + allow(Label).to receive(:build_label_array) {[label1]} + expect(GitHub).to receive(:remove_label).with(repo_name, pr_number, "low-risk") + pull_request.remove_labels(label1) + end + + it "calls remove_label only once" do + allow(Label).to receive(:build_label_array) {[label1]} + expect(GitHub).to receive(:remove_label).once + pull_request.remove_labels(label1) + end + + it "calls remove_label twice" do + allow(Label).to receive(:build_label_array) {[label1, label2]} + expect(GitHub).to receive(:remove_label).twice + pull_request.remove_labels([label1,label2]) + end end end end end end