twig 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,31 +8,33 @@ describe Twig::CommitTime do
8
8
  describe '#initialize' do
9
9
  it 'stores a Time object' do
10
10
  commit_time = Twig::CommitTime.new(@time, '99 days ago')
11
- commit_time.instance_variable_get(:@time).should == @time
11
+ expect(commit_time.instance_variable_get(:@time)).to eq(@time)
12
12
  end
13
13
 
14
14
  it 'stores a "time ago" string as its shortened version' do
15
- Twig::CommitTime.new(@time, '2 years ago').
16
- instance_variable_get(:@time_ago).should == '2y ago'
17
- Twig::CommitTime.new(@time, '2 months ago').
18
- instance_variable_get(:@time_ago).should == '2mo ago'
19
- Twig::CommitTime.new(@time, '2 weeks ago').
20
- instance_variable_get(:@time_ago).should == '2w ago'
21
- Twig::CommitTime.new(@time, '2 days ago').
22
- instance_variable_get(:@time_ago).should == '2d ago'
23
- Twig::CommitTime.new(@time, '2 hours ago').
24
- instance_variable_get(:@time_ago).should == '2h ago'
25
- Twig::CommitTime.new(@time, '2 minutes ago').
26
- instance_variable_get(:@time_ago).should == '2m ago'
27
- Twig::CommitTime.new(@time, '2 seconds ago').
28
- instance_variable_get(:@time_ago).should == '2s ago'
15
+ expect(Twig::CommitTime.new(@time, '2 years, 2 months ago').
16
+ instance_variable_get(:@time_ago)).to eq('2y ago')
17
+ expect(Twig::CommitTime.new(@time, '2 years ago').
18
+ instance_variable_get(:@time_ago)).to eq('2y ago')
19
+ expect(Twig::CommitTime.new(@time, '2 months ago').
20
+ instance_variable_get(:@time_ago)).to eq('2mo ago')
21
+ expect(Twig::CommitTime.new(@time, '2 weeks ago').
22
+ instance_variable_get(:@time_ago)).to eq('2w ago')
23
+ expect(Twig::CommitTime.new(@time, '2 days ago').
24
+ instance_variable_get(:@time_ago)).to eq('2d ago')
25
+ expect(Twig::CommitTime.new(@time, '2 hours ago').
26
+ instance_variable_get(:@time_ago)).to eq('2h ago')
27
+ expect(Twig::CommitTime.new(@time, '2 minutes ago').
28
+ instance_variable_get(:@time_ago)).to eq('2m ago')
29
+ expect(Twig::CommitTime.new(@time, '2 seconds ago').
30
+ instance_variable_get(:@time_ago)).to eq('2s ago')
29
31
  end
30
32
  end
31
33
 
32
34
  describe '#to_i' do
33
35
  it 'returns the time as an integer' do
34
36
  commit_time = Twig::CommitTime.new(@time, '99 days ago')
35
- commit_time.to_i.should == @time.to_i
37
+ expect(commit_time.to_i).to eq(@time.to_i)
36
38
  end
37
39
  end
38
40
 
@@ -40,8 +42,8 @@ describe Twig::CommitTime do
40
42
  it 'returns a formatted string, including time ago' do
41
43
  commit_time = Twig::CommitTime.new(@time, '99 days ago')
42
44
  result = commit_time.to_s
43
- result.should include('2000-12-01')
44
- result.should include('(99d ago)')
45
+ expect(result).to include('2000-12-01')
46
+ expect(result).to include('(99d ago)')
45
47
  end
46
48
  end
47
49
  end
@@ -7,20 +7,20 @@ describe Twig::Display do
7
7
 
8
8
  describe '#column' do
9
9
  it 'returns a string with an exact fixed width' do
10
- @twig.column('foo', :width => 8).should == 'foo' + (' ' * 5)
10
+ expect(@twig.column('foo', :width => 8)).to eq('foo' + (' ' * 5))
11
11
  end
12
12
 
13
13
  it 'returns a string that fits a column exactly' do
14
- @twig.column('asdfasdf', :width => 8).should == 'asdfasdf'
14
+ expect(@twig.column('asdfasdf', :width => 8)).to eq('asdfasdf')
15
15
  end
16
16
 
17
17
  it 'truncates a wide string with an ellipsis' do
