twig 1.0.1 → 1.1

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.
@@ -16,9 +16,7 @@ describe Twig::Options do
16
16
  file = double('file')
17
17
  File.should_receive(:readable?).with(Twig::CONFIG_FILE).and_return(true)
18
18
  File.should_receive(:open).with(Twig::CONFIG_FILE).and_yield(file)
19
- file.should_receive(:read).and_return(%{
20
- branch: test
21
- }.gsub(/^\s+/, ''))
19
+ file.should_receive(:read).and_return('branch: test')
22
20
  @twig.options[:branch].should be_nil # Precondition
23
21
 
24
22
  @twig.read_config_file!
@@ -31,16 +29,21 @@ describe Twig::Options do
31
29
  file = double('file')
32
30
  File.should_receive(:readable?).with(Twig::CONFIG_FILE).and_return(true)
33
31
  File.should_receive(:open).with(Twig::CONFIG_FILE).and_yield(file)
34
- file.should_receive(:read).and_return(%{
35
- branch: test
36
- except-branch: test-except
37
- only-branch: test-only
38
- max-days-old: 30.5
39
- }.gsub(/^\s+/, ''))
40
- @twig.options[:branch].should be_nil # Precondition
41
- @twig.options[:branch_except].should be_nil # Precondition
42
- @twig.options[:branch_only].should be_nil # Precondition
43
- @twig.options[:max_days_old].should be_nil # Precondition
32
+ file.should_receive(:read).and_return([
33
+ 'branch: test',
34
+ 'except-branch: test-except',
35
+ 'only-branch: test-only',
36
+ 'max-days-old: 30.5',
37
+ 'header-style: green bold'
38
+ ].join("\n"))
39
+
40
+ # Check preconditions
41
+ @twig.options[:branch].should be_nil
42
+ @twig.options[:branch_except].should be_nil
43
+ @twig.options[:branch_only].should be_nil
44
+ @twig.options[:max_days_old].should be_nil
45
+ @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
46
+ @twig.options[:header_weight].should be_nil
44
47
 
45
48
  @twig.read_config_file!
46
49
 
@@ -48,6 +51,44 @@ describe Twig::Options do
48
51
  @twig.options[:branch_except].should == /test-except/
49
52
  @twig.options[:branch_only].should == /test-only/
50
53
  @twig.options[:max_days_old].should == 30.5
54
+ @twig.options[:header_color].should == :green
55
+ @twig.options[:header_weight].should == :bold
56
+ end
57
+
58
+ it 'skips comments' do
59
+ file = double('file')
60
+ File.should_receive(:readable?).with(Twig::CONFIG_FILE).and_return(true)
61
+ File.should_receive(:open).with(Twig::CONFIG_FILE).and_yield(file)
62
+ file.should_receive(:read).and_return([
63
+ '# max-days-old: 40',
64
+ 'max-days-old: 30',
65
+ '# max-days-old: 20'
66
+ ].join("\n"))
67
+ @twig.options[:max_days_old].should be_nil # Precondition
68
+
69
+ @twig.read_config_file!
70
+
71
+ @twig.options[:max_days_old].should == 30
72
+ end
73
+
74
+ it 'skips line breaks' do
75
+ file = double('file')
76
+ File.should_receive(:readable?).with(Twig::CONFIG_FILE).and_return(true)
77
+ File.should_receive(:open).with(Twig::CONFIG_FILE).and_yield(file)
78
+ file.should_receive(:read).and_return([
79
+ 'except-branch: test-except',
80
+ '',
81
+ 'only-branch: test-only'
82
+ ].join("\n"))
83
+
84
+ # Check preconditions
85
+ @twig.options[:branch_except].should be_nil
86
+ @twig.options[:branch_only].should be_nil
87
+
88
+ @twig.read_config_file!
89
+
90
+ @twig.options[:branch_except].should == /test-except/
91
+ @twig.options[:branch_only].should == /test-only/
51
92
  end
52
93
 
53
94
  it 'fails gracefully if the config file is not readable' do
