-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathrepos_spec.rb
157 lines (137 loc) · 4.15 KB
/
repos_spec.rb
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require 'spec_helper'
describe BitBucket::Repos do
let(:repo) { BitBucket::Repos.new }
# class_eval is setting global variables in api.rb, this is creating
# failed expectations when these variables are not reset to nil before
# the next test is run. Therefore we must clear them manually as
# for the user attribute below...
after do
repo.clear_user
end
describe '.create' do
before do
expect(repo).to receive(:request).with(
:post,
'/1.0/repositories/',
BitBucket::Repos::DEFAULT_REPO_OPTIONS.merge({ 'owner' => 'mock_owner', 'name' => 'mock_repo' }),
{}
)
end
it 'should send a POST request to create the repo' do
repo.create({ 'owner' => 'mock_owner', 'name' => 'mock_repo' })
end
end
describe '.delete' do
before do
expect(repo).to receive(:request).with(
:delete,
'/1.0/repositories/mock_username/mock_repo',
{},
{}
)
end
it 'should send a DELETE request for the given repo' do
repo.delete('mock_username', 'mock_repo')
end
end
# TODO: fix case where block_given? returns true
describe '.branches' do
before do
expect(repo).to receive(:request).with(
:get,
'/1.0/repositories/mock_username/mock_repo/branches/',
{},
{}
).and_return(['branch1', 'branch2', 'branch3'])
end
context 'without a block' do
it 'invokes the .request method' do
repo.branches('mock_username', 'mock_repo')
end
end
context 'with a block' do
it 'invokes the .request method' do
repo.branches('mock_username', 'mock_repo') { |branch| branch }
end
end
end
describe '.edit' do
before do
expect(repo).to receive(:request).with(
:put,
'/1.0/repositories/mock_username/mock_repo/',
BitBucket::Repos::DEFAULT_REPO_OPTIONS.merge({ 'owner' => 'mock_owner' }),
{}
)
end
it 'should send a PUT request for the given repo' do
repo.edit('mock_username', 'mock_repo', { 'owner' => 'mock_owner' })
end
end
# TODO: make sure this gets documented in gem since it is not in official docs
describe '.get' do
before do
expect(repo).to receive(:request).with(
:get,
'/1.0/repositories/mock_username/mock_repo',
{},
{}
)
end
it 'should send a GET request for the given repo' do
repo.get('mock_username', 'mock_repo', {})
end
end
describe '.list' do
before do
expect(repo).to receive(:request).with(
:get,
'/2.0/repositories',
{"pagelen" => 100},
{}
).and_return(values: ['repo1', 'repo2' ,'repo3'])
end
# FIXME: this method belongs in the User class!
context 'without a block' do
it 'should send a GET request for the authenticated users repos' do
repo.list
end
end
context 'with a block' do
it 'should send a GET request for the authenticated users repos' do
repo.list { |repo| repo }
end
end
end
describe '.tags' do
before do
expect(repo).to receive(:request).with(
:get,
'/1.0/repositories/mock_username/mock_repo/tags/',
{},
{}
).and_return(['tag1', 'tag2' ,'tag3'])
end
context 'without a block' do
it 'should send a GET request for the tags belonging to the given repo' do
repo.tags('mock_username', 'mock_repo')
end
end
context 'with a block' do
it 'should send a GET request for the tags belonging to the given repo' do
repo.tags('mock_username', 'mock_repo') { |tag| tag }
end
end
end
describe "getter methods" do
it "returns an object of the correct class" do
expect(repo.changesets).to be_a BitBucket::Repos::Changesets
expect(repo.keys).to be_a BitBucket::Repos::Keys
expect(repo.following).to be_a BitBucket::Repos::Following
expect(repo.commits).to be_a BitBucket::Repos::Commits
expect(repo.pull_request).to be_a BitBucket::Repos::PullRequest
expect(repo.forks).to be_a BitBucket::Repos::Forks
expect(repo.download).to be_a BitBucket::Repos::Download
end
end
end