18
- @twig.column('asdfasdfasdf', :width => 8).should == 'asdfa...'
18
+ expect(@twig.column('asdfasdfasdf', :width => 8)).to eq('asdfa...')
19
19
  end
20
20
 
21
21
  it 'passes options through to `format_string`' do
22
22
  format_options = { :color => :red, :weight => :bold }
23
- @twig.should_receive(:format_string).
23
+ expect(@twig).to receive(:format_string).
24
24
  with('foo' + (' ' * 5), format_options)
25
25
 
26
26
  @twig.column('foo', format_options)
@@ -29,52 +29,57 @@ describe Twig::Display do
29
29
 
30
30
  describe '#property_column_width' do
31
31
  it 'returns a default width if no property name is given' do
32
- @twig.property_column_width.should ==
32
+ expect(@twig.property_column_width).to eq(
33
33
  Twig::Display::DEFAULT_PROPERTY_COLUMN_WIDTH
34
+ )
34
35
  end
35
36
 
36
37
  context 'with no custom column widths set' do
37
38
  before :each do
38
- @twig.options[:property_width].should be_nil
39
+ expect(@twig.options[:property_width]).to be_nil
39
40
  end
40
41
 
41
42
  it 'returns a default width if a property name is given' do
42
- @twig.property_column_width(:foo).should ==
43
+ expect(@twig.property_column_width(:foo)).to eq(
43
44
  Twig::Display::DEFAULT_PROPERTY_COLUMN_WIDTH
45
+ )
44
46
  end
45
47
 
46
48
  it 'returns a default width if :branch is given' do
47
- @twig.property_column_width(:branch).should ==
49
+ expect(@twig.property_column_width(:branch)).to eq(
48
50
  Twig::Display::DEFAULT_BRANCH_COLUMN_WIDTH
51
+ )
49
52
  end
50
53
  end
51
54
 
52
55
  context 'with custom column widths set' do
53
56
  it 'returns a default width if a property name is given but it has no custom width' do
54
- @twig.property_column_width(:baz).should ==
57
+ expect(@twig.property_column_width(:baz)).to eq(
55
58
  Twig::Display::DEFAULT_PROPERTY_COLUMN_WIDTH
59
+ )
56
60
  end
57
61
 
58
62
  it 'returns a custom width if a property name is given and it has a custom width' do
59
63
  @twig.set_option(:property_width, :foo => 20)
60
- @twig.property_column_width(:foo).should == 20
64
+ expect(@twig.property_column_width(:foo)).to eq(20)
61
65
  end
62
66
 
63
67
  it 'returns a default width if :branch is given but it has no custom width' do
64
- @twig.property_column_width(:branch).should ==
68
+ expect(@twig.property_column_width(:branch)).to eq(
65
69
  Twig::Display::DEFAULT_BRANCH_COLUMN_WIDTH
70
+ )
66
71
  end
67
72
 
68
73
  it 'returns a custom width if :branch is given but it has no custom width' do
69
74
  @twig.set_option(:property_width, :branch => 20)
70
- @twig.property_column_width(:branch).should == 20
75
+ expect(@twig.property_column_width(:branch)).to eq(20)
71
76
  end
72
77
  end
73
78
  end
74
79
 
75
80
  describe '#branch_list_headers' do
76
81
  before :each do
77
- Twig::Branch.stub(:all_property_names => %w[foo quux])
82
+ allow(Twig::Branch).to receive(:all_property_names) { %w[foo quux] }
78
83
  end
79
84
 
80
85
  it 'returns a string of branch properties and underlines' do
@@ -84,14 +89,18 @@ describe Twig::Display do
84
89
  date_time_column_width = 35
85
90
  extra_property_column_width = 8
86
91
  column_gutter = @twig.column_gutter
87
- result_lines[0].should == (' ' * date_time_column_width) + column_gutter +
92
+ expect(result_lines[0]).to eq(
93
+ (' ' * date_time_column_width) + column_gutter +
88
94
  'foo ' + (' ' * extra_property_column_width) + column_gutter +
89
95
  'quux ' + (' ' * extra_property_column_width) + column_gutter +
90
96
  ' branch'
91
- result_lines[1].should == (' ' * date_time_column_width) + column_gutter +
97
+ )
98
+ expect(result_lines[1]).to eq(
99
+ (' ' * date_time_column_width) + column_gutter +
92
100
  '--- ' + (' ' * extra_property_column_width) + column_gutter +
93
101
  '---- ' + (' ' * extra_property_column_width) + column_gutter +
94
102
  ' ------'
103
+ )
95
104
  end
