octopolo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +21 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +3 -0
  7. data/Guardfile +5 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.markdown +55 -0
  10. data/Rakefile +38 -0
  11. data/bash_completion.sh +13 -0
  12. data/bin/octopolo +21 -0
  13. data/bin/op +21 -0
  14. data/lib/octopolo.rb +15 -0
  15. data/lib/octopolo/changelog.rb +27 -0
  16. data/lib/octopolo/cli.rb +210 -0
  17. data/lib/octopolo/commands/accept_pull.rb +8 -0
  18. data/lib/octopolo/commands/compare_release.rb +9 -0
  19. data/lib/octopolo/commands/deployable.rb +8 -0
  20. data/lib/octopolo/commands/github_auth.rb +5 -0
  21. data/lib/octopolo/commands/new_branch.rb +9 -0
  22. data/lib/octopolo/commands/new_deployable.rb +8 -0
  23. data/lib/octopolo/commands/new_staging.rb +8 -0
  24. data/lib/octopolo/commands/octopolo_setup.rb +5 -0
  25. data/lib/octopolo/commands/pivotal_auth.rb +5 -0
  26. data/lib/octopolo/commands/pull_request.rb +13 -0
  27. data/lib/octopolo/commands/signoff.rb +10 -0
  28. data/lib/octopolo/commands/stage_up.rb +8 -0
  29. data/lib/octopolo/commands/stale_branches.rb +11 -0
  30. data/lib/octopolo/commands/sync_branch.rb +11 -0
  31. data/lib/octopolo/commands/tag_release.rb +13 -0
  32. data/lib/octopolo/config.rb +146 -0
  33. data/lib/octopolo/convenience_wrappers.rb +46 -0
  34. data/lib/octopolo/dated_branch_creator.rb +81 -0
  35. data/lib/octopolo/git.rb +262 -0
  36. data/lib/octopolo/github.rb +95 -0
  37. data/lib/octopolo/github/commit.rb +45 -0
  38. data/lib/octopolo/github/pull_request.rb +126 -0
  39. data/lib/octopolo/github/pull_request_creator.rb +127 -0
  40. data/lib/octopolo/github/user.rb +40 -0
  41. data/lib/octopolo/jira/story_commenter.rb +26 -0
  42. data/lib/octopolo/pivotal.rb +44 -0
  43. data/lib/octopolo/pivotal/story_commenter.rb +19 -0
  44. data/lib/octopolo/pull_request_merger.rb +99 -0
  45. data/lib/octopolo/renderer.rb +37 -0
  46. data/lib/octopolo/reports.rb +18 -0
  47. data/lib/octopolo/scripts.rb +23 -0
  48. data/lib/octopolo/scripts/accept_pull.rb +67 -0
  49. data/lib/octopolo/scripts/compare_release.rb +52 -0
  50. data/lib/octopolo/scripts/deployable.rb +27 -0
  51. data/lib/octopolo/scripts/github_auth.rb +87 -0
  52. data/lib/octopolo/scripts/new_branch.rb +34 -0
  53. data/lib/octopolo/scripts/new_deployable.rb +14 -0
  54. data/lib/octopolo/scripts/new_staging.rb +15 -0
  55. data/lib/octopolo/scripts/octopolo_setup.rb +55 -0
  56. data/lib/octopolo/scripts/pivotal_auth.rb +44 -0
  57. data/lib/octopolo/scripts/pull_request.rb +127 -0
  58. data/lib/octopolo/scripts/signoff.rb +85 -0
  59. data/lib/octopolo/scripts/stage_up.rb +26 -0
  60. data/lib/octopolo/scripts/stale_branches.rb +54 -0
  61. data/lib/octopolo/scripts/sync_branch.rb +37 -0
  62. data/lib/octopolo/scripts/tag_release.rb +70 -0
  63. data/lib/octopolo/templates/pull_request_body.erb +24 -0
  64. data/lib/octopolo/user_config.rb +112 -0
  65. data/lib/octopolo/version.rb +3 -0
  66. data/lib/octopolo/week.rb +130 -0
  67. data/octopolo.gemspec +31 -0
  68. data/spec/.DS_Store +0 -0
  69. data/spec/octopolo/cli_spec.rb +310 -0
  70. data/spec/octopolo/config_spec.rb +344 -0
  71. data/spec/octopolo/convenience_wrappers_spec.rb +80 -0
  72. data/spec/octopolo/dated_branch_creator_spec.rb +143 -0
  73. data/spec/octopolo/git_spec.rb +419 -0
  74. data/spec/octopolo/github/commit_spec.rb +59 -0
  75. data/spec/octopolo/github/pull_request_creator_spec.rb +174 -0
  76. data/spec/octopolo/github/pull_request_spec.rb +291 -0
  77. data/spec/octopolo/github/user_spec.rb +65 -0
  78. data/spec/octopolo/github_spec.rb +169 -0
  79. data/spec/octopolo/jira/stor_commenter_spec.rb +30 -0
  80. data/spec/octopolo/pivotal/story_commenter_spec.rb +34 -0
  81. data/spec/octopolo/pivotal_spec.rb +61 -0
  82. data/spec/octopolo/pull_request_merger_spec.rb +144 -0
  83. data/spec/octopolo/renderer_spec.rb +35 -0
  84. data/spec/octopolo/scripts/accept_pull_spec.rb +76 -0
  85. data/spec/octopolo/scripts/compare_release_spec.rb +115 -0
  86. data/spec/octopolo/scripts/deployable_spec.rb +52 -0
  87. data/spec/octopolo/scripts/github_auth_spec.rb +156 -0
  88. data/spec/octopolo/scripts/new_branch_spec.rb +41 -0
  89. data/spec/octopolo/scripts/new_deployable_spec.rb +18 -0
  90. data/spec/octopolo/scripts/new_staging_spec.rb +18 -0
  91. data/spec/octopolo/scripts/octopolo_setup_spec.rb +120 -0
  92. data/spec/octopolo/scripts/pivotal_auth_spec.rb +77 -0
  93. data/spec/octopolo/scripts/pull_request_spec.rb +217 -0
  94. data/spec/octopolo/scripts/signoff_spec.rb +139 -0
  95. data/spec/octopolo/scripts/stage_up_spec.rb +52 -0
  96. data/spec/octopolo/scripts/stale_branches_spec.rb +81 -0
  97. data/spec/octopolo/scripts/sync_branch_spec.rb +57 -0
  98. data/spec/octopolo/scripts/tag_release_spec.rb +108 -0
  99. data/spec/octopolo/user_config_spec.rb +167 -0
  100. data/spec/octopolo_spec.rb +7 -0
  101. data/spec/spec_helper.rb +29 -0
  102. data/spec/support/engine_yard.cache +0 -0
  103. data/spec/support/sample_octopolo.yml +2 -0
  104. data/spec/support/sample_user.yml +2 -0
  105. data/templates/lib.erb +23 -0
  106. data/templates/script.erb +7 -0
  107. data/templates/spec.erb +29 -0
  108. metadata +344 -0
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/octopolo/github/user"
3
+
4
+ module Octopolo
5
+ module GitHub
6
+ describe User do
7
+ context ".new login" do
8
+ it "remembers the given login" do
9
+ user = User.new "foo"
10
+ user.login.should == "foo"
11
+ end
12
+ end
13
+
14
+ context "#author_name" do
15
+ let(:octo) { stub }
16
+ let(:login) { "joeuser" }
17
+ let(:user) { User.new login }
18
+
19
+ before do
20
+ user.stub(user_data: octo)
21
+ end
22
+
23
+ it "fetches the real name from GitHub" do
24
+ octo.stub(name: "Joe User")
25
+ user.author_name.should == octo.name
26
+ end
27
+
28
+ it "returns the login if GitHub user has no name" do
29
+ octo.stub(name: nil)
30
+ user.author_name.should == user.login
31
+ end
32
+ end
33
+
34
+ context "#user_data" do
35
+ let(:login) { "joeuser" }
36
+ let(:user) { User.new login }
37
+ let(:octo) { stub }
38
+
39
+ it "fetches the data from the User class" do
40
+ User.should_receive(:user_data).with(login) { octo }
41
+ user.user_data.should == octo
42
+ end
43
+ end
44
+
45
+ context ".user_data login" do
46
+ let(:base_login) { "joeuser" }
47
+ let(:octo) { stub }
48
+
49
+ it "fetches the data from GitHub" do
50
+ login = "#{base_login}#{rand(100000)}"
51
+ GitHub.should_receive(:user).with(login) { octo }
52
+ User.user_data(login).should == octo
53
+ end
54
+
55
+ it "caches the data" do
56
+ login = "#{base_login}#{rand(100000)}"
57
+ GitHub.should_receive(:user).once { octo }
58
+ User.user_data(login)
59
+ User.user_data(login)
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,169 @@
1
+ require "spec_helper"
2
+ require_relative "../../lib/octopolo/github"
3
+
4
+ module Octopolo
5
+ describe GitHub do
6
+ context ".client" do
7
+ let(:octokit_client) { stub(:github_client) }
8
+ let(:user_config) { stub(:user_config, github_user: "foo", github_token: "bar") }
9
+
10
+ before do
11
+ GitHub.stub(user_config: user_config)
12
+ end
13
+
14
+ it "logs in with the configured authentication values" do
15
+ Octokit::Client.should_receive(:new).with(login: user_config.github_user, access_token: user_config.github_token) { octokit_client }
16
+ GitHub.client.should == octokit_client
17
+ end
18
+
19
+ it "uses additional given parameters" do
20
+ Octokit::Client.should_receive(:new).with(login: user_config.github_user, access_token: user_config.github_token, auto_traversal: true) { octokit_client }
21
+ GitHub.client(auto_traversal: true).should == octokit_client
22
+ end
23
+
24
+ it "properly handles if the github authentication isn't configured" do
25
+ user_config.should_receive(:github_user).and_raise(UserConfig::MissingGitHubAuth)
26
+ Scripts::GithubAuth.should_not_receive(:invoke)
27
+ expect { GitHub.client }.to raise_error(GitHub::TryAgain, "No GitHub API token stored. Please run `bundle exec github-auth` to generate your token.")
28
+ end
29
+ end
30
+
31
+ context ".crawling_client" do
32
+ let(:client) { stub }
33
+
34
+ it "instantiates a client with auto_traversal" do
35
+ GitHub.should_receive(:client).with(auto_traversal: true) { client }
36
+ GitHub.crawling_client.should == client
37
+ end
38
+ end
39
+
40
+ context "having convenience methods" do
41
+ let(:client) { stub(:github_client) }
42
+ let(:crawling_client) { stub(:github_crawling_client) }
43
+ let(:data) { stub }
44
+
45
+ before do
46
+ GitHub.stub(client: client, crawling_client: crawling_client)
47
+ end
48
+
49
+ context ".pull_request *args" do
50
+ it "sends onto the client wrapper" do
51
+ client.should_receive(:pull_request).with("a", "b") { data }
52
+ result = GitHub.pull_request("a", "b")
53
+ result.should == data
54
+ end
55
+ end
56
+
57
+ context ".pull_request_commits *args" do
58
+ it "sends onto the client wrapper" do
59
+ client.should_receive(:pull_request_commits).with("a", "b") { data }
60
+ result = GitHub.pull_request_commits("a", "b")
61
+ result.should == data
62
+ end
63
+ end
64
+
65
+ context ".issue_comments *args" do
66
+ it "sends onto the client wrapper" do
67
+ client.should_receive(:issue_comments).with("a", "b") { data }
68
+ result = GitHub.issue_comments("a", "b")
69
+ result.should == data
70
+ end
71
+ end
72
+
73
+ context ".pull_requests *args" do
74
+ it "sends onto the crawling client wrapper" do
75
+ crawling_client.should_receive(:pull_requests).with("a", "b") { data }
76
+ GitHub.pull_requests("a", "b").should == data
77
+ end
78
+ end
79
+
80
+ context ".tst_repos" do
81
+ it "fetches the sportngin organization repos" do
82
+ crawling_client.should_receive(:organization_repositories).with("sportngin") { data }
83
+ GitHub.org_repos.should == data
84
+ end
85
+
86
+ it "fetches another organization's repos if requested" do
87
+ crawling_client.should_receive(:organization_repositories).with("foo") { data }
88
+ GitHub.org_repos("foo").should == data
89
+ end
90
+ end
91
+
92
+ context ".create_pull_request" do
93
+ it "sends the pull request to the API" do
94
+ client.should_receive(:create_pull_request).with("repo", "destination_branch", "source_branch", "title", "body") { data }
95
+ GitHub.create_pull_request("repo", "destination_branch", "source_branch", "title", "body").should == data
96
+ end
97
+ end
98
+
99
+ context ".add_comment" do
100
+ it "sends the comment to the API" do
101
+ client.should_receive(:add_comment).with("repo", 123, "contents of comment")
102
+ GitHub.add_comment "repo", 123, "contents of comment"
103
+ end
104
+ end
105
+
106
+ context ".user username" do
107
+ let(:username) { "foo" }
108
+ let(:valid_user) { stub(login: "foo", name: "Joe Foo")}
109
+
110
+ it "fetches the user data from GitHub" do
111
+ client.should_receive(:user).with(username) { valid_user }
112
+ GitHub.user(username).should == valid_user
113
+ end
114
+
115
+ it "returns a generic Unknown user if none is found" do
116
+ client.should_receive(:user).with(username).and_raise(Octokit::NotFound)
117
+ GitHub.user(username).should == Hashie::Mash.new(name: GitHub::UNKNOWN_USER)
118
+ end
119
+ end
120
+
121
+ context ".check_connection" do
122
+ it "performs a request against the API which requires authentication" do
123
+ client.should_receive(:user)
124
+ GitHub.check_connection
125
+ end
126
+
127
+ it "raises BadCredentials if testing the connection raises Octokit::Unauthorized" do
128
+ client.should_receive(:user).and_raise(Octokit::Unauthorized)
129
+ expect { GitHub.check_connection }.to raise_error(GitHub::BadCredentials)
130
+ end
131
+ end
132
+
133
+ context ".connect &block" do
134
+ let(:thing) { stub }
135
+ let(:try_again) { GitHub::TryAgain.new("try-again message") }
136
+ let(:bad_credentials) { GitHub::BadCredentials.new("bad-credentials message") }
137
+
138
+ it "performs the block if GitHub.check_connection does not raise an exception" do
139
+ GitHub.should_receive(:check_connection)
140
+ thing.should_receive(:foo)
141
+
142
+ GitHub.connect do
143
+ thing.foo
144
+ end
145
+ end
146
+
147
+ it "does not perform the block if GitHub.check_connection raises TryAgain" do
148
+ GitHub.should_receive(:check_connection).and_raise(try_again)
149
+ thing.should_not_receive(:foo)
150
+ CLI.should_receive(:say).with(try_again.message)
151
+
152
+ GitHub.connect do
153
+ thing.foo
154
+ end
155
+ end
156
+
157
+ it "does not perform the block if GitHub.check_connection raises BadCredentials" do
158
+ GitHub.should_receive(:check_connection).and_raise(bad_credentials)
159
+ thing.should_not_receive(:foo)
160
+ CLI.should_receive(:say).with(bad_credentials.message)
161
+
162
+ GitHub.connect do
163
+ thing.foo
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/octopolo/jira/story_commenter"
3
+
4
+ module Octopolo
5
+ module Jira
6
+ describe StoryCommenter do
7
+ let(:comments) { stub }
8
+ let(:issue) { stub(:comments => comments) }
9
+ context ".new" do
10
+ it "finds the issue via the jira api" do
11
+ Jiralicious.should_receive(:configure)
12
+ Jiralicious::Issue.should_receive(:find).with(:id).and_return(issue)
13
+ StoryCommenter.new(:id, 'text')
14
+ end
15
+ end
16
+
17
+ context "#perform" do
18
+ let(:comment) { "test comment" }
19
+ before do
20
+ Jiralicious::Issue.stub(:find).with(:id).and_return(issue)
21
+ end
22
+
23
+ it "creates a new note for the story" do
24
+ comments.should_receive(:add).with(comment)
25
+ StoryCommenter.new(:id, comment).perform
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+ require_relative "../../../lib/octopolo/pivotal/story_commenter"
3
+
4
+ module Octopolo
5
+ module Pivotal
6
+ describe StoryCommenter do
7
+ let(:client) { stub }
8
+ before do
9
+ Pivotal::Client.stub(:new) { client }
10
+ end
11
+
12
+ context ".new" do
13
+ it "finds the story via the pivotal api" do
14
+ client.should_receive(:find_story).with(:id)
15
+ StoryCommenter.new(:id, 'text')
16
+ end
17
+ end
18
+
19
+ context "#perform" do
20
+ let(:notes) { stub }
21
+ let(:story) { stub(notes: notes) }
22
+ let(:comment) { "test comment" }
23
+
24
+ it "creates a new note for the story" do
25
+ client.stub(:find_story) { story }
26
+ note = stub
27
+ notes.should_receive(:new).with(owner: story, text: comment) { note }
28
+ note.should_receive(:create)
29
+ StoryCommenter.new(story, comment).perform
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+ require_relative "../../lib/octopolo/pivotal"
3
+
4
+ module Octopolo
5
+ module Pivotal
6
+ describe Client do
7
+
8
+ let(:user_config) { stub(:user_config, pivotal_token: "token") }
9
+
10
+ before do
11
+ Client.any_instance.stub(user_config: user_config)
12
+ end
13
+
14
+ context ".new" do
15
+ it "forces the PivotalTracker gem to use SSL" do
16
+ ::PivotalTracker::Client.should_receive(:use_ssl=).with(true)
17
+ Pivotal::Client.new
18
+ end
19
+ end
20
+
21
+ context ".fetch_token(email, password)" do
22
+ let(:email) { "example@example.com" }
23
+ let(:password) { "sekret" }
24
+ let(:token) { "dead-beef" }
25
+
26
+ it "passes down to the PivotalTracker gem" do
27
+ ::PivotalTracker::Client.should_receive(:token).with(email, password) { token }
28
+ expect(Client.fetch_token email, password).to eq(token)
29
+ end
30
+
31
+ it "raises BadCredentials if given invalid credentials" do
32
+ ::PivotalTracker::Client.should_receive(:token).and_raise(RestClient::Unauthorized)
33
+ expect { Client.fetch_token email, password }.to raise_error(BadCredentials)
34
+ end
35
+ end
36
+
37
+ context "#find_story(story_id)" do
38
+ let(:project) { PivotalTracker::Project.new }
39
+ let(:story) { PivotalTracker::Story.new }
40
+
41
+ it "gets all of the PT projects" do
42
+ project.stub_chain(:stories, :find).with(:id) { story }
43
+ PivotalTracker::Project.should_receive(:all) { [project] }
44
+ subject.find_story(:id)
45
+ end
46
+
47
+ it "finds the story that matches the id" do
48
+ PivotalTracker::Project.stub(:all) { [project] }
49
+ project.stub_chain(:stories, :find).with(:id) { story }
50
+ expect(subject.find_story(:id)).to eq(story)
51
+ end
52
+
53
+ it "raises StoryNoteFound if no story is found" do
54
+ PivotalTracker::Project.stub(:all) { [] }
55
+ project.stub_chain(:stories, :find).with(:id) { nil }
56
+ expect { subject.find_story(:id) }.to raise_error(StoryNotFound)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,144 @@
1
+ require "spec_helper"
2
+ require "octopolo/pull_request_merger"
3
+
4
+ module Octopolo
5
+ module Scripts
6
+ describe PullRequestMerger do
7
+ let(:cli) { stub(:CLI) }
8
+ let(:config) { stub(:Config, github_repo: "tstmedia/foo") }
9
+ let(:pull_request_id) { 42 }
10
+ let(:pull_request) { stub(:PullRequest, branch: "cool-feature", url: "http://example.com/") }
11
+ let(:branch_type) { Git::DEPLOYABLE_PREFIX }
12
+ let(:git) { stub(:git, deployable_branch: "deployable") }
13
+ let(:options) { { :user_notifications => ['NickLaMuro', 'anfleene'] } }
14
+
15
+ subject { PullRequestMerger.new(Git::DEPLOYABLE_PREFIX, 42, options) }
16
+
17
+ before do
18
+ subject.git = git
19
+ subject.config = config
20
+ subject.cli = cli
21
+ end
22
+
23
+ context "#pull_request" do
24
+ before do
25
+ subject.pull_request_id = pull_request_id
26
+ end
27
+
28
+ it "finds the PullRequest for the given ID" do
29
+ GitHub::PullRequest.should_receive(:new).with(config.github_repo, pull_request_id) { pull_request }
30
+ subject.pull_request.should == pull_request
31
+ end
32
+
33
+ it "caches the PullRequest" do
34
+ GitHub::PullRequest.should_receive(:new).once { pull_request }
35
+ subject.pull_request
36
+ subject.pull_request
37
+ end
38
+ end
39
+
40
+ context "#perform" do
41
+ before do
42
+ subject.pull_request_id = pull_request_id
43
+ subject.pull_request = pull_request
44
+ end
45
+
46
+ it "checks out branch, merges the pull request's branch, and writes a comment" do
47
+ git.stub(:if_clean).and_yield # do not yield, index is dirty
48
+ subject.should_receive(:check_out_branch)
49
+ subject.should_receive(:merge_pull_request)
50
+ subject.should_receive(:comment_about_merge)
51
+
52
+ subject.perform
53
+ end
54
+
55
+ it "does nothing if the index is dirty" do
56
+ git.stub(:if_clean) # do not yield, index is dirty
57
+ subject.should_not_receive(:check_out_branch)
58
+ subject.should_not_receive(:merge_pull_request)
59
+ subject.should_not_receive(:comment_about_merge)
60
+
61
+ subject.perform
62
+ end
63
+
64
+ it "properly handles an invalid pull request ID" do
65
+ git.should_receive(:if_clean).and_raise(GitHub::PullRequest::NotFound)
66
+ cli.should_receive(:say).with("Unable to find pull request #{pull_request_id}. Please retry with a valid ID.")
67
+
68
+ subject.perform
69
+ end
70
+
71
+ it "properly handles a failed merge" do
72
+ git.should_receive(:if_clean).and_raise(Git::MergeFailed)
73
+ cli.should_receive(:say).with("Merge failed. Please identify the source of this merge conflict resolve this conflict in your pull request's branch. NOTE: Merge conflicts resolved in the deployable branch are NOT used when deploying.")
74
+
75
+ subject.perform
76
+ end
77
+
78
+ it "properly handles a failed checkout of branch" do
79
+ git.should_receive(:if_clean).and_raise(Git::CheckoutFailed)
80
+ git.should_receive(:latest_branch_for).with("deployable").and_return("deployable")
81
+ cli.should_receive(:say).with("Checkout of #{git.deployable_branch} failed. Please contact Infrastructure to determine the cause.")
82
+
83
+ subject.perform
84
+ end
85
+
86
+ it "properly handles a failed comment" do
87
+ git.should_receive(:if_clean).and_raise(GitHub::PullRequest::CommentFailed)
88
+ git.should_receive(:latest_branch_for).with("deployable").and_return("deployable")
89
+ cli.should_receive(:say).with("Unable to write comment. Please navigate to #{pull_request.url} and add the comment, '#{subject.comment_body}'")
90
+ subject.perform
91
+ end
92
+ end
93
+
94
+ context "#check_out_branch" do
95
+ let(:creator) { stub(:dated_branch_creator, branch_name: "new-deployable") }
96
+
97
+ it "checks out the project's deployable branch" do
98
+ git.should_receive(:check_out).with(git.deployable_branch)
99
+ git.should_receive(:latest_branch_for).with("deployable").and_return("deployable")
100
+ subject.check_out_branch
101
+ end
102
+
103
+ it "creates a new deployable branch if none exists, and checks it out" do
104
+ git.should_receive(:latest_branch_for).with(Git::DEPLOYABLE_PREFIX).and_raise(Git::NoBranchOfType)
105
+ DatedBranchCreator.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX) { creator }
106
+ git.should_receive(:check_out).with(creator.branch_name)
107
+ cli.should_receive(:say).with("No deployable branch available. Creating one now.")
108
+ subject.check_out_branch
109
+ end
110
+ end
111
+
112
+ context "#merge_pull_request" do
113
+ before do
114
+ subject.pull_request = pull_request
115
+ end
116
+
117
+ it "merges the pull request into the checked-out branch" do
118
+ git.should_receive(:merge).with(pull_request.branch)
119
+ subject.merge_pull_request
120
+ end
121
+ end
122
+
123
+ context "#comment_about_merge" do
124
+ before do
125
+ subject.pull_request = pull_request
126
+ end
127
+
128
+ it "submits a comment that the pull request was merged into the branch" do
129
+ git.should_receive(:latest_branch_for).with("deployable").and_return("deployable")
130
+ pull_request.should_receive(:write_comment).with(subject.comment_body)
131
+
132
+ subject.comment_about_merge
133
+ end
134
+ end
135
+
136
+ context "#comment_body" do
137
+ it "contains the default comment body" do
138
+ git.should_receive(:latest_branch_for).with("deployable").and_return("deployable")
139
+ subject.comment_body.should == "Merged into #{git.deployable_branch}. /cc @NickLaMuro @anfleene"
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end