hammer_cli 3.7.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer +1 -6
  3. data/doc/release_notes.md +15 -0
  4. data/lib/hammer_cli/help/builder.rb +1 -2
  5. data/lib/hammer_cli/i18n/find_task.rb +88 -0
  6. data/lib/hammer_cli/i18n.rb +4 -0
  7. data/lib/hammer_cli/options/normalizers.rb +2 -5
  8. data/lib/hammer_cli/settings.rb +7 -0
  9. data/lib/hammer_cli/task_helper.rb +84 -0
  10. data/lib/hammer_cli/testing/output_matchers.rb +1 -1
  11. data/lib/hammer_cli/utils.rb +1 -1
  12. data/lib/hammer_cli/version.rb +1 -1
  13. data/locale/Makefile.def +29 -7
  14. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  15. data/locale/cs_CZ/LC_MESSAGES/hammer-cli.mo +0 -0
  16. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  17. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  18. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  19. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  20. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  21. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  22. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  23. data/locale/ka/LC_MESSAGES/hammer-cli.mo +0 -0
  24. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  25. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  26. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  27. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  28. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  29. data/man/hammer.1.gz +0 -0
  30. data/test/functional/help_test.rb +1 -1
  31. data/test/test_helper.rb +1 -1
  32. data/test/unit/abstract_test.rb +54 -54
  33. data/test/unit/apipie/command_test.rb +26 -27
  34. data/test/unit/apipie/option_builder_test.rb +28 -28
  35. data/test/unit/apipie/option_definition_test.rb +5 -5
  36. data/test/unit/apipie/test_helper.rb +3 -0
  37. data/test/unit/bash_test.rb +21 -21
  38. data/test/unit/command_extensions_test.rb +68 -68
  39. data/test/unit/completer_test.rb +57 -57
  40. data/test/unit/csv_parser_test.rb +12 -12
  41. data/test/unit/defaults_test.rb +3 -3
  42. data/test/unit/help/builder_test.rb +7 -7
  43. data/test/unit/help/definition/abstract_item_test.rb +2 -2
  44. data/test/unit/help/definition/list_test.rb +2 -2
  45. data/test/unit/help/definition/note_test.rb +2 -2
  46. data/test/unit/help/definition/section_test.rb +2 -2
  47. data/test/unit/help/definition/text_test.rb +2 -2
  48. data/test/unit/help/definition_test.rb +36 -36
  49. data/test/unit/help/text_builder_test.rb +39 -39
  50. data/test/unit/history_test.rb +6 -6
  51. data/test/unit/i18n_test.rb +2 -2
  52. data/test/unit/logger_test.rb +1 -1
  53. data/test/unit/main_test.rb +7 -7
  54. data/test/unit/modules_test.rb +24 -25
  55. data/test/unit/option_builder_test.rb +1 -1
  56. data/test/unit/options/matcher_test.rb +15 -15
  57. data/test/unit/options/normalizers_test.rb +92 -88
  58. data/test/unit/options/option_definition_test.rb +11 -11
  59. data/test/unit/options/option_family_test.rb +7 -7
  60. data/test/unit/options/validators/dsl_test.rb +35 -35
  61. data/test/unit/output/adapter/abstract_test.rb +10 -10
  62. data/test/unit/output/adapter/base_test.rb +36 -36
  63. data/test/unit/output/adapter/csv_test.rb +38 -38
  64. data/test/unit/output/adapter/json_test.rb +38 -38
  65. data/test/unit/output/adapter/table_test.rb +42 -50
  66. data/test/unit/output/adapter/yaml_test.rb +38 -38
  67. data/test/unit/output/definition_test.rb +43 -43
  68. data/test/unit/output/dsl_test.rb +19 -19
  69. data/test/unit/output/field_filter_test.rb +10 -10
  70. data/test/unit/output/fields_test.rb +27 -27
  71. data/test/unit/output/formatters_test.rb +39 -39
  72. data/test/unit/output/output_test.rb +14 -14
  73. data/test/unit/output/record_collection_test.rb +18 -18
  74. data/test/unit/settings_test.rb +35 -35
  75. data/test/unit/utils_test.rb +30 -27
  76. metadata +33 -44
