twig 1.0.0

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.
@@ -0,0 +1,232 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twig::Branch do
4
+ before :each do
5
+ @twig = Twig.new
6
+ end
7
+
8
+ describe '.all_properties' do
9
+ before :each do
10
+ Twig::Branch.instance_variable_set(:@_all_properties, nil)
11
+ @config = %{
12
+ user.name=Ron DeVera
13
+ branch.autosetupmerge=always
14
+ remote.origin.url=git@github.com:rondevera/twig.git
15
+ remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
16
+ branch.master.remote=origin
17
+ branch.master.merge=refs/heads/master
18
+ branch.master.test0=value0
19
+ branch.test_branch_1.remote=origin
20
+ branch.test_branch_1.merge=refs/heads/test_branch_1
21
+ branch.test_branch_1.test0=value1
22
+ branch.test_branch_1.test1=value1
23
+ branch.test_branch_2.remote=origin
24
+ branch.test_branch_2.merge=refs/heads/test_branch_2
25
+ branch.test_branch_2.test2=value2
26
+ }.gsub(/^\s+/, '')
27
+ end
28
+
29
+ it 'returns the union of properties for all branches' do
30
+ Twig.should_receive(:run).with('git config --list').and_return(@config)
31
+
32
+ result = Twig::Branch.all_properties
33
+ result.should == %w[test0 test1 test2]
34
+ end
35
+
36
+ it 'handles branch names that contain dots' do
37
+ @config << 'branch.dot1.dot2.dot3.dotproperty=dotvalue'
38
+ Twig.should_receive(:run).with('git config --list').and_return(@config)
39
+
40
+ result = Twig::Branch.all_properties
41
+ result.should == %w[dotproperty test0 test1 test2]
42
+ end
43
+
44
+ it 'handles branch names that contain equal signs' do
45
+ @config << 'branch.eq1=eq2=eq3.eqproperty=eqvalue'
46
+ Twig.should_receive(:run).with('git config --list').and_return(@config)
47
+
48
+ result = Twig::Branch.all_properties
49
+ result.should == %w[eqproperty test0 test1 test2]
50
+ end
51
+
52
+ it 'memoizes the result' do
53
+ Twig.should_receive(:run).once.and_return(@config)
54
+ 2.times { Twig::Branch.all_properties }
55
+ end
56
+ end
57
+
58
+ describe '#initialize' do
59
+ it 'requires a name' do
60
+ branch = Twig::Branch.new('test')
61
+ branch.name.should == 'test'
62
+
63
+ lambda { Twig::Branch.new }.should raise_exception
64
+ lambda { Twig::Branch.new(nil) }.should raise_exception
65
+ lambda { Twig::Branch.new('') }.should raise_exception
66
+ end
67
+
68
+ it 'accepts a last commit time' do
69
+ commit_time = Twig::CommitTime.new(Time.now, '99 days ago')
70
+ branch = Twig::Branch.new('test', :last_commit_time => commit_time)
71
+ branch.last_commit_time.should == commit_time
72
+ end
73
+ end
74
+
75
+ describe '#to_s' do
76
+ it 'returns the branch name' do
77
+ branch = Twig::Branch.new('test')
78
+ branch.to_s.should == 'test'
79
+ end
80
+ end
81
+
82
+ describe '#sanitize_property' do
83
+ before :each do
84
+ @branch = Twig::Branch.new('test')
85
+ end
86
+
87
+ it 'removes whitespace from branch property names' do
88
+ @branch.sanitize_property(' foo bar ').should == 'foobar'
89
+ end
90
+
91
+ it 'removes underscores from branch property names' do
92
+ @branch.sanitize_property('__foo_bar__').should == 'foobar'
93
+ end
94
+ end
95
+
96
+ describe '#get_property' do
97
+ it 'returns a property value' do
98
+ branch = Twig::Branch.new('test')
99
+ property = 'test'
100
+ value = 'value'
101
+ Twig.should_receive(:run).
102
+ with(%{git config branch.#{branch}.#{property}}).
103
+ and_return(value)
104
+
105
+ result = branch.get_property(property)
106
+ result.should == value
107
+ end
108
+ end
109
+
110
+ describe '#set_property' do
111
+ before :each do
112
+ @branch = Twig::Branch.new('test')
113
+ end
114
+
115
+ it 'sets a property value' do
116
+ property = 'test'
117
+ value = 'value'
118
+ Twig.should_receive(:run).
119
+ with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
120
+ `(exit 0)`; value # Set `$?` to `0`
121
+ end
122
+
123
+ result = @branch.set_property(property, value)
124
+ result.should include(
125
+ %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
126
+ )
127
+ end
128
+
129
+ it 'does nothing if Git cannot set the property value' do
130
+ property = 'test'
131
+ value = 'value'
132
+ Twig.stub(:run) { `(exit 1)`; value } # Set `$?` to `1`
133
+
134
+ result = @branch.set_property(property, value)
135
+ result.should include(
136
+ %{Could not save property "#{property}" as "#{value}" for branch "#{@branch}"}
137
+ )
138
+ end
139
+
140
+ it 'returns an error if trying to set a reserved branch property' do
141
+ property = 'merge'
142
+ value = 'NOOO'
143
+ Twig.should_not_receive(:run)
144
+
145
+ result = @branch.set_property(property, value)
146
+ result.should include(%{Can't modify the reserved property "#{property}"})
147
+ end
148
+
149
+ it 'returns an error if trying to set a branch property to an empty string' do
150
+ property = 'test'
151
+ value = ''
152
+ Twig.should_not_receive(:run)
153
+
154
+ result = @branch.set_property(property, value)
155
+ result.should include(%{Can't set a branch property to an empty string})
156
+ end
157
+
158
+ it 'removes whitespace from branch property names' do
159
+ bad_property = ' foo foo '
160
+ property = 'foofoo'
161
+ value = 'bar'
162
+ Twig.should_receive(:run).
163
+ with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
164
+ `(exit 0)`; value # Set `$?` to `0`
165
+ end
166
+
167
+ result = @branch.set_property(bad_property, value)
168
+ result.should include(
169
+ %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
170
+ )
171
+ end
172
+
173
+ it 'removes underscores from branch property names' do
174
+ bad_property = 'foo_foo'
175
+ property = 'foofoo'
176
+ value = 'bar'
177
+ Twig.should_receive(:run).
178
+ with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
179
+ `(exit 0)`; value # Set `$?` to `0`
180
+ end
181
+
182
+ result = @branch.set_property(bad_property, value)
183
+ result.should include(
184
+ %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
185
+ )
186
+ end
187
+
188
+ it 'strips whitespace from a value before setting it as a property' do
189
+ property = 'test'
190
+ bad_value = ' foo '
191
+ value = 'foo'
192
+ Twig.should_receive(:run).
193
+ with(%{git config branch.#{@branch}.#{property} "#{value}"}) do
194
+ `(exit 0)`; value # Set `$?` to `0`
195
+ end
196
+
197
+ result = @branch.set_property(property, bad_value)
198
+ result.should include(
199
+ %{Saved property "#{property}" as "#{value}" for branch "#{@branch}"}
200
+ )
201
+ end
202
+ end
203
+
204
+ describe '#unset_property' do
205
+ before :each do
206
+ @branch = Twig::Branch.new('test')
207
+ end
208
+
209
+ it 'unsets a branch property' do
210
+ property = 'test'
211
+ @branch.should_receive(:get_property).with(property).and_return('value')
212
+ Twig.should_receive(:run).
213
+ with(%{git config --unset branch.#{@branch}.#{property}})
214
+
215
+ result = @branch.unset_property(property)
216
+ result.should include(
217
+ %{Removed property "#{property}" for branch "#{@branch}"}
218
+ )
219
+ end
220
+
221
+ it 'returns an error if the branch does not have the given property' do
222
+ property = 'test'
223
+ @branch.should_receive(:get_property).with(property).and_return('')
224
+
225
+ result = @branch.unset_property(property)
226
+ result.should include(
227
+ %{The branch "#{@branch}" does not have the property "#{property}"}
228
+ )
229
+ end
230
+ end
231
+
232
+ end
@@ -0,0 +1,291 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twig::Cli do
4
+
5
+ describe '#help_description' do
6
+ before :each do
7
+ @twig = Twig.new
8
+ end
9
+
10
+ it 'returns short text in a single line' do
11
+ text = 'The quick brown fox.'
12
+ result = @twig.help_description(text, :width => 80)
13
+ result.should == [text]
14
+ end
15
+
16
+ it 'returns long text in a string with line breaks' do
17
+ text = 'The quick brown fox jumps over the lazy, lazy dog.'
18
+ result = @twig.help_description(text, :width => 20)
19
+ result.should == [
20
+ 'The quick brown fox',
21
+ 'jumps over the lazy,',
22
+ 'lazy dog.'
23
+ ]
24
+ end
25
+
26
+ it 'breaks a long word by max line length' do
27
+ text = 'Thequickbrownfoxjumpsoverthelazydog.'
28
+ result = @twig.help_description(text, :width => 20)
29
+ result.should == [
30
+ 'Thequickbrownfoxjump',
31
+ 'soverthelazydog.'
32
+ ]
33
+ end
34
+
35
+ it 'adds a separator line' do
36
+ text = 'The quick brown fox.'
37
+ result = @twig.help_description(text, :width => 80, :add_separator => true)
38
+ result.should == [text, ' ']
39
+ end
40
+ end
41
+
42
+ describe '#read_cli_options!' do
43
+ before :each do
44
+ @twig = Twig.new
45
+ end
46
+
47
+ it 'recognizes `-b` and sets a `:branch` option' do
48
+ @twig.should_receive(:branch_names).and_return(['test'])
49
+ @twig.options[:branch].should be_nil # Precondition
50
+
51
+ @twig.read_cli_options!(%w[-b test])
52
+
53
+ @twig.options[:branch].should == 'test'
54
+ end
55
+
56
+ it 'recognizes `--branch` and sets a `:branch` option' do
57
+ @twig.should_receive(:branch_names).and_return(['test'])
58
+ @twig.options[:branch].should be_nil # Precondition
59
+
60
+ @twig.read_cli_options!(%w[--branch test])
61
+
62
+ @twig.options[:branch].should == 'test'
63
+ end
64
+
65
+ it 'recognizes `--except-branch` and sets a `:branch_except` option' do
66
+ @twig.options[:branch_except].should be_nil # Precondition
67
+ @twig.read_cli_options!(%w[--except-branch test])
68
+ @twig.options[:branch_except].should == /test/
69
+ end
70
+
71
+ it 'recognizes `--only-branch` and sets a `:branch_only` option' do
72
+ @twig.options[:branch_only].should be_nil # Precondition
73
+ @twig.read_cli_options!(%w[--only-branch test])
74
+ @twig.options[:branch_only].should == /test/
75
+ end
76
+
77
+ it 'recognizes `--max-days-old` and sets a `:max_days_old` option' do
78
+ @twig.options[:max_days_old].should be_nil # Precondition
79
+ @twig.read_cli_options!(%w[--max-days-old 30])
80
+ @twig.options[:max_days_old].should == 30
81
+ end
82
+
83
+ it 'recognizes `--all` and unsets other options except `:branch`' do
84
+ @twig.set_option(:max_days_old, 30)
85
+ @twig.set_option(:branch_except, /test/)
86
+ @twig.set_option(:branch_only, /test/)
87
+
88
+ @twig.read_cli_options!(['--all'])
89
+
90
+ @twig.options[:max_days_old].should be_nil
91
+ @twig.options[:branch_except].should be_nil
92
+ @twig.options[:branch_only].should be_nil
93
+ end
94
+
95
+ it 'recognizes `--unset` and sets an `:unset_property` option' do
96
+ @twig.options[:unset_property].should be_nil # Precondition
97
+ @twig.read_cli_options!(%w[--unset test])
98
+ @twig.options[:unset_property].should == 'test'
99
+ end
100
+
101
+ it 'recognizes `--version` and prints the current version' do
102
+ @twig.should_receive(:puts).with(Twig::VERSION)
103
+ @twig.should_receive(:exit)
104
+
105
+ @twig.read_cli_options!(['--version'])
106
+ end
107
+
108
+ it 'handles invalid options' do
109
+ @twig.should_receive(:puts) do |message|
110
+ message.should include('invalid option: --foo')
111
+ end
112
+ @twig.should_receive(:puts) do |message|
113
+ message.should include('`twig --help`')
114
+ end
115
+ @twig.should_receive(:exit)
116
+
117
+ @twig.read_cli_options!(['--foo'])
118
+ end
119
+
120
+ it 'handles missing arguments' do
121
+ @twig.should_receive(:puts) do |message|
122
+ message.should include('missing argument: --branch')
123
+ end
124
+ @twig.should_receive(:puts) do |message|
125
+ message.should include('`twig --help`')
126
+ end
127
+ @twig.should_receive(:exit)
128
+
129
+ @twig.read_cli_options!(['--branch'])
130
+ end
131
+ end
132
+
133
+ describe '#read_cli_args!' do
134
+ before :each do
135
+ @twig = Twig.new
136
+ end
137
+
138
+ it 'lists branches' do
139
+ branch_list = %[foo bar]
140
+ @twig.should_receive(:list_branches).and_return(branch_list)
141
+ @twig.should_receive(:puts).with(branch_list)
142
+
143
+ @twig.read_cli_args!([])
144
+ end
145
+
146
+ context 'running a subcommand' do
147
+ before :each do
148
+ Twig.stub(:run)
149
+ @twig.stub(:current_branch_name => 'test')
150
+ @twig.stub(:puts)
151
+ end
152
+
153
+ it 'recognizes a subcommand' do
154
+ command_path = '/path/to/bin/twig-subcommand'
155
+ Twig.should_receive(:run).with('which twig-subcommand').
156
+ and_return(command_path)
157
+ @twig.should_receive(:exec).with(command_path)
158
+
159
+ @twig.read_cli_args!(['subcommand'])
160
+ end
161
+
162
+ it 'does not recognize a subcommand' do
163
+ Twig.should_receive(:run).with('which twig-subcommand').and_return('')
164
+ @twig.should_not_receive(:exec)
165
+
166
+ @twig.read_cli_args!(['subcommand'])
167
+ end
168
+ end
169
+
170
+ context 'getting properties' do
171
+ before :each do
172
+ @branch_name = 'test'
173
+ @property_name = 'foo'
174
+ @property_value = 'bar'
175
+ end
176
+
177
+ context 'with the current branch' do
178
+ before :each do
179
+ @twig.should_receive(:current_branch_name).and_return(@branch_name)
180
+ end
181
+
182
+ it 'gets a property' do
183
+ @twig.should_receive(:get_branch_property).
184
+ with(@branch_name, @property_name).and_return(@property_value)
185
+ @twig.should_receive(:puts).with(@property_value)
186
+
187
+ @twig.read_cli_args!([@property_name])
188
+ end
189
+
190
+ it 'shows an error if getting a property that is not set' do
191
+ @twig.should_receive(:get_branch_property).
192
+ with(@branch_name, @property_name).and_return('')
193
+ @twig.should_receive(:puts) do |error|
194
+ error.should include(
195
+ %{The branch "#{@branch_name}" does not have the property "#{@property_name}"}
196
+ )
197
+ end
198
+
199
+ @twig.read_cli_args!([@property_name])
200
+ end
201
+ end
202
+
203
+ context 'with a specified branch' do
204
+ before :each do
205
+ @twig.should_receive(:branch_names).and_return([@branch_name])
206
+ @twig.set_option(:branch, @branch_name)
207
+ end
208
+
209
+ it 'gets a property' do
210
+ @twig.should_receive(:get_branch_property).
211
+ with(@branch_name, @property_name).and_return(@property_value)
212
+ @twig.should_receive(:puts).with(@property_value)
213
+
214
+ @twig.read_cli_args!([@property_name])
215
+ end
216
+
217
+ it 'shows an error if getting a property that is not set' do
218
+ @twig.should_receive(:get_branch_property).
219
+ with(@branch_name, @property_name).and_return('')
220
+ @twig.should_receive(:puts) do |error|
221
+ error.should include(
222
+ %{The branch "#{@branch_name}" does not have the property "#{@property_name}"}
223
+ )
224
+ end
225
+
226
+ @twig.read_cli_args!([@property_name])
227
+ end
228
+ end
229
+
230
+ end
231
+
232
+ context 'setting properties' do
233
+ before :each do
234
+ @branch_name = 'test'
235
+ @property_name = 'foo'
236
+ @property_value = 'bar'
237
+ @message = 'Saved.'
238
+ end
239
+
240
+ it 'sets a property for the current branch' do
241
+ @twig.should_receive(:current_branch_name).and_return(@branch_name)
242
+ @twig.should_receive(:set_branch_property).
243
+ with(@branch_name, @property_name, @property_value).
244
+ and_return(@message)
245
+ @twig.should_receive(:puts).with(@message)
246
+
247
+ @twig.read_cli_args!([@property_name, @property_value])
248
+ end
249
+
250
+ it 'sets a property for a specified branch' do
251
+ @twig.should_receive(:branch_names).and_return([@branch_name])
252
+ @twig.set_option(:branch, @branch_name)
253
+ @twig.should_receive(:set_branch_property).
254
+ with(@branch_name, @property_name, @property_value).
255
+ and_return(@message)
256
+ @twig.should_receive(:puts).with(@message)
257
+
258
+ @twig.read_cli_args!([@property_name, @property_value])
259
+ end
260
+ end
261
+
262
+ context 'unsetting properties' do
263
+ before :each do
264
+ @branch_name = 'test'
265
+ @property_name = 'foo'
266
+ @message = 'Removed.'
267
+ @twig.set_option(:unset_property, @property_name)
268
+ end
269
+
270
+ it 'unsets a property for the current branch' do
271
+ @twig.should_receive(:current_branch_name).and_return(@branch_name)
272
+ @twig.should_receive(:unset_branch_property).
273
+ with(@branch_name, @property_name).and_return(@message)
274
+ @twig.should_receive(:puts).with(@message)
275
+
276
+ @twig.read_cli_args!([])
277
+ end
278
+
279
+ it 'unsets a property for a specified branch' do
280
+ @twig.should_receive(:branch_names).and_return([@branch_name])
281
+ @twig.set_option(:branch, @branch_name)
282
+ @twig.should_receive(:unset_branch_property).
283
+ with(@branch_name, @property_name).and_return(@message)
284
+ @twig.should_receive(:puts).with(@message)
285
+
286
+ @twig.read_cli_args!([])
287
+ end
288
+ end
289
+ end
290
+
291
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twig::CommitTime do
4
+ before :each do
5
+ @time = Time.utc(2000, 12, 1, 12, 00, 00)
6
+ end
7
+
8
+ describe '#initialize' do
9
+ it 'stores a Time object' do
10
+ commit_time = Twig::CommitTime.new(@time, '99 days ago')
11
+ commit_time.instance_variable_get(:@time).should == @time
12
+ end
13
+
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'
29
+ end
30
+ end
31
+
32
+ describe '#to_i' do
33
+ it 'returns the time as an integer' do
34
+ commit_time = Twig::CommitTime.new(@time, '99 days ago')
35
+ commit_time.to_i.should == @time.to_i
36
+ end
37
+ end
38
+
39
+ describe '#to_s' do
40
+ it 'returns a formatted string, including time ago' do
41
+ commit_time = Twig::CommitTime.new(@time, '99 days ago')
42
+ result = commit_time.to_s
43
+ result.should include('2000-12-01')
44
+ result.should include('(99d ago)')
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twig::Display do
4
+ before :each do
5
+ @twig = Twig.new
6
+ end
7
+
8
+ describe '#column' do
9
+ it 'returns a string with an exact fixed width' do
10
+ @twig.column('foo', 1, :width => 8).should == 'foo' + (' ' * 5)
11
+ end
12
+
13
+ it 'returns a string that fits a column exactly' do
14
+ @twig.column('asdfasdf', 1, :width => 8).should == 'asdf... '
15
+ end
16
+
17
+ it 'truncates a wide string with an ellipsis' do
18
+ @twig.column('asdfasdfasdf', 1, :width => 8).should == 'asdf... '
19
+ end
20
+
21
+ it 'returns a string that spans multiple columns' do
22
+ @twig.column('foo', 2, :width => 8).should == 'foo' + (' ' * 13)
23
+ end
24
+
25
+ it 'returns a string that spans multiple columns and is truncated' do
26
+ @twig.column('asdf' * 5, 2, :width => 8).should == 'asdfasdfasdf... '
27
+ end
28
+
29
+ it 'passes options through to `format_string`' do
30
+ format_options = { :color => :red, :weight => :bold }
31
+ @twig.should_receive(:format_string).
32
+ with('foo' + (' ' * 5), format_options)
33
+
34
+ @twig.column('foo', 1, format_options)
35
+ end
36
+ end
37
+
38
+ describe '#branch_list_headers' do
39
+ it 'returns a string of branch properties and underlines' do
40
+ Twig::Branch.stub(:all_properties => %w[foo quux])
41
+
42
+ result = @twig.branch_list_headers({})
43
+ result_lines = result.split("\n")
44
+
45
+ column_width = 8
46
+ columns_for_date_time = 5
47
+ first_column_width = column_width * columns_for_date_time
48
+ result_lines[0].should == (' ' * first_column_width) +
49
+ 'foo ' + (' ' * column_width) +
50
+ 'quux ' + (' ' * column_width) +
51
+ ' branch' + (' ' * column_width)
52
+ result_lines[1].should == (' ' * first_column_width) +
53
+ '--- ' + (' ' * column_width) +
54
+ '---- ' + (' ' * column_width) +
55
+ ' ------' + (' ' * column_width)
56
+ end
57
+ end
58
+
59
+ describe '#branch_list_line' do
60
+ before :each do
61
+ @current_branch_name = 'my-branch'
62
+ Twig::Branch.stub(:all_properties => ['foo', 'bar'])
63
+ @twig.should_receive(:get_branch_property).
64
+ with(anything, 'foo').and_return('foo!')
65
+ @twig.should_receive(:get_branch_property).
66
+ with(anything, 'bar').and_return('bar!')
67
+ @twig.should_receive(:current_branch_name).
68
+ and_return(@current_branch_name)
69
+ @commit_time = Twig::CommitTime.new(Time.now, '')
70
+ @commit_time.should_receive(:to_s).and_return('2000-01-01')
71
+ end
72
+
73
+ it 'returns a line for the current branch' do
74
+ indicator = Twig::Display::CURRENT_BRANCH_INDICATOR
75
+ branch = Twig::Branch.new('my-branch')
76
+ branch_regexp = /#{Regexp.escape(indicator)}#{Regexp.escape(branch.name)}/
77
+ branch.should_receive(:last_commit_time).and_return(@commit_time)
78
+
79
+ result = @twig.branch_list_line(branch)
80
+
81
+ result.should =~ /2000-01-01\s+foo!\s+bar!\s+#{branch_regexp}/
82
+ end
83
+
84
+ it 'returns a line for a branch other than the current branch' do
85
+ branch = Twig::Branch.new('other-branch')
86
+ branch.should_receive(:last_commit_time).and_return(@commit_time)
87
+
88
+ result = @twig.branch_list_line(branch)
89
+
90
+ result.should =~ /2000-01-01\s+foo!\s+bar!\s+#{Regexp.escape(branch.name)}/
91
+ end
92
+ end
93
+
94
+ describe '#format_string' do
95
+ it 'returns a plain string' do
96
+ @twig.format_string('foo', {}).should == 'foo'
97
+ end
98
+
99
+ it 'returns a string with a color code' do
100
+ @twig.format_string('foo', :color => :red).
101
+ should == "\033[#{Twig::Display::COLORS[:red]}mfoo\033[0m"
102
+ end
103
+
104
+ it 'returns a string with a weight code' do
105
+ @twig.format_string('foo', :weight => :bold).
106
+ should == "\033[#{Twig::Display::WEIGHTS[:bold]}mfoo\033[0m"
107
+ end
108
+
109
+ it 'returns a string with a color and weight code 'do
110
+ color_code = Twig::Display::COLORS[:red]
111
+ weight_code = Twig::Display::WEIGHTS[:bold]
112
+
113
+ @twig.format_string('foo', :color => :red, :weight => :bold).
114
+ should == "\033[#{color_code};#{weight_code}mfoo\033[0m"
115
+ end
116
+ end
117
+ end