twig 1.4 → 1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
1
  class Twig
2
+
3
+ # Stores a branch's last commit time and its relative time representation.
2
4
  class CommitTime
3
5
 
4
6
  def initialize(time, time_ago)
@@ -13,6 +15,10 @@ class Twig
13
15
  sub(' hours', 'h').
14
16
  sub(' minutes', 'm').
15
17
  sub(' seconds', 's')
18
+
19
+ # Keep only the most significant units in the relative time
20
+ time_ago_parts = @time_ago.split(/\s+/)
21
+ @time_ago = "#{time_ago_parts[0]} #{time_ago_parts[-1]}".gsub(/,/, '')
16
22
  end
17
23
 
18
24
  def to_i
@@ -24,6 +30,10 @@ class Twig
24
30
  "#{time_string} (#{@time_ago})"
25
31
  end
26
32
 
33
+ def iso8601
34
+ @time.iso8601
35
+ end
36
+
27
37
  def <=>(other)
28
38
  to_i <=> other.to_i
29
39
  end
@@ -137,6 +137,15 @@ class Twig
137
137
  line
138
138
  end
139
139
 
140
+ def branches_json
141
+ require 'json'
142
+
143
+ data = {
144
+ 'branches' => branches.map { |branch| branch.to_hash }
145
+ }
146
+ data.to_json
147
+ end
148
+
140
149
  def format_string(string, options)
141
150
  # Options:
142
151
  # - `:color`: `nil` by default. Accepts a key from `COLORS`.
@@ -5,61 +5,96 @@ class Twig
5
5
  DEPRECATED_CONFIG_PATH = '~/.twigrc'
6
6
  MIN_PROPERTY_WIDTH = 3
7
7
 
8
- def read_config_file!
9
- config_path = File.expand_path(Twig::CONFIG_PATH)
10
- unless File.readable?(config_path)
11
- config_path = File.expand_path(Twig::DEPRECATED_CONFIG_PATH)
12
- if File.readable?(config_path)
13
- $stderr.puts "DEPRECATED: #{DEPRECATED_CONFIG_PATH} is deprecated. " <<
14
- "Please rename it to #{CONFIG_PATH}."
8
+ def readable_config_file_path
9
+ config_path = File.expand_path(CONFIG_PATH)
10
+
11
+ if File.exists?(config_path)
12
+ unless File.readable?(config_path)
13
+ $stderr.puts "Warning: #{CONFIG_PATH} is not readable."
14
+ return # Stop if file exists but is not readable
15
+ end
16
+ else
17
+ config_path = File.expand_path(DEPRECATED_CONFIG_PATH)
18
+
19
+ if File.exists?(config_path)
20
+ if File.readable?(config_path)
21
+ $stderr.puts "DEPRECATED: #{DEPRECATED_CONFIG_PATH} is deprecated. " <<
22
+ "Please rename it to #{CONFIG_PATH}."
23
+ else
24
+ $stderr.puts "DEPRECATED: #{DEPRECATED_CONFIG_PATH} is deprecated. " <<
25
+ "Please rename it to #{CONFIG_PATH} and make it readable."
26
+ return # Stop if file exists but is not readable
27
+ end
15
28
  else
16
- return
29
+ return # Stop if neither file exists
17
30
  end
18
31
  end
19
32
 
33
+ config_path
34
+ end
35
+
36
+ def parse_config_file(config_path)
37
+ lines = []
38
+
20
39
  File.open(config_path) do |file|
21
- opts = file.read.split("\n").inject({}) do |hsh, line|
22
- line = line.strip
40
+ lines = file.read.split("\n")
41
+ end
23
42
 
24
- if line !~ /^#/
25
- key, value = line.split(':', 2)
26
- hsh[key.strip] = value.strip if key && value
27
- end
43
+ lines.inject({}) do |opts, line|
44
+ line = line.strip
45
+ next opts if line =~ /^#/
46
+
47
+ key, value = line.split(':', 2)
48
+ key = key ? key.strip : ''
28
49
 