96
105
 
97
106
  it 'sets a header width' do
@@ -103,44 +112,51 @@ describe Twig::Display do
103
112
  date_time_column_width = 35
104
113
  extra_property_column_width = 8
105
114
  column_gutter = @twig.column_gutter
106
- result_lines[0].should == (' ' * date_time_column_width) + column_gutter +
115
+ expect(result_lines[0]).to eq(
116
+ (' ' * date_time_column_width) + column_gutter +
107
117
  'foo ' + column_gutter +
108
118
  'quux ' + (' ' * extra_property_column_width) + column_gutter +
109
119
  ' branch'
110
- result_lines[1].should == (' ' * date_time_column_width) + column_gutter +
120
+ )
121
+ expect(result_lines[1]).to eq(
122
+ (' ' * date_time_column_width) + column_gutter +
111
123
  '--- ' + column_gutter +
112
124
  '---- ' + (' ' * extra_property_column_width) + column_gutter +
113
125
  ' ------'
126
+ )
114
127
  end
115
128
 
116
129
  it 'sets a header color' do
117
130
  result = @twig.branch_list_headers({ :header_color => :green })
118
131
  header_line = result.split("\n").first
119
132
  color = Twig::Display::COLORS[:green]
120
- header_line.gsub(/\s/, '').should ==
133
+ expect(header_line.gsub(/\s/, '')).to eq(
121
134
  "\e[#{color}mfoo\e[0m" <<
122
135
  "\e[#{color}mquux\e[0m" <<
123
136
  "\e[#{color}mbranch\e[0m"
137
+ )
124
138
  end
125
139
 
126
140
  it 'sets a header weight' do
127
141
  result = @twig.branch_list_headers({ :header_weight => :bold })
128
142
  header_line = result.split("\n").first
129
143
  weight = Twig::Display::WEIGHTS[:bold]
130
- header_line.gsub(/\s/, '').should ==
144
+ expect(header_line.gsub(/\s/, '')).to eq(
131
145
  "\e[#{weight}mfoo\e[0m" <<
132
146
  "\e[#{weight}mquux\e[0m" <<
133
147
  "\e[#{weight}mbranch\e[0m"
148
+ )
134
149
  end
135
150
 
136
151
  it 'sets a header color and weight' do
137
152
  result = @twig.branch_list_headers({ :header_color => :red, :header_weight => :bold })
138
153
  header_line = result.split("\n").first
139
154
  color, weight = Twig::Display::COLORS[:red], Twig::Display::WEIGHTS[:bold]
140
- header_line.gsub(/\s/, '').should ==
155
+ expect(header_line.gsub(/\s/, '')).to eq(
141
156
  "\e[#{color};#{weight}mfoo\e[0m" <<
142
157
  "\e[#{color};#{weight}mquux\e[0m" <<
143
158
  "\e[#{color};#{weight}mbranch\e[0m"
159
+ )
144
160
  end
145
161
  end
146
162
 
@@ -148,20 +164,18 @@ describe Twig::Display do
148
164
  before :each do
149
165
  @current_branch = Twig::Branch.new('my-branch')
150
166
  @other_branch = Twig::Branch.new('other-branch')
151
- @twig.should_receive(:current_branch_name).and_return(@current_branch.name)
152
- Twig::Branch.stub(:all_property_names => %w[foo bar])
153
- @current_branch.stub(:get_properties => {
154
- 'foo' => 'foo!',
155
- 'bar' => 'bar!'
156
- })
157
- @other_branch.stub(:get_properties => {
158
- 'foo' => 'foo!',
159
- 'bar' => 'bar!'
160
- })
167
+ expect(@twig).to receive(:current_branch_name).and_return(@current_branch.name)
168
+ allow(Twig::Branch).to receive(:all_property_names) { %w[foo bar] }
169
+ allow(@current_branch).to receive(:get_properties) do
170
+ { 'foo' => 'foo!', 'bar' => 'bar!' }
171
+ end
172
+ allow(@other_branch).to receive(:get_properties) do
173
+ { 'foo' => 'foo!', 'bar' => 'bar!' }
174
+ end
161
175
  commit_time = Twig::CommitTime.new(Time.now, '')