@@ -63,16 +104,22 @@ describe Twig::Options do
63
104
  end
64
105
 
65
106
  it 'succeeds' do
107
+ branch_name = 'foo'
66
108
  @twig.should_receive(:branch_names).and_return(%[foo bar])
67
- @twig.set_option(:branch, 'foo')
68
- @twig.options[:branch].should == 'foo'
109
+
110
+ @twig.set_option(:branch, branch_name)
111
+
112
+ @twig.options[:branch].should == branch_name
69
113
  end
70
114
 
71
115
  it 'fails if the branch is unknown' do
116
+ branch_name = 'foo'
72
117
  @twig.should_receive(:branch_names).and_return([])
73
- @twig.should_receive(:abort)
118
+ @twig.should_receive(:abort) do |message|
119
+ message.should include(%{branch "#{branch_name}" could not be found})
120
+ end
74
121
 
75
- @twig.set_option(:branch, 'foo')
122
+ @twig.set_option(:branch, branch_name)
76
123
 
77
124
  @twig.options[:branch].should be_nil
78
125
  end
@@ -90,6 +137,13 @@ describe Twig::Options do
90
137
  @twig.options[:branch_only].should == /important_prefix_/
91
138
  end
92
139
 
140
+ it 'sets a :header_style option' do
141
+ style = 'red bold'
142
+ @twig.should_receive(:set_header_style_option).with(style)
143
+
144
+ @twig.set_option(:header_style, style)
145
+ end
146
+
93
147
  context 'when setting a :max_days_old option' do
94
148
  before :each do
95
149
  @twig.options[:max_days_old].should be_nil # Precondition
@@ -101,8 +155,12 @@ describe Twig::Options do
101
155
  end
102
156
 
103
157
  it 'fails if the option is not numeric' do
104
- @twig.should_receive(:abort)
105
- @twig.set_option(:max_days_old, 'blargh')
158
+ value = 'blargh'
159
+ @twig.should_receive(:abort) do |message|
160
+ message.should include("`--max-days-old=#{value}` is invalid")
161
+ end
162
+ @twig.set_option(:max_days_old, value)
163
+
106
164
  @twig.options[:max_days_old].should be_nil
107
165
  end
108
166
  end
@@ -114,6 +172,91 @@ describe Twig::Options do
114
172
  end
115
173
  end
116
174
 
175
+ describe '#set_header_style_option' do
176
+ before :each do
177
+ # Preconditions:
178
+ @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
179
+ @twig.options[:header_weight].should be_nil
180
+ end
181
+
182
+ it 'succeeds at setting a color option' do
183
+ @twig.set_header_style_option('red')
184
+ @twig.options[:header_color].should == :red
185
+ @twig.options[:header_weight].should be_nil
186
+ end
187
+
188
+ it 'succeeds at setting a weight option' do
189
+ @twig.set_header_style_option('bold')
190
+ @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
191
+ @twig.options[:header_weight].should == :bold
192
+ end
193
+
194
+ it 'succeeds at setting color and weight options, color first' do
195
+ @twig.set_header_style_option('red bold')
196
+ @twig.options[:header_color].should == :red
197
+ @twig.options[:header_weight].should == :bold
198
+ end
199
+
200
+ it 'succeeds at setting color and weight options, weight first' do
201
+ @twig.set_header_style_option('bold red')
202
+ @twig.options[:header_color].should == :red
203
+ @twig.options[:header_weight].should == :bold
204
+ end
205
+
206
+ it 'succeeds at setting color and weight options with extra space between words' do
207
+ @twig.set_header_style_option('red bold')
208
+ @twig.options[:header_color].should == :red
209
+ @twig.options[:header_weight].should == :bold
210
+ end
211
+
212
+ it 'fails if the one-word option is invalid' do
213
+ style = 'handsofblue' # Two by two...
214
+ @twig.should_receive(:abort) do |message|
215
+ message.should include("`--header-style=#{style}` is invalid")
216
+ end
217
+ @twig.set_header_style_option(style)
218
+
219
+ @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
220
+ @twig.options[:header_weight].should be_nil
221
+ end
222
+
223
+ it 'fails if the color of the two-word option is invalid' do
224
+ style = 'handsofblue bold'
225
+ @twig.should_receive(:abort) do |message|
226
+ message.should include("`--header-style=#{style}` is invalid")
227
+ end
228
+
229
+ @twig.set_header_style_option(style)
230
+ end
231
+
232
+ it 'fails if the weight of the two-word option is invalid' do
233
+ style = 'red extrabold'
234
+ @twig.should_receive(:abort) do |message|
235
+ message.should include("`--header-style=#{style}` is invalid")
236
+ end
237
+
238
+ @twig.set_header_style_option(style)
239
+ end
240
+
241
+ it 'fails if there are two colors' do
242
+ style = 'red green'
243
+ @twig.should_receive(:abort) do |message|
244
+ message.should include("`--header-style=#{style}` is invalid")
245
+ end
246
+
247
+ @twig.set_header_style_option(style)
248
+ end
249
+
250
+ it 'fails if there are two weights' do
251
+ style = 'bold bold'
252
+ @twig.should_receive(:abort) do |message|
253
+ message.should include("`--header-style=#{style}` is invalid")
254
+ end
255
+
256
+ @twig.set_header_style_option(style)
257
+ end
258
+ end
259
+
117
260
  describe '#unset_option' do