29
- hsh
50
+ if !key.empty? && value
51
+ opts[key] = value.strip
52
+ elsif !line.empty?
53
+ $stderr.puts %{Warning: Invalid line "#{line}" in #{config_path}. } <<
54
+ %{Expected format: `key: value`}
30
55
  end
31
56
 
32
- opts.each do |key, value|
33
- case key
34
-
35
- # Filtering branches:
36
- when 'branch'
37
- set_option(:branch, value)
38
- when 'max-days-old'
39
- set_option(:max_days_old, value)
40
- when /^except-/
41
- property_name = key.sub(/^except-/, '').to_sym
42
- set_option(:property_except, property_name => value)
43
- when /^only-/
44
- property_name = key.sub(/^only-/, '').to_sym
45
- set_option(:property_only, property_name => value)
46
-
47
- # Displaying branches:
48
- when 'header-style'
49
- set_option(:header_style, value)
50
- when 'reverse'
51
- set_option(:reverse, value)
52
- when /-width$/
53
- property_name = key.sub(/-width$/, '').to_sym
54
- set_option(:property_width, property_name => value)
55
-
56
- # GitHub integration:
57
- when 'github-api-uri-prefix'
58
- set_option(:github_api_uri_prefix, value)
59
- when 'github-uri-prefix'
60
- set_option(:github_uri_prefix, value)
57
+ opts
58
+ end
59
+ end
60
+
61
+ def read_config_file!
62
+ config_path = readable_config_file_path
63
+ return unless config_path
64
+
65
+ options = parse_config_file(config_path)
66
+ options.each do |key, value|
67
+ case key
68
+
69
+ # Filtering branches:
70
+ when 'branch'
71
+ set_option(:branch, value)
72
+ when 'max-days-old'
73
+ set_option(:max_days_old, value)
74
+ when /^except-/
75
+ property_name = key.sub(/^except-/, '').to_sym
76
+ set_option(:property_except, property_name => value)
77
+ when /^only-/
78
+ property_name = key.sub(/^only-/, '').to_sym
79
+ set_option(:property_only, property_name => value)
80
+
81
+ # Displaying branches:
82
+ when 'format'
83
+ set_option(:format, value)
84
+ when 'header-style'
85
+ set_option(:header_style, value)
86
+ when 'reverse'
87
+ set_option(:reverse, value)
88
+ when /-width$/
89
+ property_name = key.sub(/-width$/, '').to_sym
90
+ set_option(:property_width, property_name => value)
91
+
92
+ # GitHub integration:
93
+ when 'github-api-uri-prefix'
94
+ set_option(:github_api_uri_prefix, value)
95
+ when 'github-uri-prefix'
96
+ set_option(:github_uri_prefix, value)
61
97
 
62
- end
63
98
  end
64
99
  end
65
100
  end
@@ -70,7 +105,14 @@ class Twig
70
105
  if all_branch_names.include?(value)
71
106
  options[:branch] = value
72
107
  else
73
- abort %{The branch "#{value}" could not be found.}
108
+ abort %{The branch `#{value}` could not be found.}
109
+ end
110
+
111
+ when :format
112
+ if value == 'json'
113
+ options[:format] = value.to_sym
114
+ else
115
+ abort %{The format `#{value}` is not supported; only `json` is supported.}
74
116
  end
75
117
 
76
118
  when :github_api_uri_prefix, :github_uri_prefix
@@ -0,0 +1,26 @@
1
+ class Twig
2
+ module Subcommands
3
+
4
+ BIN_PREFIX = 'twig-'
5
+
6
+ def self.all_names
7
+ bin_paths = []
8
+
9
+ bin_dir_paths.each do |bin_dir_path|
10
+ path_pattern = File.join(bin_dir_path, BIN_PREFIX + '*')
11
+ Dir.glob(path_pattern) do |bin_path|
12
+ bin_paths << File.basename(bin_path)
13
+ end
14
+ end
15
+
16
+ bin_paths.uniq.sort.map do |bin_path|
17
+ bin_path.sub(Regexp.new('^' << BIN_PREFIX), '')
18
+ end
19
+ end
20
+
21
+ def self.bin_dir_paths
22
+ ENV['PATH'].split(':')
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ class Twig
2
+ module System
3
+
4
+ def self.windows?
5
+ RbConfig::CONFIG['host_os'] =~ /(cygwin|mingw|windows|win32)/
6
+ end
7
+
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  class Twig
2
- VERSION = '1.4'
2
+ VERSION = '1.5'
3
3
  end
@@ -1 +1,8 @@
1
1
  require 'twig'
2
+ require 'json'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |c|
6
+ c.syntax = :expect
7
+ end
8
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Twig::Branch do
@@ -27,37 +28,37 @@ describe Twig::Branch do
27
28
  end
28
29
 
29
30
  it 'returns the union of properties for all branches' do
30
- Twig.should_receive(:run).with('git config --list').and_return(@config)
31
+ expect(Twig).to receive(:run).with('git config --list').and_return(@config)
31
32
 
32
33
  result = Twig::Branch.all_property_names
33
- result.should == %w[test0 test1 test2]
34
+ expect(result).to eq(%w[test0 test1 test2])
34
35
  end
35
36
 
36
37
  it 'handles branch names that contain dots' do
37
38
  @config << 'branch.dot1.dot2.dot3.dotproperty=dotvalue'
38
- Twig.should_receive(:run).with('git config --list').and_return(@config)
39
+ expect(Twig).to receive(:run).with('git config --list').and_return(@config)
39
40
 
40
41
  result = Twig::Branch.all_property_names
41
- result.should == %w[dotproperty test0 test1 test2]
42
+ expect(result).to eq(%w[dotproperty test0 test1 test2])
42
43
  end
43
44
 
44
45
  it 'handles branch names that contain equal signs' do
45
46
  @config << 'branch.eq1=eq2=eq3.eqproperty=eqvalue'
46
- Twig.should_receive(:run).with('git config --list').and_return(@config)
47
+ expect(Twig).to receive(:run).with('git config --list').and_return(@config)
47
48
 
48
49
  result = Twig::Branch.all_property_names
49
- result.should == %w[eqproperty test0 test1 test2]
50
+ expect(result).to eq(%w[eqproperty test0 test1 test2])
50
51
  end
51
52
 
52
53
  it 'skips path values with an equal sign but no value' do
53
54
  @config << 'foo_path='
54
- Twig.should_receive(:run).with('git config --list').and_return(@config)
55
+ expect(Twig).to receive(:run).with('git config --list').and_return(@config)
55
56
  result = Twig::Branch.all_property_names
56
- result.should_not include 'foo_path'
57
+ expect(result).not_to include('foo_path')
57
58
  end
58
59
 
59
60
  it 'memoizes the result' do
60
- Twig.should_receive(:run).once.and_return(@config)
61
+ expect(Twig).to receive(:run).once.and_return(@config)
61
62
  2.times { Twig::Branch.all_property_names }
62
63
  end
63
64
  end
@@ -65,24 +66,65 @@ describe Twig::Branch do
65
66
  describe '#initialize' do
66
67
  it 'requires a name' do
67
68
  branch = Twig::Branch.new('test')
68
- branch.name.should == 'test'
69
+ expect(branch.name).to eq('test')
69
70
 
70
- lambda { Twig::Branch.new }.should raise_exception
71
- lambda { Twig::Branch.new(nil) }.should raise_exception
72
- lambda { Twig::Branch.new('') }.should raise_exception
71
+ expect { Twig::Branch.new }.to raise_exception
72
+ expect { Twig::Branch.new(nil) }.to raise_exception
73
+ expect { Twig::Branch.new('') }.to raise_exception
73
74
  end
74
75
 
75
76
  it 'accepts a last commit time' do
76
77
  commit_time = Twig::CommitTime.new(Time.now, '99 days ago')
77
78
  branch = Twig::Branch.new('test', :last_commit_time => commit_time)
78
- branch.last_commit_time.should == commit_time
79
+ expect(branch.last_commit_time).to eq(commit_time)
79
80
  end
80
81
  end
81
82
 
82
83
  describe '#to_s' do
83
84
  it 'returns the branch name' do
84
85
  branch = Twig::Branch.new('test')
85
- branch.to_s.should == 'test'
86
+ expect(branch.to_s).to eq('test')
87
+ end
88
+ end
89
+
90
+ describe '#to_hash' do
91
+ before :each do
92
+ @branch = Twig::Branch.new('test')
93
+ time = Time.parse('2000-01-01 18:30 UTC')
94
+ commit_time = Twig::CommitTime.new(time, '')
95
+ @time_string = time.iso8601
96
+ allow(@branch).to receive(:last_commit_time) { commit_time }
97
+ end
98
+
99
+ it 'returns the hash for a branch with properties' do
100
+ expect(Twig::Branch).to receive(:all_property_names) { %w[foo bar] }
101
+ expect(@branch).to receive(:get_properties) do
102
+ { 'foo' => 'foo!', 'bar' => 'bar!' }
103
+ end
104
+
105
+ result = @branch.to_hash
106
+
107
+ expect(result).to eq(
108
+ 'name' => 'test',
109
+ 'last-commit-time' => @time_string,
110
+ 'properties' => {
111
+ 'foo' => 'foo!',
112
+ 'bar' => 'bar!'
113
+ }
114
+ )
115
+ end
116
+
117
+ it 'returns the hash for a branch with no properties' do
118
+ expect(Twig::Branch).to receive(:all_property_names) { %w[foo bar] }
119
+ expect(@branch).to receive(:get_properties).and_return({})
120
+
121
+ result = @branch.to_hash
122
+
123
+ expect(result).to eq(
124
+ 'name' => 'test',
125
+ 'last-commit-time' => @time_string,
126
+ 'properties' => {}
127
+ )
86
128
  end
87
129
  end
88
130
 
@@ -92,11 +134,23 @@ describe Twig::Branch do
92
134
  end
93
135
 
94
136
  it 'removes whitespace from branch property names' do
95
- @branch.sanitize_property(' foo bar ').should == 'foobar'
137
+ expect(@branch.sanitize_property(' foo bar ')).to eq('foobar')
96
138
  end
97
139
 
98
140
  it 'removes underscores from branch property names' do
99
- @branch.sanitize_property('__foo_bar__').should == 'foobar'
141
+ expect(@branch.sanitize_property('__foo_bar__')).to eq('foobar')
142
+ end
143
+ end
144
+
145
+ describe '#escaped_property_names' do
146
+ before :each do
147
+ @branch = Twig::Branch.new('test')
148
+ end
149
+
150
+ it 'converts an array of property names into an array of regexps' do
151
+ property_names = %w[test.1 test.2]
152
+ result = @branch.escaped_property_names(property_names)
153
+ expect(result).to eq(%w[test\\.1 test\\.2])
100
154
  end
101
155
  end
102
156
 
@@ -114,29 +168,41 @@ describe Twig::Branch do
114
168
  "branch.#{@branch}.test1 value1",
115
169
  "branch.#{@branch}.test2 value2"
116
170
  ].join("\n")
