-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathpull_request_spec.rb
More file actions
139 lines (92 loc) · 3.54 KB
/
pull_request_spec.rb
File metadata and controls
139 lines (92 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
require 'git-process/pull_request'
require 'github_test_helper'
require 'pull_request_helper'
require 'GitRepoHelper'
require 'sawyer'
require 'octokit'
describe GitProc::PullRequest do
include GitRepoHelper
include GitHubTestHelper
before(:each) do
create_files(%w(.gitignore))
gitlib.commit('initial')
end
after(:each) do
rm_rf(gitlib.workdir)
end
def log_level
Logger::ERROR
end
describe 'with no parameters' do
def create_process(dir, opts)
GitProc::PullRequest.new(dir, opts)
end
it 'should push the branch and create a default pull request' do
pr_client = double('pr_client')
gitlib.config['gitProcess.integrationBranch'] = 'develop'
gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')
GitProc::PullRequest.stub(:create_pull_request_client).and_return(pr_client)
#PullRequest.stub(:create_pull_request_client).with(anything, 'origin', 'jdigger/git-process').and_return(pr_client)
gitlib.should_receive(:push)
agent = Sawyer::Agent.new(Octokit::Default::API_ENDPOINT, {})
sawyer_resource = Sawyer::Resource.new(agent, {:html_url => 'http://test'})
pr_client.should_receive(:create).with('develop', 'master', 'master', '').and_return(sawyer_resource)
gitprocess.runner
end
it 'should fail if the base and head branch are the same' do
gitlib.remote.add('origin', 'git@github.com:jdigger/git-process.git')
expect {
gitprocess.runner
}.to raise_error GitProc::PullRequestError
end
end
describe 'checkout pull request' do
include PullRequestHelper
before(:each) do
gitlib.config['gitProcess.github.authToken'] = 'sdfsfsdf'
gitlib.config['github.user'] = 'jdigger'
end
describe "with PR #" do
def pull_request
@pr ||= create_pull_request({})
end
def create_process(dir, opts)
GitProc::PullRequest.new(dir, opts.merge({:prNumber => pull_request[:number]}))
end
it 'should checkout the branch for the pull request' do
add_remote(:head)
stub_fetch(:head)
stub_get_pull_request(pull_request)
expect_checkout_pr_head()
expect_upstream_set()
gitlib.stub(:branch).with(nil, :no_color => true, :all => true).and_return('')
gitlib.stub(:branch).with(nil, :no_color => true, :remote => true).and_return('')
gitlib.should_receive(:rebase).with('tester/test_repo/master', {})
gitprocess.runner
end
end
describe 'with repo name and PR #' do
def pull_request
@pr ||= create_pull_request(:base_remote => 'sourcerepo', :base_repo => 'source_repo')
end
def create_process(dir, opts)
GitProc::PullRequest.new(dir, opts.merge({:prNumber => pull_request[:number],
:server => pull_request[:head][:remote]}))
end
it 'should checkout the branch for the pull request' do
add_remote(:head)
add_remote(:base)
stub_fetch(:head)
stub_fetch(:base)
gitlib.config['gitProcess.remoteName'] = pull_request[:head][:repo][:name]
stub_get_pull_request(pull_request)
expect_checkout_pr_head()
expect_upstream_set()
gitlib.stub(:branch).with(nil, :no_color => true, :all => true).and_return('')
gitlib.stub(:branch).with(nil, :no_color => true, :remote => true).and_return('')
gitlib.should_receive(:rebase).with('tester/test_repo/master', {})
gitprocess.runner
end
end
end
end