@@ -4,30 +4,30 @@ describe HammerCLI::Output::Formatters::FormatterLibrary do
4
4
  it "accepts formatter" do
5
5
  lib = HammerCLI::Output::Formatters::FormatterLibrary.new(
6
6
  :Id => HammerCLI::Output::Formatters::FieldFormatter.new)
7
- lib.formatter_for_type(Fields::Id).must_be_instance_of HammerCLI::Output::Formatters::FormatterContainer
7
+ _(lib.formatter_for_type(Fields::Id)).must_be_instance_of HammerCLI::Output::Formatters::FormatterContainer
8
8
  end
9
9
 
10
10
  it "can add formatter to instance" do
11
11
  lib = HammerCLI::Output::Formatters::FormatterLibrary.new
12
12
  lib.register_formatter :Id, HammerCLI::Output::Formatters::FieldFormatter.new
13
- lib.formatter_for_type(Fields::Id).must_be_instance_of HammerCLI::Output::Formatters::FormatterContainer
13
+ _(lib.formatter_for_type(Fields::Id)).must_be_instance_of HammerCLI::Output::Formatters::FormatterContainer
14
14
  end
15
15
  end
16
16
 
17
17
  describe HammerCLI::Output::Formatters::FieldFormatter do
18
18
  let(:formatter) { HammerCLI::Output::Formatters::FieldFormatter.new }
19
19
  it "has format method" do
20
- formatter.respond_to?(:format).must_equal true
20
+ _(formatter.respond_to?(:format)).must_equal true
21
21
  end
22
22
 
23
23
  it "has features" do
24
- formatter.required_features.must_be_kind_of Array
24
+ _(formatter.required_features).must_be_kind_of Array
25
25
  end
26
26
 
27
27
  it "should know if it has matching features" do
28
28
  formatter.stubs(:required_features).returns([:feature])
29
- formatter.match?([:feature]).must_equal true
30
- formatter.match?([:nofeature]).must_equal false
29
+ _(formatter.match?([:feature])).must_equal true
30
+ _(formatter.match?([:nofeature])).must_equal false
31
31
  end
32
32
  end
33
33
 
@@ -41,37 +41,37 @@ describe HammerCLI::Output::Formatters::FormatterContainer do
41
41
 
42
42
  it "accepts formatter" do
43
43
  container = HammerCLI::Output::Formatters::FormatterContainer.new(TestFormatter.new)
44
- container.format('').must_equal '.'
44
+ _(container.format('')).must_equal '.'
45
45
  end
46
46
 
47
47
  it "has format method" do
48
48
  container = HammerCLI::Output::Formatters::FormatterContainer.new
49
- container.respond_to?(:format).must_equal true
49
+ _(container.respond_to?(:format)).must_equal true
50
50
  end
51
51
 
52
52
  it "can add formatter to instance" do
53
53
  container = HammerCLI::Output::Formatters::FormatterContainer.new(TestFormatter.new)
54
54
  container.add_formatter TestFormatter.new
55
- container.format('').must_equal '..'
55
+ _(container.format('')).must_equal '..'
56
56
  end
57
57
  end
58
58
 
59
59
  describe HammerCLI::Output::Formatters::ColorFormatter do
60
60
  it "colorizes the value" do
61
61
  formatter = HammerCLI::Output::Formatters::ColorFormatter.new(:red)
62
- formatter.format('red').must_equal "\e[31mred\e[0m"
62
+ _(formatter.format('red')).must_equal "\e[31mred\e[0m"
63
63
  end
64
64
  end
65
65
 
66
66
  describe HammerCLI::Output::Formatters::DateFormatter do
67
67
  it "formats the date" do
