spec/unit/lita/handlers/github_pr_spec.rb in lita-github-0.0.7 vs spec/unit/lita/handlers/github_pr_spec.rb in lita-github-0.0.8
- old
+ new
@@ -1,14 +1,26 @@
# -*- coding: UTF-8 -*-
require 'spec_helper'
describe Lita::Handlers::GithubPR, lita_handler: true do
- it { routes_command('gh shipit #42 GrapeDuty/lita-test').to(:pr_merge) }
- it { routes_command('gh pr merge #42 GrapeDuty/lita-test').to(:pr_merge) }
- it { routes_command('shipit #42 GrapeDuty/lita-test').to(:pr_merge) }
+ # pr_merge command routing
+ it { routes_command('gh shipit GrapeDuty/lita-test #42').to(:pr_merge) }
+ it { routes_command('gh shipit lita-test #42').to(:pr_merge) }
+ it { routes_command('gh pr merge lita-test #42').to(:pr_merge) }
+ it { routes_command('gh pr merge GrapeDuty/lita-test #42').to(:pr_merge) }
+ it { routes_command('shipit GrapeDuty/lita-test #42').to(:pr_merge) }
+ it { routes_command('shipit lita-test #42').to(:pr_merge) }
+ # pr_info command routing
+ it { routes_command('gh pr info GrapeDuty/lita-test #42').to(:pr_info) }
+ it { routes_command('gh pr info lita-test #42').to(:pr_info) }
+
+ # pr_list command routing
+ it { routes_command('gh pr list GrapeDuty/lita-test').to(:pr_list) }
+ it { routes_command('gh pr list lita-test').to(:pr_list) }
+
let(:github_pr) { Lita::Handlers::GithubPR.new('robot') }
let(:github_org) { 'GrapeDuty' }
let(:github_repo) { 'lita-test' }
let(:full_name) { "#{github_org}/#{github_repo}" }
let(:disabled_reply) { 'Sorry, this function has either been disabled or not enabled in the config' }
@@ -429,11 +441,11 @@
"https://github.com/GrapeDuty/lita-test/pulls/42\n" \
"Opened By: theckman (Tim Heckman) | State: Open | Build: success | Mergeable: true\n" \
'Head: 1234567 | Commits: 1 (+42/-0) :: ' \
"https://github.com/GrapeDuty/lita-test/compare/0987654321...1234567890\n" \
"PR Comments: 1 | Code Comments: 2\n"
- send_command("gh pr info #42 #{github_org}/#{github_repo}")
+ send_command("gh pr info #{github_org}/#{github_repo} #42")
expect(replies.last).to eql r
end
end
context 'when the PR has been merged' do
@@ -457,11 +469,11 @@
'Opened By: theckman (Tim Heckman) | State: Merged | Build: success | ' \
"Merged By: theckman (Tim Heckman)\n" \
'Head: 1234567 | Commits: 1 (+42/-0) :: ' \
"https://github.com/GrapeDuty/lita-test/compare/0987654321...1234567890\n" \
"PR Comments: 1 | Code Comments: 2\n"
- send_command("gh pr info #42 #{github_org}/#{github_repo}")
+ send_command("gh pr info #{github_org}/#{github_repo} #42")
expect(replies.last).to eql r
end
end
context 'when the PR was not found' do
@@ -469,11 +481,11 @@
@pr_resp = { fail: true, not_found: true, pr: @pr_info }
allow(github_pr).to receive(:pull_request).and_return(@pr_resp)
end
it 'should reply with the not found error' do
- send_command("gh pr info #42 #{github_org}/#{github_repo}")
+ send_command("gh pr info #{github_org}/#{github_repo} #42")
expect(replies.last).to eql 'Pull request #42 on GrapeDuty/lita-test not found'
end
end
end
@@ -493,36 +505,36 @@
before do
allow(github_pr).to receive(:func_disabled?).and_return(true)
end
it 'should no-op and say such' do
- send_command("shipit #42 #{github_org}/#{github_repo}")
+ send_command("shipit #{github_org}/#{github_repo} #42")
expect(replies.last).to eql disabled_reply
end
end
context 'when repo not found' do
before do
allow(@octo_obj).to receive(:pull_request).and_raise(Octokit::NotFound.new)
end
it 'should reply indicating it was invalid' do
- send_command("shipit #42 #{github_org}/#{github_repo}")
+ send_command("shipit #{github_org}/#{github_repo} #42")
expect(replies.last).to eql 'Pull request #42 on GrapeDuty/lita-test not found'
end
end
context 'when merging should succeed' do
it 'should set the right commit message' do
expect(github_pr).to receive(:merge_pr).with(
'GrapeDuty', 'lita-test', '42', "Merge pull request #42 from GrapeDuty/fix-some-bugs\n\nfix bug"
)
- send_command('shipit #42 GrapeDuty/lita-test')
+ send_command('shipit GrapeDuty/lita-test #42')
end
it 'should confirm merging of PR' do
- send_command("shipit #42 #{github_org}/#{github_repo}")
+ send_command("shipit #{github_org}/#{github_repo} #42")
expect(replies.last)
.to eql "Merged pull request #42 from GrapeDuty/fix-some-bugs\nfix bug"
end
end
@@ -531,11 +543,11 @@
@merge_status = { sha: 'abc456', merged: false, message: '*BOOM*' }
allow(github_pr).to receive(:merge_pr).and_return(@merge_status)
end
it 'should confirm the failure' do
- send_command("shipit #42 #{github_org}/#{github_repo}")
+ send_command("shipit #{github_org}/#{github_repo} #42")
expect(replies.last)
.to eql(
"Failed trying to merge PR #42 (fix bug) :: https://github.com/GrapeDuty/lita-test/pull/42\n"\
'Message: *BOOM*'
)
@@ -548,10 +560,10 @@
@octo_obj = double('Octokit::Client', pull_request: @pr_obj)
allow(github_pr).to receive(:merge_pr).and_return(nil)
end
it 'should confirm the failure' do
- send_command("shipit #42 #{github_org}/#{github_repo}")
+ send_command("shipit #{github_org}/#{github_repo} #42")
expect(replies.last)
.to eql(
'An unexpected exception was hit during the GitHub API operation. Please make sure all ' \
'arguments are proper and try again, or try checking the GitHub status (gh status)'
)