117
- Twig.should_receive(:run).
171
+ expect(Twig).to receive(:run).
118
172
  with(%{git config --get-regexp "branch.#{@branch}.(test1|test2)$"}).
119
173
  and_return(git_result)
120
174
 
121
175
  result = @branch.get_properties(%w[test1 test2])
122
- result.should == properties
176
+ expect(result).to eq(properties)
177
+ end
178
+
179
+ it 'returns properties for a branch with UTF-8 characters in its name' do
180
+ branch = Twig::Branch.new('utf8_{・ิω・ิ}')
181
+ properties = { 'test1' => 'value1' }
182
+ git_result = "branch.#{branch}.test1 value1"
183
+ expect(Twig).to receive(:run).
184
+ with(%{git config --get-regexp "branch.#{branch}.(test1)$"}).
185
+ and_return(git_result)
186
+
187
+ result = branch.get_properties(%w[test1])
188
+ expect(result).to eq(properties)
123
189
  end
124
190
 
125
191
  it 'returns an empty hash if no property names are given' do
126
- Twig.should_not_receive(:run)
192
+ expect(Twig).not_to receive(:run)
127
193
 
128
194
  result = @branch.get_properties([])
129
- result.should == {}
195
+ expect(result).to eq({})
130
196
  end
131
197
 