68
68
  formatter = HammerCLI::Output::Formatters::DateFormatter.new
69
- formatter.format('2000-01-01 21:01:01').must_equal "2000/01/01 21:01:01"
69
+ _(formatter.format('2000-01-01 21:01:01')).must_equal "2000/01/01 21:01:01"
70
70
  end
71
71
 
72
72
  it "returns empty string on wrong value" do
73
73
  formatter = HammerCLI::Output::Formatters::DateFormatter.new
74
- formatter.format('wrong value').must_equal ""
74
+ _(formatter.format('wrong value')).must_equal ""
75
75
  end
76
76
  end
77
77
 
@@ -79,23 +79,23 @@ describe HammerCLI::Output::Formatters::ListFormatter do
79
79
  let(:formatter) { HammerCLI::Output::Formatters::ListFormatter.new }
80
80
 
81
81
  it "serializes the value" do
82
- formatter.format([1, 2]).must_equal '1, 2'
82
+ _(formatter.format([1, 2])).must_equal '1, 2'
83
83
  end
84
84
 
85
85
  it "returns empty string when the input is nil" do
86
- formatter.format(nil).must_equal ''
86
+ _(formatter.format(nil)).must_equal ''
87
87
  end
88
88
 
89
89
  it "returns string value when the input is not a list" do
90
- formatter.format('some string').must_equal 'some string'
90
+ _(formatter.format('some string')).must_equal 'some string'
91
91
  end
92
92
 
93
93
  it 'can put the string on a new line' do
94
- formatter.format([1, 2], :on_new_line => true).must_equal "\n 1, 2"
94
+ _(formatter.format([1, 2], :on_new_line => true)).must_equal "\n 1, 2"
95
95
  end
96
96
 
97
97
  it 'allows to change the separator' do
98
- formatter.format([1, 2, 3], :separator => '#').must_equal "1#2#3"
98
+ _(formatter.format([1, 2, 3], :separator => '#')).must_equal "1#2#3"
99
99
  end
100
100
 
101
101
  it 'can format list vertically' do
@@ -105,7 +105,7 @@ describe HammerCLI::Output::Formatters::ListFormatter do
105
105
  ' value 2',
106
106
  ].join("\n")
107
107
 
108
- formatter.format(['value 1', 'value 2'], :separator => "\n", :on_new_line => true).must_equal expected_output
108
+ _(formatter.format(['value 1', 'value 2'], :separator => "\n", :on_new_line => true)).must_equal expected_output
109
109
  end
110
110
  end
111
111
 
@@ -121,17 +121,17 @@ describe HammerCLI::Output::Formatters::KeyValueFormatter do
121
121
 
122
122
  it "serializes the value" do
123
123
  formatter = HammerCLI::Output::Formatters::KeyValueFormatter.new
124
- formatter.format(params).must_equal 'Name => Value'
124
+ _(formatter.format(params)).must_equal 'Name => Value'
125
125
  end
126
126
 
127
127
  it "returns empty string when the input is nil" do
128
128
  formatter = HammerCLI::Output::Formatters::KeyValueFormatter.new
129
- formatter.format(nil).must_equal ''
129
+ _(formatter.format(nil)).must_equal ''
130
130
  end
131
131
 
132
132
  it "returns empty string value when the input is not a hash" do
133
133
  formatter = HammerCLI::Output::Formatters::KeyValueFormatter.new
134
- formatter.format('some string').must_equal ''
134
+ _(formatter.format('some string')).must_equal ''
135
135
  end
136
136
  end
137
137
 
@@ -141,17 +141,17 @@ describe HammerCLI::Output::Formatters::LongTextFormatter do
141
141
 
142
142
  it "prepends new line" do
143
143
  formatter = HammerCLI::Output::Formatters::LongTextFormatter.new
144
- formatter.format("Some\nmultiline\ntext").must_equal "\n Some\n multiline\n text"
144
+ _(formatter.format("Some\nmultiline\ntext")).must_equal "\n Some\n multiline\n text"
145
145
  end