162
- commit_time.should_receive(:to_s).and_return('2000-01-01')
163
- @current_branch.stub(:last_commit_time => commit_time)
164
- @other_branch.stub(:last_commit_time => commit_time)
176
+ expect(commit_time).to receive(:to_s).and_return('2000-01-01')
177
+ allow(@current_branch).to receive(:last_commit_time) { commit_time }
178
+ allow(@other_branch).to receive(:last_commit_time) { commit_time }
165
179
  end
166
180
 
167
181
  it 'returns a line for the current branch' do
@@ -171,38 +185,38 @@ describe Twig::Display do
171
185
 
172
186
  result = @twig.branch_list_line(branch)
173
187
 
174
- result.should =~ /2000-01-01\s+foo!\s+bar!\s+#{branch_regexp}/
188
+ expect(result).to match(/2000-01-01\s+foo!\s+bar!\s+#{branch_regexp}/)
175
189
  end
176
190
 
177
191
  it 'returns a line for a branch other than the current branch' do
178
192
  branch = @other_branch
179
193
  result = @twig.branch_list_line(branch)
180
- result.should =~ /2000-01-01\s+foo!\s+bar!\s+#{Regexp.escape(branch.name)}/
194
+ expect(result).to match(/2000-01-01\s+foo!\s+bar!\s+#{Regexp.escape(branch.name)}/)
181
195
  end
182
196
 
183
197
  it 'returns a line containing an empty branch property' do
184
- Twig::Branch.should_receive(:all_property_names).and_return(%w[foo bar baz])
198
+ expect(Twig::Branch).to receive(:all_property_names).and_return(%w[foo bar baz])
185
199
  branch = @other_branch
186
200
 
187
201
  result = @twig.branch_list_line(branch)
188
202
 
189
203
  empty_indicator = Twig::Display::EMPTY_BRANCH_PROPERTY_INDICATOR
190
- result.should =~ /2000-01-01\s+foo!\s+bar!\s+#{empty_indicator}\s+#{Regexp.escape(branch.name)}/
204
+ expect(result).to match(/2000-01-01\s+foo!\s+bar!\s+#{empty_indicator}\s+#{Regexp.escape(branch.name)}/)
191
205
  end
192
206
 
193
207
  it 'changes line break characters to spaces' do
194
208
  branch = @current_branch
195
209
  property_names = %w[foo bar linebreaks]
196
- branch.should_receive(:get_properties).with(property_names).and_return(
210
+ expect(branch).to receive(:get_properties).with(property_names).and_return(
197
211
  'foo' => 'foo!',
198
212
  'bar' => 'bar!',
199
213
  'linebreaks' => "line\r\nbreaks!"
200
214
  )
201
- Twig::Branch.should_receive(:all_property_names).and_return(property_names)
215
+ expect(Twig::Branch).to receive(:all_property_names).and_return(property_names)
202
216
 
203
217
  result = @twig.branch_list_line(branch)
204
218
 
205
- result.should include('line breaks')
219
+ expect(result).to include('line breaks')
206
220
  end
207
221
 
208
222
  it 'returns a line with custom column widths' do
@@ -212,11 +226,12 @@ describe Twig::Display do
212
226
  result = @twig.branch_list_line(branch)
213
227
 
214
228
  column_gutter = @twig.column_gutter
215
- result.should ==
229
+ expect(result).to eq(
216
230
  '2000-01-01' + (' ' * 25) + column_gutter +
217
231
  'foo! ' + column_gutter +
218
232
  'bar!' + (' ' * 12) + column_gutter +
219
233
  ' ' + branch.name
234
+ )
220
235
  end
221
236
 
222
237
  context 'with a custom width for the branch column' do
@@ -233,11 +248,12 @@ describe Twig::Display do
233
248
  unformatted_result = @twig.unformat_string(result)
234
249
 
235
250
  column_gutter = @twig.column_gutter
236
- unformatted_result.should ==
251
+ expect(unformatted_result).to eq(
237
252
  '2000-01-01' + (' ' * 25) + column_gutter +
238
253
  'foo!' + (' ' * 12) + column_gutter +
239
254
  'bar!' + (' ' * 12) + column_gutter +
240
255
  indicator + 'my-br...'
256
+ )
241
257
  end
242
258
 
243
259
  it 'returns a line for a branch other than the current branch' do
@@ -246,67 +262,102 @@ describe Twig::Display do
246
262
  result = @twig.branch_list_line(branch)
247
263
 
248
264
  column_gutter = @twig.column_gutter
249
- result.should ==
265
+ expect(result).to eq(
250
266
  '2000-01-01' + (' ' * 25) + column_gutter +
251
267
  'foo!' + (' ' * 12) + column_gutter +
252
268
  'bar!' + (' ' * 12) + column_gutter +
253
269
  ' ' + 'other...'
270
+ )
254
271
  end
255
272
  end
256
273
  end
257
274
 
275
+ describe '#branches_json' do
276
+ before :each do
277
+ @commit_time = Twig::CommitTime.new(Time.now, '')
278
+ allow(@commit_time).to receive(:to_s).and_return('2000-01-01')
279
+ end
280
+
281
+ it 'returns JSON for an array of branches' do
282
+ branches = [
283
+ Twig::Branch.new('branch1'),
284
+ Twig::Branch.new('branch2')
285
+ ]
286
+ branch_hashes = [
287
+ { 'name' => 'branch1' },
288
+ { 'name' => 'branch2' }
289
+ ]
290
+ expect(@twig).to receive(:branches).and_return(branches)
291
+ expect(branches[0]).to receive(:to_hash).and_return(branch_hashes[0])
292
+ expect(branches[1]).to receive(:to_hash).and_return(branch_hashes[1])
293
+
294
+ result = @twig.branches_json
295
+
296
+ expect(result).to eq({ 'branches' => branch_hashes }.to_json)
297
+ end
298
+
299
+ it 'returns JSON for an empty array if there are no branches' do
300
+ expect(@twig).to receive(:branches).and_return([])
301
+ result = @twig.branches_json
302
+ expect(result).to eq({ 'branches' => [] }.to_json)
303
+ end
304
+ end
305
+
258
306
  describe '#format_string' do
259
307
  it 'returns a plain string' do
260
- @twig.format_string('foo', {}).should == 'foo'
308
+ expect(@twig.format_string('foo', {})).to eq('foo')
261
309
  end
262
310
 
263
311
  it 'returns a string with a color code' do
264
- @twig.format_string('foo', :color => :red).
265
- should == "\e[#{Twig::Display::COLORS[:red]}mfoo\e[0m"
312
+ expect(@twig.format_string('foo', :color => :red)).to eq(
313
+ "\e[#{Twig::Display::COLORS[:red]}mfoo\e[0m"
314
+ )
266
315
  end
267
316
 
268
317
  it 'returns a string with a weight code' do
269
- @twig.format_string('foo', :weight => :bold).
270
- should == "\e[#{Twig::Display::WEIGHTS[:bold]}mfoo\e[0m"
318
+ expect(@twig.format_string('foo', :weight => :bold)).to eq(
319
+ "\e[#{Twig::Display::WEIGHTS[:bold]}mfoo\e[0m"
320
+ )
271
321
  end
272
322
 
273
323
  it 'returns a string with a color and weight code 'do
274
324
  color_code = Twig::Display::COLORS[:red]
275
325
  weight_code = Twig::Display::WEIGHTS[:bold]
276
326
 
277
- @twig.format_string('foo', :color => :red, :weight => :bold).
278
- should == "\e[#{color_code};#{weight_code}mfoo\e[0m"
327
+ expect(@twig.format_string('foo', :color => :red, :weight => :bold)).to eq(
328
+ "\e[#{color_code};#{weight_code}mfoo\e[0m"
329
+ )
279
330
  end
280
331
  end
281
332
 
282
333
  describe '#unformat_string' do
283
334
  it 'unformats a plain text string' do
284
335
  string = 'foo'
285
- @twig.unformat_string(string).should == string
336
+ expect(@twig.unformat_string(string)).to eq(string)
286
337
  end
287
338
 
288
339
  it 'unformats a string with color' do
289
340
  string = 'foo'
290
341
  formatted_string = @twig.format_string(string, :color => :red)
291
- formatted_string.size.should > 3 # Precondition
342
+ expect(formatted_string.size).to be > 3
292
343
 
293
- @twig.unformat_string(formatted_string).should == string
344
+ expect(@twig.unformat_string(formatted_string)).to eq(string)
294
345
  end
295
346
 
296
347
  it 'unformats a string with weight' do
297
348
  string = 'foo'
298
349
  formatted_string = @twig.format_string(string, :weight => :bold)
299
- formatted_string.size.should > 3 # Precondition
350
+ expect(formatted_string.size).to be > 3
300
351
 
301
- @twig.unformat_string(formatted_string).should == string
352
+ expect(@twig.unformat_string(formatted_string)).to eq(string)
302
353
  end
303
354
 
304
355
  it 'unformats a string with color and weight' do
305
356
  string = 'foo'
306
357
  formatted_string = @twig.format_string(string, :color => :red, :weight => :bold)
307
- formatted_string.size.should > 3 # Precondition
358
+ expect(formatted_string.size).to be > 3
308
359
 
309
- @twig.unformat_string(formatted_string).should == string
360
+ expect(@twig.unformat_string(formatted_string)).to eq(string)
310
361
  end
311
362
  end
312
363
  end
@@ -15,67 +15,72 @@ describe Twig::GithubRepo do
15
15
 
16
16
  describe '#initialize' do
17
17
  it 'runs the given block' do
18
- Twig.stub(:repo?) { true }
19
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
20
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
21
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
18
+ origin_url = @github_ssh_read_write_url
19
+ allow(Twig).to receive(:repo?) { true }
20
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
21
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
22
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
22
23
 
23
24
  block_has_run = false
24
25
  Twig::GithubRepo.new do |gh_repo|
25
26
  block_has_run = true
26
27
  end
27
28
 
28
- block_has_run.should be_true
29
+ expect(block_has_run).to be_true
29
30
  end
30
31
 
31
32
  it 'aborts if this is not a Git repo' do
32
- Twig.stub(:repo?) { false }
33
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
34
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
35
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
36
- Twig::GithubRepo.any_instance.should_receive(:abort) do |message|
37
- message.should include('not a git repository')
33
+ origin_url = @github_ssh_read_write_url
34
+ allow(Twig).to receive(:repo?) { false }
35
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
36
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
37
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
38
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |message|
39
+ expect(message).to include('not a git repository')
38
40
  end
39
41
 
40
42
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
41
43
  end
42
44
 
43
45
  it 'aborts if the repo origin URL is empty' do
44
- Twig.stub(:repo?) { true }
45
- Twig::GithubRepo.any_instance.stub(:origin_url) { '' }
46
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
47
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
48
- Twig::GithubRepo.any_instance.should_receive(:abort_for_non_github_repo)
46
+ allow(Twig).to receive(:repo?) { true }
47
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { '' }
48
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
49
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
50
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
49
51
 
50
52
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
51
53
  end
52
54
 
53
55
  it 'aborts if the repo username is empty' do
54
- Twig.stub(:repo?) { true }
55
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
56
- Twig::GithubRepo.any_instance.stub(:username) { '' }
57
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
58
- Twig::GithubRepo.any_instance.should_receive(:abort_for_non_github_repo)
56
+ origin_url = @github_ssh_read_write_url
57
+ allow(Twig).to receive(:repo?) { true }
58
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
59
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { '' }
60
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
61
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
59
62
 
60
63
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
61
64
  end
62
65
 
63
66
  it 'aborts if the repo name is empty' do
64
- Twig.stub(:repo?) { true }
65
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
66
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
67
- Twig::GithubRepo.any_instance.stub(:repository) { '' }
68
- Twig::GithubRepo.any_instance.should_receive(:abort_for_non_github_repo)
67
+ origin_url = @github_ssh_read_write_url
68
+ allow(Twig).to receive(:repo?) { true }
69
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
70
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
71
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { '' }
72
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
69
73
 
70
74
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
71
75
  end
72
76
 
73
77
  it 'aborts if the repo is not hosted by GitHub' do
74
- Twig.stub(:repo?) { true }
75
- Twig::GithubRepo.any_instance.stub(:origin_url) { @generic_ssh_read_write_url }
76
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
77
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
78
- Twig::GithubRepo.any_instance.should_receive(:abort_for_non_github_repo)
78
+ origin_url = @generic_ssh_read_write_url
79
+ allow(Twig).to receive(:repo?) { true }
80
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
81
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
82
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
83
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
79
84
 
80
85
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
81
86
  end
@@ -83,14 +88,14 @@ describe Twig::GithubRepo do
83
88
 
84
89
  describe '#origin_url' do
85
90
  before :each do
86
- Twig.stub(:repo?) { true }
87
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
88
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
91
+ allow(Twig).to receive(:repo?) { true }
92
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
93
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
89
94
  end
90
95
 
91
96
  it 'gets the origin URL from the repo config' do
92
97
  origin_url = @github_ssh_read_write_url
93
- Twig.should_receive(:run).
98
+ expect(Twig).to receive(:run).
94
99
  with('git config remote.origin.url').once { origin_url }
95
100
 
96
101
  Twig::GithubRepo.new do |gh_repo|
@@ -101,36 +106,37 @@ describe Twig::GithubRepo do
101
106
 
102
107
  describe '#origin_url_parts' do
103
108
  before :each do
104
- Twig.stub(:repo?) { true }
105
- Twig::GithubRepo.any_instance.stub(:username) { 'username' }
106
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
109
+ allow(Twig).to receive(:repo?) { true }
110
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
111
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
107
112
  end
108
113
 
109
114
  it 'splits the origin URL into useful parts' do
110
115
  origin_url = @github_ssh_read_write_url
111
- Twig::GithubRepo.any_instance.stub(:origin_url) { origin_url }
116
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
112
117
 
113
118
  origin_url_parts = nil
114
119
  Twig::GithubRepo.new do |gh_repo|
115
120
  origin_url_parts = gh_repo.origin_url_parts
116
121
  end
117
122
 
118
- origin_url_parts.should == %w[
123
+ expect(origin_url_parts).to eq(%w[
119
124
  git@github.com
120
125
  rondevera
121
126
  twig.git
122
- ]
127
+ ])
123
128
  end
124
129
  end
125
130
 
126
131
  describe '#github_repo?' do
127
132
  before :each do
128
- Twig.stub(:repo?) { true }
133
+ allow(Twig).to receive(:repo?) { true }
129
134
  end
130
135
 
131
136
  context 'with a GitHub HTTPS URL' do
132
137
  before :each do
133
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_https_url }
138
+ origin_url = @github_https_url
139
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
134
140
  end
135
141
 
136
142
  it 'returns true' do
@@ -139,13 +145,14 @@ describe Twig::GithubRepo do
139
145
  is_github_repo = gh_repo.github_repo?
140
146
  end
141
147
 
142
- is_github_repo.should be_true
148
+ expect(is_github_repo).to be_true
143
149
  end
144
150
  end
145
151
 
146
152
  context 'with a GitHub Git read-only URL' do
147
153
  before :each do
148
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_git_read_only_url }
154
+ origin_url = @github_git_read_only_url
155
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
149
156
  end
150
157
 
151
158
  it 'returns true' do
@@ -154,13 +161,14 @@ describe Twig::GithubRepo do
154
161
  is_github_repo = gh_repo.github_repo?
155
162
  end
156
163
 
157
- is_github_repo.should be_true
164
+ expect(is_github_repo).to be_true
158
165
  end
159
166
  end
160
167
 
161
168
  context 'with a GitHub SSH read/write URL' do
162
169
  before :each do
163
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
170
+ origin_url = @github_ssh_read_write_url
171
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
164
172
  end
165
173
 
166
174
  it 'returns true' do
@@ -169,14 +177,15 @@ describe Twig::GithubRepo do
169
177
  is_github_repo = gh_repo.github_repo?
170
178
  end
171
179
 
172
- is_github_repo.should be_true
180
+ expect(is_github_repo).to be_true
173
181
  end
174
182
  end
175
183
 
176
184
  context 'with a generic HTTPS URL' do
177
185
  before :each do
178
- Twig::GithubRepo.any_instance.stub(:origin_url) { @generic_https_url }
179
- Twig::GithubRepo.any_instance.stub(:abort_for_non_github_repo)
186
+ origin_url = @generic_https_url
187
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
188
+ allow_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
180
189
  end
181
190
 
182
191
  it 'returns false' do
@@ -185,14 +194,15 @@ describe Twig::GithubRepo do
185
194
  is_github_repo = gh_repo.github_repo?
186
195
  end
187
196
 
188
- is_github_repo.should be_false
197
+ expect(is_github_repo).to be_false
189
198
  end
190
199
  end
191
200
 
192
201
  context 'with a generic Git read-only URL' do
193
202
  before :each do
194
- Twig::GithubRepo.any_instance.stub(:origin_url) { @generic_git_read_only_url }
195
- Twig::GithubRepo.any_instance.stub(:abort_for_non_github_repo)
203
+ origin_url = @generic_git_read_only_url
204
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
205
+ allow_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
196
206
  end
197
207
 
198
208
  it 'returns false' do
@@ -201,14 +211,15 @@ describe Twig::GithubRepo do
201
211
  is_github_repo = gh_repo.github_repo?
202
212
  end
203
213
 
204
- is_github_repo.should be_false
214
+ expect(is_github_repo).to be_false
205
215
  end
206
216
  end
207
217
 
208
218
  context 'with a generic SSH read/write URL' do
209
219
  before :each do
210
- Twig::GithubRepo.any_instance.stub(:origin_url) { @generic_ssh_read_write_url }
211
- Twig::GithubRepo.any_instance.stub(:abort_for_non_github_repo)
220
+ origin_url = @generic_ssh_read_write_url
221
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
222
+ allow_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
212
223
  end
213
224
 
214
225
  it 'returns false' do
@@ -217,82 +228,88 @@ describe Twig::GithubRepo do
217
228
  is_github_repo = gh_repo.github_repo?
218
229
  end
219
230
 
220
- is_github_repo.should be_false
231
+ expect(is_github_repo).to be_false
221
232
  end
222
233
  end
223
234
  end
224
235
 
225
236
  describe '#username' do
226
237
  before :each do
227
- Twig.stub(:repo?) { true }
228
- Twig::GithubRepo.any_instance.stub(:repository) { 'repository' }
238
+ allow(Twig).to receive(:repo?) { true }
239
+ allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
229
240
  end
230
241
 
231
242
  it 'gets the username for a HTTPS repo' do
232
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
243
+ origin_url = @github_ssh_read_write_url
244
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
233
245
  username = nil
234
246
  Twig::GithubRepo.new do |gh_repo|
235
247
  username = gh_repo.username
236
248
  end
237
249
 
238
- username.should == 'rondevera'
250
+ expect(username).to eq('rondevera')
239
251
  end
240
252
 
241
253
  it 'gets the username for a Git read-only repo' do
242
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_git_read_only_url }
254
+ origin_url = @github_git_read_only_url
255
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
243
256
  username = nil
244
257
  Twig::GithubRepo.new do |gh_repo|
245
258
  username = gh_repo.username
246
259
  end
247
260
 
248
- username.should == 'rondevera'
261
+ expect(username).to eq('rondevera')
249
262
  end
250
263
 
251
264
  it 'gets the username for a SSH read/write repo' do
252
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
265
+ origin_url = @github_ssh_read_write_url
266
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
253
267
  username = nil
254
268
  Twig::GithubRepo.new do |gh_repo|
255
269
  username = gh_repo.username
256
270
  end
257
271
 
258
- username.should == 'rondevera'
272
+ expect(username).to eq('rondevera')
259
273
  end
260
274
  end
261
275
 
262
276
  describe '#repository' do
263
277
  before :each do
264
- Twig.stub(:repo?) { true }
265
- Twig::GithubRepo.any_instance.stub(:username) { 'repository' }
278
+ allow(Twig).to receive(:repo?) { true }
279
+ allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'repository' }
266
280
  end