132
198
  it 'returns an empty hash if no matching property names are found' do
133
199
  git_result = ''
134
- Twig.should_receive(:run).
200
+ expect(Twig).to receive(:run).
135
201
  with(%{git config --get-regexp "branch.#{@branch}.(test1|test2)$"}).
136
202
  and_return(git_result)
137
203
 
138
204
  result = @branch.get_properties(%w[test1 test2])
139
- result.should == {}
205
+ expect(result).to eq({})
140
206
  end
141
207
 
142
208
  it 'removes whitespace from property names' do
@@ -145,12 +211,12 @@ describe Twig::Branch do
145
211
  property_value = 'bar'
146
212
  properties = { property_name => property_value }
147
213
  git_result = "branch.#{@branch}.#{property_name} #{property_value}"
148
- Twig.should_receive(:run).
214
+ expect(Twig).to receive(:run).
149
215
  with(%{git config --get-regexp "branch.#{@branch}.(#{property_name})$"}).
150
216
  and_return(git_result)
151
217
 
152
218
  result = @branch.get_properties([bad_property_name])
153
- result.should == properties
219
+ expect(result).to eq(properties)
154
220
  end
155
221
 
156
222
  it 'excludes properties whose values are empty strings' do
@@ -158,17 +224,17 @@ describe Twig::Branch do
158
224
  "branch.#{@branch}.test1 value1",