146
146
 
147
147
  it "accepts nil" do
148
148
  formatter = HammerCLI::Output::Formatters::LongTextFormatter.new
149
- formatter.format(nil).must_equal "\n "
149
+ _(formatter.format(nil)).must_equal "\n "
150
150
  end
151
151
 
152
152
  it "enables to switch indentation off" do
153
153
  formatter = HammerCLI::Output::Formatters::LongTextFormatter.new(:indent => false)
154
- formatter.format("Some\nmultiline\ntext").must_equal "\nSome\nmultiline\ntext"
154
+ _(formatter.format("Some\nmultiline\ntext")).must_equal "\nSome\nmultiline\ntext"
155
155
  end
156
156
 
157
157
  end
@@ -160,11 +160,11 @@ describe HammerCLI::Output::Formatters::InlineTextFormatter do
160
160
  let(:formatter) { HammerCLI::Output::Formatters::InlineTextFormatter.new }
161
161
 
162
162
  it 'prints multiline text to one line' do
163
- formatter.format("Some\nmultiline\ntext").must_equal('Some multiline text')
163
+ _(formatter.format("Some\nmultiline\ntext")).must_equal('Some multiline text')
164
164
  end
165
165
 
166
166
  it 'accepts nil' do
167
- formatter.format(nil).must_equal('')
167
+ _(formatter.format(nil)).must_equal('')
168
168
  end
169
169
  end
170
170
 
@@ -175,26 +175,26 @@ describe HammerCLI::Output::Formatters::MultilineTextFormatter do
175
175
  let(:long_multiline_text) { 'Lorem ipsum dolor' * 5 }
176
176
 
177
177
  it 'prints multiline text' do