118
261
  it 'unsets an option' do
119
262
  @twig.set_option(:max_days_old, 1)
data/spec/twig_spec.rb CHANGED
@@ -4,14 +4,9 @@ describe Twig do
4
4
  describe '#initialize' do
5
5
  it 'creates a Twig instance' do
6
6
  twig = Twig.new
7
- twig.options.should == {}
8
- end
9
-
10
- it 'creates a Twig instance with arbitrary options' do
11
- options = {:foo => 'bar'}
12
- twig = Twig.new(options)
13
-
14
- twig.options.should == options
7
+ twig.options.should == {
8
+ :header_color => Twig::DEFAULT_HEADER_COLOR
9
+ }
15
10
  end
16
11
  end
17
12
 
@@ -35,14 +30,13 @@ describe Twig do
35
30
  fix_some_other_of_the_things
36
31
  fix_nothing
37
32
  ]
38
- branch_refs = @branch_names.map { |name| Twig::REF_PREFIX + name }
39
33
  @commit_time_strings = ['2001-01-01', '2002-02-02', '2003-03-03' ]
40
34
  @commit_time_agos = ['111 days ago', '222 days ago', '333 days ago']
41
35
  @command =
42
36
  %{git for-each-ref #{Twig::REF_PREFIX} --format="#{Twig::REF_FORMAT}"}
43
37
 
44
38
  @branch_tuples = (0..2).map do |i|
45
- "#{branch_refs[i]},#{@commit_time_strings[i]},#{@commit_time_agos[i]}"
39
+ "#{@branch_names[i]},#{@commit_time_strings[i]},#{@commit_time_agos[i]}"
46
40
  end.join("\n")
47
41
  end
48
42
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twig
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ version: "1.1"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Ron DeVera
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2013-02-13 00:00:00 -08:00
17
+ date: 2013-03-06 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -72,8 +71,11 @@ email:
72
71
  executables:
73
72
  - twig
74
73
  - twig-gh-open
74
+ - twig-gh-open-issue
75
75
  - twig-gh-update
76
76
  - twig-help
77
+ - twig-init-completion
78
+ - twig-init-completion-bash
77
79
  extensions: []
78
80
 
79
81
  extra_rdoc_files: []
@@ -89,8 +91,11 @@ files:
89
91
  - Rakefile
90
92
  - bin/twig
91
93
  - bin/twig-gh-open
94
+ - bin/twig-gh-open-issue
92
95
  - bin/twig-gh-update
93
96
  - bin/twig-help
97
+ - bin/twig-init-completion
98
+ - bin/twig-init-completion-bash
94
99
  - lib/twig.rb
95
100
  - lib/twig/branch.rb
96
101
  - lib/twig/cli.rb