159
225
  "branch.#{@branch}.test2"
160
226
  ].join("\n")
161
- Twig.should_receive(:run).
227
+ expect(Twig).to receive(:run).
162
228
  with(%{git config --get-regexp "branch.#{@branch}.(test1|test2)$"}).
163
229
  and_return(git_result)
164
230
 
165
231
  result = @branch.get_properties(%w[test1 test2])
166
- result.should == { 'test1' => 'value1' }
232
+ expect(result).to eq('test1' => 'value1')
167
233
  end
168
234
 
169
235
  it 'raises an error if any property name is an empty string' do
170
236
  property_name = ' '
171
- Twig.should_not_receive(:run)
237
+ expect(Twig).not_to receive(:run)
172
238
 
173
239
  begin
174
240
  @branch.get_properties(['test1', property_name])
@@ -176,7 +242,9 @@ describe Twig::Branch do
176
242
  expected_exception = exception
177
243
  end
178
244
 
179
- expected_exception.message.should == Twig::Branch::EMPTY_PROPERTY_NAME_ERROR
245
+ expect(expected_exception.message).to eq(
246
+ Twig::Branch::EMPTY_PROPERTY_NAME_ERROR
247
+ )
180
248
  end
181
249
  end
182
250
 
@@ -188,24 +256,24 @@ describe Twig::Branch do
188
256
  it 'returns a property value' do
189
257
  property = 'test'
190
258
  value = 'value'
191
- @branch.should_receive(:get_properties).
259
+ expect(@branch).to receive(:get_properties).
192
260
  with([property]).
193
261
  and_return(property => value)
194
262
 
195
263
  result = @branch.get_property(property)
196
- result.should == value
264
+ expect(result).to eq(value)
197
265
  end
198
266
 
199
267
  it 'removes whitespace from branch property names' do
200
268
  bad_property = ' foo foo '
201
269
  property = 'foofoo'
202
270
  value = 'bar'
203
- @branch.should_receive(:get_properties).
271
+ expect(@branch).to receive(:get_properties).
204
272
  with([property]).
205
273
  and_return(property => value)
206
274
 
207
275
  result = @branch.get_property(bad_property)
208
- result.should == value
276
+ expect(result).to eq(value)
209
277
  end
210
278
  end
211
279
 
@@ -217,13 +285,13 @@ describe Twig::Branch do
217
285
  it 'sets a property value' do