178
- formatter.format(multiline_text).must_equal(
178
+ _(formatter.format(multiline_text)).must_equal(
179
179
  "#{indentation}Some#{indentation}multiline#{indentation}text"
180
180
  )
181
181
  end
182
182
 
183
183
  it 'accepts nil' do
184
- formatter.format(nil).must_equal(indentation)
184
+ _(formatter.format(nil)).must_equal(indentation)
185
185
  end
186
186
 
187
187
  it 'accepts field width param' do
188
- formatter.format(long_multiline_text, width: 80)
188
+ _(formatter.format(long_multiline_text, width: 80))
189
189
  .must_equal(indentation + long_multiline_text[0..-6] +
190
190
  indentation + long_multiline_text[-5..-1])
191
191
  end
192
192
 
193
193
  it 'deals with strange params' do
194
- formatter.format(long_multiline_text, width: -1)
194
+ _(formatter.format(long_multiline_text, width: -1))
195
195
  .must_equal(indentation + long_multiline_text[0..-26] +
196
196
  indentation + long_multiline_text[-25..-1])
197
- formatter.format(long_multiline_text, width: 999)
197
+ _(formatter.format(long_multiline_text, width: 999))
198
198
  .must_equal(indentation + long_multiline_text)
199
199
  end
200
200
  end
@@ -204,16 +204,16 @@ describe HammerCLI::Output::Formatters::BooleanFormatter do
204
204
  let(:formatter) { HammerCLI::Output::Formatters::BooleanFormatter.new }
205
205
 
206
206
  it "says yes for true like objects" do
207
- formatter.format(true).must_equal "yes"
208
- formatter.format("yes").must_equal "yes"
209
- formatter.format("no").must_equal "yes"
210
- formatter.format(1).must_equal "yes"
207
+ _(formatter.format(true)).must_equal "yes"
208
+ _(formatter.format("yes")).must_equal "yes"
209
+ _(formatter.format("no")).must_equal "yes"
210
+ _(formatter.format(1)).must_equal "yes"
211
211
  end
212
212
 
213
213
  it "says no for false, nil, empty string and 0" do
214
- formatter.format(nil).must_equal "no"
215
- formatter.format(false).must_equal "no"
216
- formatter.format("").must_equal "no"
217
- formatter.format(0).must_equal "no"
214
+ _(formatter.format(nil)).must_equal "no"
215
+ _(formatter.format(false)).must_equal "no"
216
+ _(formatter.format("")).must_equal "no"
217
+ _(formatter.format(0)).must_equal "no"
218
218
  end
219
219
  end
@@ -79,27 +79,27 @@ describe HammerCLI::Output::Output do
79
79
  context "adapters" do
80
80
  it "should register adapter" do
81
81
  out_class.register_adapter(:test, HammerCLI::Output::Adapter::Silent)
82
- out_class.adapters[:test].must_equal(HammerCLI::Output::Adapter::Silent)
82
+ _(out_class.adapters[:test]).must_equal(HammerCLI::Output::Adapter::Silent)
83
83
  end
84
84
 
85
85
  it "should return required default adapter" do
86
86
  out = out_class.new({}, {:default_adapter => :silent})
87
- out.adapter.must_be_instance_of HammerCLI::Output::Adapter::Silent
87
+ _(out.adapter).must_be_instance_of HammerCLI::Output::Adapter::Silent
88
88
  end
89
89
 
90
90
  it "should use adapter form context" do
91
91
  out = out_class.new({:adapter => :silent})
92
- out.adapter.must_be_instance_of HammerCLI::Output::Adapter::Silent
92
+ _(out.adapter).must_be_instance_of HammerCLI::Output::Adapter::Silent
93
93
  end
94
94
 
95
95
  it "should prioritize adapter from the context" do
96
96
  out = out_class.new({:adapter => :table}, {:default_adapter => :silent})
97
- out.adapter.must_be_instance_of HammerCLI::Output::Adapter::Table
97
+ _(out.adapter).must_be_instance_of HammerCLI::Output::Adapter::Table
98
98
  end
99
99
 
100
100
  it "should use base adapter if the requested default was not found" do
101
101
  out = out_class.new({}, {:default_adapter => :unknown})
102
- out.adapter.must_be_instance_of HammerCLI::Output::Adapter::Base
102
+ _(out.adapter).must_be_instance_of HammerCLI::Output::Adapter::Base
103
103
  end
104
104
  end
105
105
 
@@ -107,8 +107,8 @@ describe HammerCLI::Output::Output do
107
107
  it "should register formatter" do
108
108
  formatter = HammerCLI::Output::Formatters::FieldFormatter.new
109
109
  out_class.register_formatter(formatter, :type1, :type2)
110
- out_class.formatters[:type1].must_equal([formatter])
111
- out_class.formatters[:type2].must_equal([formatter])
110
+ _(out_class.formatters[:type1]).must_equal([formatter])
111
+ _(out_class.formatters[:type2]).must_equal([formatter])
112
112
  end
113
113
  end
114
114
 
@@ -128,7 +128,7 @@ describe HammerCLI::Output::Output do
128
128
  )
129
129
  end
130
130
  let(:id) { Fields::Id.new(:path => [:id], :label => 'Id') }
131
- let(:name) { Fields::Field.new(:path => [:name], :label => 'Name') }
131
+ let(:firstname) { Fields::Field.new(:path => [:name], :label => 'Name') }
132
132
  let(:surname) { Fields::Field.new(:path => [:surname], :label => 'Surname') }
133
133
  let(:definition) { HammerCLI::Output::Definition.new }
134
134
  let(:expected_record_output) do
@@ -174,14 +174,14 @@ describe HammerCLI::Output::Output do
174
174
  end
175
175
 
176
176
  it 'should not print record data' do
177
- definition.append([id, name, surname])
177
+ definition.append([id, firstname, surname])
178
178
  assert_output('', nil) do
179
179
  output.print_record(definition, data.first)
180
180
  end
181
181
  end
182
182
 
183
183
  it 'should not print collection data' do