267
281
 
268
282
  it 'gets the repo name for a HTTPS repo' do
269
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_https_url }
283
+ origin_url = @github_https_url
284
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
270
285
  repository = nil
271
286
  Twig::GithubRepo.new do |gh_repo|
272
287
  repository = gh_repo.repository
273
288
  end
274
289
 
275
- repository.should == 'twig'
290
+ expect(repository).to eq('twig')
276
291
  end
277
292
 
278
293
  it 'gets the repo name for a Git read-only repo' do
279
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_git_read_only_url }
294
+ origin_url = @github_git_read_only_url
295
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
280
296
  repository = nil
281
297
  Twig::GithubRepo.new do |gh_repo|
282
298
  repository = gh_repo.repository
283
299
  end
284
300
 
285
- repository.should == 'twig'
301
+ expect(repository).to eq('twig')
286
302
  end
287
303
 
288
304
  it 'gets the repo name for a SSH read/write repo' do
289
- Twig::GithubRepo.any_instance.stub(:origin_url) { @github_ssh_read_write_url }
305
+ origin_url = @github_ssh_read_write_url
306
+ allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
290
307
  repository = nil
291
308
  Twig::GithubRepo.new do |gh_repo|
292
309
  repository = gh_repo.repository
293
310
  end
294
311
 
295
- repository.should == 'twig'
312
+ expect(repository).to eq('twig')
296
313
  end
297
314
  end
298
315