218
286
  property = 'test'
219
287
  value = 'value'
220
- Twig.should_receive(:run).
288
+ expect(Twig).to receive(:run).
221
289
  with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
222
290
  `(exit 0)`; value # Set `$?` to `0`
223
291
  end
224
292
 
225
293
  result = @branch.set_property(property, value)
226
- result.should include(
294
+ expect(result).to include(
227
295
  %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
228
296
  )
229
297
  end
@@ -231,7 +299,7 @@ describe Twig::Branch do
231
299
  it 'raises an error if Git cannot set the property value' do
232
300
  property = 'test'
233
301
  value = 'value'
234
- Twig.stub(:run) { `(exit 1)`; value } # Set `$?` to `1`
302
+ allow(Twig).to receive(:run) { `(exit 1)`; value } # Set `$?` to `1`
235
303
 
236
304
  begin
237
305
  @branch.set_property(property, value)
@@ -239,7 +307,7 @@ describe Twig::Branch do
239
307
  expected_exception = exception
240
308
  end
241
309
 
242
- expected_exception.message.should include(
310
+ expect(expected_exception.message).to include(
243
311
  %{Could not save property "#{property}" as "#{value}" for branch "#{@branch}"}
244
312
  )
245
313
  end
@@ -247,7 +315,7 @@ describe Twig::Branch do
247
315
  it 'raises an error if the property name is an empty string' do
248
316
  property = ' '
249
317
  value = 'value'
250
- Twig.should_not_receive(:run)
318
+ expect(Twig).not_to receive(:run)
251
319
 
252
320
  begin
253
321
  @branch.set_property(property, value)
@@ -255,13 +323,15 @@ describe Twig::Branch do
255
323
  expected_exception = exception
256
324
  end
257
325
 
258
- expected_exception.message.should == Twig::Branch::EMPTY_PROPERTY_NAME_ERROR
326
+ expect(expected_exception.message).to eq(
327
+ Twig::Branch::EMPTY_PROPERTY_NAME_ERROR
328
+ )
259
329
  end
260
330
 
261
331
  it 'raises an error if trying to set a reserved branch property' do
262
332
  property = 'merge'
263
333
  value = 'NOOO'
264
- Twig.should_not_receive(:run)
334
+ expect(Twig).not_to receive(:run)
265
335
 
266
336
  begin
267
337
  @branch.set_property(property, value)
@@ -269,7 +339,7 @@ describe Twig::Branch do
269
339
  expected_exception = exception
270
340
  end
271
341
 
272
- expected_exception.message.should include(
342
+ expect(expected_exception.message).to include(
273
343
  %{Can't modify the reserved property "#{property}"}
274
344
  )
275
345
  end
@@ -277,7 +347,7 @@ describe Twig::Branch do
277
347
  it 'raises an error if trying to set a branch property to an empty string' do
278
348
  property = 'test'
279
349
  value = ''
280
- Twig.should_not_receive(:run)
350
+ expect(Twig).not_to receive(:run)
281
351
 
282
352
  begin
283
353
  @branch.set_property(property, value)
@@ -285,7 +355,7 @@ describe Twig::Branch do
285
355
  expected_exception = exception
286
356
  end
287
357
 
288
- expected_exception.message.should include(
358
+ expect(expected_exception.message).to include(
289
359
  %{Can't set a branch property to an empty string}
290
360
  )
291
361
  end
@@ -294,13 +364,13 @@ describe Twig::Branch do
294
364
  bad_property = ' foo foo '
295
365
  property = 'foofoo'
296
366
  value = 'bar'
297
- Twig.should_receive(:run).
367
+ expect(Twig).to receive(:run).
298
368
  with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
299
369
  `(exit 0)`; value # Set `$?` to `0`
300
370
  end
301
371
 
302
372
  result = @branch.set_property(bad_property, value)
303
- result.should include(
373
+ expect(result).to include(
304
374
  %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
305
375
  )
306
376
  end
@@ -309,13 +379,13 @@ describe Twig::Branch do
309
379
  bad_property = 'foo_foo'
310
380
  property = 'foofoo'
311
381
  value = 'bar'
312
- Twig.should_receive(:run).
382
+ expect(Twig).to receive(:run).
313
383
  with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
314
384
  `(exit 0)`; value # Set `$?` to `0`
315
385
  end
316
386
 
317
387
  result = @branch.set_property(bad_property, value)
318
- result.should include(
388
+ expect(result).to include(
319
389
  %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
320
390
  )
321
391
  end
@@ -324,13 +394,13 @@ describe Twig::Branch do
324
394
  property = 'test'
325
395
  bad_value = ' foo '
326
396
  value = 'foo'
327
- Twig.should_receive(:run).
397
+ expect(Twig).to receive(:run).
328
398
  with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
329
399
  `(exit 0)`; value # Set `$?` to `0`
330
400
  end
331
401
 
332
402
  result = @branch.set_property(property, bad_value)
333
- result.should include(
403
+ expect(result).to include(
334
404
  %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
335
405
  )
336
406
  end
@@ -343,12 +413,13 @@ describe Twig::Branch do
343
413
 
344
414
  it 'unsets a branch property' do
345
415
  property = 'test'
346
- @branch.should_receive(:get_property).with(property).and_return('value')
347
- Twig.should_receive(:run).
416
+ expect(@branch).to receive(:get_property).
417
+ with(property).and_return('value')
418
+ expect(Twig).to receive(:run).
348
419
  with(%{git config --unset branch.#{@branch}.#{property}})
349
420
 
350
421
  result = @branch.unset_property(property)
351
- result.should include(
422
+ expect(result).to include(
352
423
  %{Removed property "#{property}" for branch "#{@branch}"}
353
424
  )
354
425
  end
@@ -356,12 +427,13 @@ describe Twig::Branch do
356
427
  it 'removes whitespace from branch property names' do
357
428
  bad_property = ' foo foo '
358
429
  property = 'foofoo'
359
- @branch.should_receive(:get_property).with(property).and_return('value')
360
- Twig.should_receive(:run).
430
+ expect(@branch).to receive(:get_property).
431
+ with(property).and_return('value')
432
+ expect(Twig).to receive(:run).
361
433
  with(%{git config --unset branch.#{@branch}.#{property}})
362
434
 
363
435
  result = @branch.unset_property(bad_property)
364
- result.should include(
436
+ expect(result).to include(
365
437
  %{Removed property "#{property}" for branch "#{@branch}"}
366
438
  )
367
439
  end
@@ -369,8 +441,8 @@ describe Twig::Branch do
369
441
  it 'raises an error if the property name is an empty string' do
370
442
  bad_property = ' '
371
443
  property = ''
372
- @branch.should_not_receive(:get_property)
373
- Twig.should_not_receive(:run)
444
+ expect(@branch).not_to receive(:get_property)
445
+ expect(Twig).not_to receive(:run)
374
446
 
375
447
  begin
376
448
  @branch.unset_property(bad_property)
@@ -378,12 +450,14 @@ describe Twig::Branch do
378
450
  expected_exception = exception
379
451
  end
380
452
 
381
- expected_exception.message.should == Twig::Branch::EMPTY_PROPERTY_NAME_ERROR
453
+ expect(expected_exception.message).to eq(
454
+ Twig::Branch::EMPTY_PROPERTY_NAME_ERROR
455
+ )
382
456
  end
383
457
 
384
458
  it 'raises an error if the branch does not have the given property' do
385
459
  property = 'test'
386
- @branch.should_receive(:get_property).with(property).and_return(nil)
460
+ expect(@branch).to receive(:get_property).with(property).and_return(nil)
387
461
 
388
462
  begin
389
463
  @branch.unset_property(property)
@@ -391,7 +465,7 @@ describe Twig::Branch do
391
465
  expected_exception = exception
392
466
  end
393
467
 
394
- expected_exception.message.should include(
468
+ expect(expected_exception.message).to include(
395
469
  %{The branch "#{@branch}" does not have the property "#{property}"}
396
470
  )
397
471
  end