184
- definition.append([id, name, surname])
184
+ definition.append([id, firstname, surname])
185
185
  assert_output('', nil) do
186
186
  output.print_record(definition, data)
187
187
  end
@@ -223,14 +223,14 @@ describe HammerCLI::Output::Output do
223
223
  end
224
224
 
225
225
  it 'should print record data' do
226
- definition.append([id, name, surname])
226
+ definition.append([id, firstname, surname])
227
227
  assert_output(expected_record_output, nil) do
228
228
  output.print_record(definition, data.first)
229
229
  end
230
230
  end
231
231
 
232
232
  it 'should print collection data' do
233
- definition.append([id, name, surname])
233
+ definition.append([id, firstname, surname])
234
234
  assert_output(expected_record_output, nil) do
235
235
  output.print_record(definition, data)
236
236
  end
@@ -271,14 +271,14 @@ describe HammerCLI::Output::Output do
271
271
  end
272
272
 
273
273
  it 'should print record data' do
274
- definition.append([id, name, surname])
274
+ definition.append([id, firstname, surname])
275
275
  assert_output(expected_record_output, nil) do
276
276
  output.print_record(definition, data.first)
277
277
  end
278
278
  end
279
279
 
280
280
  it 'should print collection data' do
281
- definition.append([id, name, surname])
281
+ definition.append([id, firstname, surname])
282
282
  assert_output(expected_record_output, nil) do
283
283
  output.print_record(definition, data)
284
284
  end
@@ -7,28 +7,28 @@ describe HammerCLI::Output::RecordCollection do
7
7
  let(:set) { HammerCLI::Output::RecordCollection.new(data, meta) }
8
8
 
9
9
  it "should keep records and its meta data" do
10
- set.must_equal data
11
- set.meta.total.must_equal 6
12
- set.meta.subtotal.must_equal 5
13
- set.meta.total.must_equal 6
14
- set.meta.page.must_equal 2
15
- set.meta.per_page.must_equal 3
16
- set.meta.search.must_equal 'name~=xx'
17
- set.meta.sort_by.must_equal 'name'
18
- set.meta.sort_order.must_equal 'ASC'
10
+ _(set).must_equal data
11
+ _(set.meta.total).must_equal 6
12
+ _(set.meta.subtotal).must_equal 5
13
+ _(set.meta.total).must_equal 6
14
+ _(set.meta.page).must_equal 2
15
+ _(set.meta.per_page).must_equal 3
16
+ _(set.meta.search).must_equal 'name~=xx'
17
+ _(set.meta.sort_by).must_equal 'name'
18
+ _(set.meta.sort_order).must_equal 'ASC'
19
19
  end
20
20
 
21
21
  it "should wrap the data into list" do
22
22
  record = { :key => :value, :key2 => :value }
23
23
  rs = HammerCLI::Output::RecordCollection.new(record)
24
- rs.must_be_kind_of Array
24
+ _(rs).must_be_kind_of Array
25
25
  end
26
26
 
27
27
  it "sould accept MetaData as option" do
28
28
  metadata = HammerCLI::Output::MetaData.new(meta)
29
29
  set = HammerCLI::Output::RecordCollection.new(data, :meta => metadata)
30
- set.meta.must_equal metadata
31
- set.meta.total.must_equal 6
30
+ _(set.meta).must_equal metadata
31
+ _(set.meta.total).must_equal 6
32
32
  end
33
33
  end
34
34
 
@@ -37,23 +37,23 @@ describe HammerCLI::Output::MetaData do
37
37
  let(:meta) { HammerCLI::Output::MetaData.new(:total => "6", :page => "2", :per_page => "3", :subtotal => "5") }
38
38
 
39
39
  it "converts numeric metadata to numbers" do
40
- meta.total.must_equal 6
41
- meta.page.must_equal 2
42
- meta.per_page.must_equal 3
43
- meta.subtotal.must_equal 5
40
+ _(meta.total).must_equal 6
41
+ _(meta.page).must_equal 2
42
+ _(meta.per_page).must_equal 3
43
+ _(meta.subtotal).must_equal 5
44
44
  end
45
45
 
46
46
  describe "pagination_set?" do
47
47
  let(:pagination_data) { { :total => 6, :page => 2, :per_page => 3, :subtotal => 5 } }
48
48
 
49
49
  it "can tell if pagination data are set" do
50
- meta.pagination_set?.must_equal true
50
+ _(meta.pagination_set?).must_equal true
51
51
  end
52
52
 
53
53
  it "can tell if pagination data are not set" do
54
54
  pagination_data.keys.each do |key|
55
55
  meta = HammerCLI::Output::MetaData.new(pagination_data.clone.reject { |k| k == key })
56
- meta.pagination_set?.must_equal false
56
+ _(meta.pagination_set?).must_equal false
57
57
  end
58
58
  end
59
59
  end
@@ -10,83 +10,83 @@ describe HammerCLI::Settings do
10
10
  let(:settings) { HammerCLI::Settings }
11
11
 
12
12
  it "returns nil when nothing is loaded" do
13
- settings.get(:a).must_be_nil
14
- settings.get(:a, :b).must_be_nil
13
+ _(settings.get(:a)).must_be_nil
14
+ _(settings.get(:a, :b)).must_be_nil
15
15
  end
16
16
 
17
17
  it "returns nil on unknown key" do
18
18
  settings.load({:a => 1})
19
- settings.get(:b).must_be_nil
19
+ _(settings.get(:b)).must_be_nil
20
20
  end
21
21
 
22
22
  it "returns correct value" do
23
23
  settings.load({:a => 1})
24
- settings.get(:a).must_equal 1
24
+ _(settings.get(:a)).must_equal 1
25
25
  end
26
26
 
27
27
  it "takes both strings and symbols" do
28
28
  settings.load({:a => 1, 'b' => 2})
29
- settings.get('a').must_equal 1
30
- settings.get(:b).must_equal 2
29
+ _(settings.get('a')).must_equal 1
30
+ _(settings.get(:b)).must_equal 2
31
31
  end
32
32
 
33
33
  it "finds nested settings" do
34
34
  settings.load({:a => {:b => 1}})
35
- settings.get(:a, :b).must_equal 1
36
- settings.get(:a, 'b').must_equal 1
37
- settings.get('a', :b).must_equal 1
35
+ _(settings.get(:a, :b)).must_equal 1
36
+ _(settings.get(:a, 'b')).must_equal 1
37
+ _(settings.get('a', :b)).must_equal 1
38
38
  end
39
39
 
40
40
  it "loads all settings" do
41
41
  settings.load({:a => 1, :b => 2})
42
- settings.get(:a).must_equal 1
43
- settings.get(:b).must_equal 2
42
+ _(settings.get(:a)).must_equal 1
43
+ _(settings.get(:b)).must_equal 2
44
44
  end
45
45
 
46
46
  it "dumps all settings" do
47
47
  settings.empty
48
48
  data = {:a => 1, :b => 2}
49
49
  settings.load(data)
50
- settings.dump.must_equal data
50
+ _(settings.dump).must_equal data
51
51
  end
52
52
 
53
53
  it "merges hash settings on second load" do
54
54
  settings.load({:a => 1, :b => 2, :d => {:e => 4, :f => 5}})
55
55
  settings.load({:b => 'B', :c => 'C', :d => {:e => 'E'}})
56
- settings.get(:a).must_equal 1
57
- settings.get(:b).must_equal 'B'
58
- settings.get(:c).must_equal 'C'
59
- settings.get(:d, :e).must_equal 'E'
60
- settings.get(:d, :f).must_equal 5
56
+ _(settings.get(:a)).must_equal 1
57
+ _(settings.get(:b)).must_equal 'B'
58
+ _(settings.get(:c)).must_equal 'C'
59
+ _(settings.get(:d, :e)).must_equal 'E'
60
+ _(settings.get(:d, :f)).must_equal 5
61
61
  end
62
62
 
63
63
  it "merges array settings on second load" do
64
64
  settings.load({:x => [:a, :b]})
65
65
  settings.load({:x => [:c, :d]})
66
- settings.get(:x)[0].must_equal :a
67
- settings.get(:x)[1].must_equal :b
68
- settings.get(:x)[2].must_equal :c
69
- settings.get(:x)[3].must_equal :d
70
- settings.get(:x).size.must_equal 4
66
+ _(settings.get(:x)[0]).must_equal :a
67
+ _(settings.get(:x)[1]).must_equal :b
68
+ _(settings.get(:x)[2]).must_equal :c
69
+ _(settings.get(:x)[3]).must_equal :d
70
+ _(settings.get(:x).size).must_equal 4
71
71
  end
72
72
 
73
73
  it "clear wipes all settings but default values" do
74
74
  settings.load({:a => 1, :b => 2})
75
75
  settings.clear
76
- settings.get(:a).must_be_nil
77
- settings.get(:b).must_be_nil
78
- settings.default_settings.each { |key, val| settings.get(key).must_equal val }
76
+ _(settings.get(:a)).must_be_nil
77
+ _(settings.get(:b)).must_be_nil
78
+ settings.default_settings.each { |key, val| _(settings.get(key)).must_equal val }
79
79
  end
80
80
 
81
81
  it "empty wipes all settings including default values" do
82
82
  settings.load({:a => 1, :b => 2})
83
83
  settings.empty
84
- settings.dump.must_equal({})
84
+ _(settings.dump).must_equal({})
85
85
  end
86
86
 
87
87
  it "initializes settings with default settings" do
88
88
  settings.instance_variable_set(:@settings_hash, nil)
89
- settings.dump.must_equal settings.default_settings
89
+ _(settings.dump).must_equal settings.default_settings
90
90
  end
91
91
 
92
92
  context "load from paths" do
@@ -115,19 +115,19 @@ describe HammerCLI::Settings do
115
115
 
116
116
  it "loads settings from file" do
117
117
  [config1.path, config2.path].each { |config| settings.load_from_file config }
118
- settings.get(:host).must_equal 'https://localhost.localdomain/'
119
- settings.get(:username).must_equal 'admin'
118
+ _(settings.get(:host)).must_equal 'https://localhost.localdomain/'
119
+ _(settings.get(:username)).must_equal 'admin'
120
120
  end
121
121
 
122
122
  it "clears path history on clear invokation" do
123
123
  settings.load_from_paths [config2.path]
124
124
  settings.clear
125
- settings.path_history.must_equal []
125
+ _(settings.path_history).must_equal []
126
126
  end
127
127
 
128
128
  it "store config path history" do
129
129
  [config1.path, config2.path].each { |config| settings.load_from_file config }
130
- settings.path_history.must_equal [config1.path, config2.path]
130
+ _(settings.path_history).must_equal [config1.path, config2.path]
131
131
  end
132
132
 
133
133
  it "loads settings from dir" do
@@ -146,10 +146,10 @@ describe HammerCLI::Settings do
146
146
  settings.load_from_paths [dir]
147
147
  settings.load_from_file config1.path
148
148
 
149
- settings.get(:host).must_equal 'https://localhost/'
150
- settings.get(:username).must_equal 'admin'
151
- settings.get(:param1).must_equal 'value1'
152
- settings.get(:module, :param2).must_equal 'value2'
149
+ _(settings.get(:host)).must_equal 'https://localhost/'
150
+ _(settings.get(:username)).must_equal 'admin'
151
+ _(settings.get(:param1)).must_equal 'value1'
152
+ _(settings.get(:module, :param2)).must_equal 'value2'
153
153
 
154
154
  ensure
155
155
  FileUtils.remove_entry dir