hammer_cli 3.7.0 → 3.8.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.
- checksums.yaml +4 -4
- data/bin/hammer +1 -6
- data/doc/release_notes.md +15 -0
- data/lib/hammer_cli/help/builder.rb +1 -2
- data/lib/hammer_cli/i18n/find_task.rb +88 -0
- data/lib/hammer_cli/i18n.rb +4 -0
- data/lib/hammer_cli/options/normalizers.rb +2 -5
- data/lib/hammer_cli/settings.rb +7 -0
- data/lib/hammer_cli/task_helper.rb +84 -0
- data/lib/hammer_cli/testing/output_matchers.rb +1 -1
- data/lib/hammer_cli/utils.rb +1 -1
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/Makefile.def +29 -7
- data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/cs_CZ/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ka/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
- data/man/hammer.1.gz +0 -0
- data/test/functional/help_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/abstract_test.rb +54 -54
- data/test/unit/apipie/command_test.rb +26 -27
- data/test/unit/apipie/option_builder_test.rb +28 -28
- data/test/unit/apipie/option_definition_test.rb +5 -5
- data/test/unit/apipie/test_helper.rb +3 -0
- data/test/unit/bash_test.rb +21 -21
- data/test/unit/command_extensions_test.rb +68 -68
- data/test/unit/completer_test.rb +57 -57
- data/test/unit/csv_parser_test.rb +12 -12
- data/test/unit/defaults_test.rb +3 -3
- data/test/unit/help/builder_test.rb +7 -7
- data/test/unit/help/definition/abstract_item_test.rb +2 -2
- data/test/unit/help/definition/list_test.rb +2 -2
- data/test/unit/help/definition/note_test.rb +2 -2
- data/test/unit/help/definition/section_test.rb +2 -2
- data/test/unit/help/definition/text_test.rb +2 -2
- data/test/unit/help/definition_test.rb +36 -36
- data/test/unit/help/text_builder_test.rb +39 -39
- data/test/unit/history_test.rb +6 -6
- data/test/unit/i18n_test.rb +2 -2
- data/test/unit/logger_test.rb +1 -1
- data/test/unit/main_test.rb +7 -7
- data/test/unit/modules_test.rb +24 -25
- data/test/unit/option_builder_test.rb +1 -1
- data/test/unit/options/matcher_test.rb +15 -15
- data/test/unit/options/normalizers_test.rb +92 -88
- data/test/unit/options/option_definition_test.rb +11 -11
- data/test/unit/options/option_family_test.rb +7 -7
- data/test/unit/options/validators/dsl_test.rb +35 -35
- data/test/unit/output/adapter/abstract_test.rb +10 -10
- data/test/unit/output/adapter/base_test.rb +36 -36
- data/test/unit/output/adapter/csv_test.rb +38 -38
- data/test/unit/output/adapter/json_test.rb +38 -38
- data/test/unit/output/adapter/table_test.rb +42 -50
- data/test/unit/output/adapter/yaml_test.rb +38 -38
- data/test/unit/output/definition_test.rb +43 -43
- data/test/unit/output/dsl_test.rb +19 -19
- data/test/unit/output/field_filter_test.rb +10 -10
- data/test/unit/output/fields_test.rb +27 -27
- data/test/unit/output/formatters_test.rb +39 -39
- data/test/unit/output/output_test.rb +14 -14
- data/test/unit/output/record_collection_test.rb +18 -18
- data/test/unit/settings_test.rb +35 -35
- data/test/unit/utils_test.rb +30 -27
- metadata +33 -44
@@ -5,7 +5,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
5
5
|
let(:adapter) { HammerCLI::Output::Adapter::CSValues.new }
|
6
6
|
|
7
7
|
it "forbids default pagination" do
|
8
|
-
adapter.paginate_by_default
|
8
|
+
_(adapter.paginate_by_default?).must_equal false
|
9
9
|
end
|
10
10
|
|
11
11
|
context "print_collection" do
|
@@ -24,28 +24,28 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
24
24
|
|
25
25
|
it "should print column name" do
|
26
26
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
27
|
-
out.must_match(/.*Name,Started At.*/)
|
28
|
-
err.must_match(//)
|
27
|
+
_(out).must_match(/.*Name,Started At.*/)
|
28
|
+
_(err).must_match(//)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should print field value" do
|
32
32
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
33
|
-
out.must_match(/.*John Doe.*/)
|
34
|
-
err.must_match(//)
|
33
|
+
_(out).must_match(/.*John Doe.*/)
|
34
|
+
_(err).must_match(//)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "does not print fields which data are missing from api by default" do
|
38
38
|
fields << field_login
|
39
39
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
40
|
-
out.wont_match(/.*Login.*/)
|
41
|
-
err.must_match(//)
|
40
|
+
_(out).wont_match(/.*Login.*/)
|
41
|
+
_(err).must_match(//)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "prints fields which data are missing from api when field has hide_missing flag set to false" do
|
45
45
|
fields << field_missing
|
46
46
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
47
|
-
out.must_match(/.*Missing.*/)
|
48
|
-
err.must_match(//)
|
47
|
+
_(out).must_match(/.*Missing.*/)
|
48
|
+
_(err).must_match(//)
|
49
49
|
end
|
50
50
|
|
51
51
|
context "handle ids" do
|
@@ -60,14 +60,14 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
60
60
|
|
61
61
|
it "should ommit column of type Id by default" do
|
62
62
|
out, _ = capture_io { adapter.print_collection(fields, data) }
|
63
|
-
out.wont_match(/.*Id.*/)
|
64
|
-
out.wont_match(/.*2000,.*/)
|
63
|
+
_(out).wont_match(/.*Id.*/)
|
64
|
+
_(out).wont_match(/.*2000,.*/)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should print column of type Id when --show-ids is set" do
|
68
68
|
adapter = HammerCLI::Output::Adapter::CSValues.new( { :show_ids => true } )
|
69
69
|
out, _ = capture_io { adapter.print_collection(fields, data) }
|
70
|
-
out.must_match(/.*Id.*/)
|
70
|
+
_(out).must_match(/.*Id.*/)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -76,12 +76,12 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
76
76
|
|
77
77
|
it "should print headers by default" do
|
78
78
|
out, _ = capture_io { adapter.print_collection(fields, data) }
|
79
|
-
out.must_match(/.*Name.*/)
|
79
|
+
_(out).must_match(/.*Name.*/)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should print headers by default even if there is no data" do
|
83
83
|
out, _ = capture_io { adapter.print_collection(fields, empty_data) }
|
84
|
-
out.must_match(/.*Name.*/)
|
84
|
+
_(out).must_match(/.*Name.*/)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should print data only when --no-headers is set" do
|
@@ -90,13 +90,13 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
90
90
|
"",
|
91
91
|
].join("\n")
|
92
92
|
adapter = HammerCLI::Output::Adapter::CSValues.new( { :no_headers => true } )
|
93
|
-
|
93
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should print nothing when --no-headers is set but no data" do
|
97
97
|
expected_output = "\n"
|
98
98
|
adapter = HammerCLI::Output::Adapter::CSValues.new( { :no_headers => true } )
|
99
|
-
|
99
|
+
_{ adapter.print_collection(fields, empty_data) }.must_output(expected_output)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -127,14 +127,14 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
127
127
|
|
128
128
|
it "should print column names" do
|
129
129
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
130
|
-
out.must_match(/.*Demographics::Age,Demographics::Gender,Biometrics::Weight,Biometrics::Height*/)
|
131
|
-
err.must_match(//)
|
130
|
+
_(out).must_match(/.*Demographics::Age,Demographics::Gender,Biometrics::Weight,Biometrics::Height*/)
|
131
|
+
_(err).must_match(//)
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should print data" do
|
135
135
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
136
|
-
out.must_match(/.*2000,22,m,123,155*/)
|
137
|
-
err.must_match(//)
|
136
|
+
_(out).must_match(/.*2000,22,m,123,155*/)
|
137
|
+
_(err).must_match(//)
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -167,28 +167,28 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
167
167
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
168
168
|
|
169
169
|
lines = out.split("\n")
|
170
|
-
lines[0].must_equal 'Name,Started At,Items::Item Name::1,Items::Item Quantity::1,Items::Item Name::2,Items::Item Quantity::2'
|
170
|
+
_(lines[0]).must_equal 'Name,Started At,Items::Item Name::1,Items::Item Quantity::1,Items::Item Name::2,Items::Item Quantity::2'
|
171
171
|
|
172
|
-
err.must_match(//)
|
172
|
+
_(err).must_match(//)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "should print collection data" do
|
176
176
|
out, err = capture_io { adapter.print_collection(fields, data) }
|
177
177
|
lines = out.split("\n")
|
178
178
|
|
179
|
-
lines[1].must_equal 'John Doe,2000,hammer,100,"",""'
|
180
|
-
lines[2].must_equal 'Jane Roe,2001,cleaver,1,sledge,50'
|
179
|
+
_(lines[1]).must_equal 'John Doe,2000,hammer,100,"",""'
|
180
|
+
_(lines[2]).must_equal 'Jane Roe,2001,cleaver,1,sledge,50'
|
181
181
|
|
182
|
-
err.must_match(//)
|
182
|
+
_(err).must_match(//)
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should handle empty collection" do
|
186
186
|
out, err = capture_io { adapter.print_collection(fields, []) }
|
187
187
|
lines = out.split("\n")
|
188
188
|
|
189
|
-
lines[0].must_equal 'Name,Started At,Items'
|
189
|
+
_(lines[0]).must_equal 'Name,Started At,Items'
|
190
190
|
|
191
|
-
err.must_match(//)
|
191
|
+
_(err).must_match(//)
|
192
192
|
end
|
193
193
|
|
194
194
|
end
|
@@ -203,7 +203,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
203
203
|
|
204
204
|
adapter = HammerCLI::Output::Adapter::CSValues.new({}, { :Field => [ DotFormatter.new ]})
|
205
205
|
out, _ = capture_io { adapter.print_collection(fields, data) }
|
206
|
-
out.must_match(/.*-DOT-.*/)
|
206
|
+
_(out).must_match(/.*-DOT-.*/)
|
207
207
|
end
|
208
208
|
|
209
209
|
it "should not replace nil with empty string before it applies formatters" do
|
@@ -216,7 +216,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
216
216
|
adapter = HammerCLI::Output::Adapter::CSValues.new({}, { :Field => [ NilFormatter.new ]})
|
217
217
|
nil_data = HammerCLI::Output::RecordCollection.new [{ :name => nil }]
|
218
218
|
out, _ = capture_io { adapter.print_collection([field_name], nil_data) }
|
219
|
-
out.must_match(/.*NIL.*/)
|
219
|
+
_(out).must_match(/.*NIL.*/)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
@@ -239,7 +239,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
239
239
|
out, _err = capture_io do
|
240
240
|
adapter.print_collection(fields, collection_data)
|
241
241
|
end
|
242
|
-
out.must_equal(expected_output)
|
242
|
+
_(out).must_equal(expected_output)
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'prints first chunk' do
|
@@ -252,7 +252,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
252
252
|
fields, collection_data[0...10], current_chunk: :first
|
253
253
|
)
|
254
254
|
end
|
255
|
-
out.must_equal(expected_output)
|
255
|
+
_(out).must_equal(expected_output)
|
256
256
|
end
|
257
257
|
|
258
258
|
it 'prints another chunk' do
|
@@ -265,7 +265,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
265
265
|
fields, collection_data[10...20], current_chunk: :another
|
266
266
|
)
|
267
267
|
end
|
268
|
-
out.must_equal(expected_output)
|
268
|
+
_(out).must_equal(expected_output)
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'prints last chunk' do
|
@@ -278,7 +278,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
278
278
|
fields, collection_data[20...30], current_chunk: :last
|
279
279
|
)
|
280
280
|
end
|
281
|
-
out.must_equal(expected_output)
|
281
|
+
_(out).must_equal(expected_output)
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -291,7 +291,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
291
291
|
it "should not print to stdout when --output-file is set" do
|
292
292
|
fields = [field_name]
|
293
293
|
|
294
|
-
|
294
|
+
_{ adapter.print_collection(fields, data) }.must_output("")
|
295
295
|
end
|
296
296
|
|
297
297
|
it "should print to file if --output-file is set" do
|
@@ -300,7 +300,7 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
300
300
|
|
301
301
|
adapter.print_collection(fields, data)
|
302
302
|
tempfile.close
|
303
|
-
IO.read(tempfile.path).must_equal(expected_output)
|
303
|
+
_(IO.read(tempfile.path)).must_equal(expected_output)
|
304
304
|
end
|
305
305
|
|
306
306
|
end
|
@@ -310,17 +310,17 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
310
310
|
context "print message" do
|
311
311
|
|
312
312
|
it "shoud print a message" do
|
313
|
-
|
313
|
+
_{ adapter.print_message("SOME MESSAGE") }.must_output("Message\nSOME MESSAGE\n", "")
|
314
314
|
end
|
315
315
|
|
316
316
|
it "should print message, id and name of created/updated record" do
|
317
|
-
|
317
|
+
_{
|
318
318
|
adapter.print_message("SOME MESSAGE", "id" => 83, "name" => "new_record")
|
319
319
|
}.must_output("Message,Id,Name\nSOME MESSAGE,83,new_record\n", "")
|
320
320
|
end
|
321
321
|
|
322
322
|
it 'should print message with nil params' do
|
323
|
-
|
323
|
+
_{ adapter.print_message('MESSAGE', nil) }.must_output("Message\nMESSAGE\n", '')
|
324
324
|
end
|
325
325
|
end
|
326
326
|
|
@@ -6,7 +6,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
6
6
|
let(:adapter) { HammerCLI::Output::Adapter::Json.new(context, HammerCLI::Output::Output.formatters) }
|
7
7
|
|
8
8
|
it "forbids default pagination" do
|
9
|
-
adapter.paginate_by_default
|
9
|
+
_(adapter.paginate_by_default?).must_equal false
|
10
10
|
end
|
11
11
|
|
12
12
|
context "print_message" do
|
@@ -20,7 +20,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
20
20
|
''
|
21
21
|
].join("\n")
|
22
22
|
|
23
|
-
|
23
|
+
_{ adapter.print_message(msg, params) }.must_output(expected_output)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "prints the message with name and id" do
|
@@ -35,7 +35,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
35
35
|
''
|
36
36
|
].join("\n")
|
37
37
|
|
38
|
-
|
38
|
+
_{ adapter.print_message(msg, params) }.must_output(expected_output)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'prints the message with nil params' do
|
@@ -47,14 +47,14 @@ describe HammerCLI::Output::Adapter::Json do
|
|
47
47
|
'}',
|
48
48
|
''
|
49
49
|
].join("\n")
|
50
|
-
|
50
|
+
_{ adapter.print_message(msg, params) }.must_output(expected_output)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
context "print_collection" do
|
55
55
|
|
56
56
|
let(:id) { Fields::Id.new(:path => [:id], :label => "Id") }
|
57
|
-
let(:
|
57
|
+
let(:firstname) { Fields::Field.new(:path => [:name], :label => "Name") }
|
58
58
|
let(:unlabeled) { Fields::Field.new(:path => [:name]) }
|
59
59
|
let(:surname) { Fields::Field.new(:path => [:surname], :label => "Surname") }
|
60
60
|
let(:address_city) { Fields::Field.new(:path => [:address, :city], :label => "City") }
|
@@ -109,16 +109,16 @@ describe HammerCLI::Output::Adapter::Json do
|
|
109
109
|
}]}
|
110
110
|
|
111
111
|
it "should print one field" do
|
112
|
-
fields = [
|
112
|
+
fields = [firstname]
|
113
113
|
expected_output = JSON.pretty_generate([{ 'Name' => 'John' }]) + "\n"
|
114
|
-
|
114
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should field with nested data" do
|
118
118
|
fields = [address_city]
|
119
119
|
expected_output = JSON.pretty_generate([{ 'City' => 'New York' }]) + "\n"
|
120
120
|
|
121
|
-
|
121
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should print labeled fields" do
|
@@ -130,7 +130,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
130
130
|
}
|
131
131
|
}]
|
132
132
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
133
|
-
|
133
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should print collection" do
|
@@ -150,7 +150,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
150
150
|
}]
|
151
151
|
|
152
152
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
153
|
-
|
153
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should print collection with one element" do
|
@@ -166,7 +166,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
166
166
|
}]
|
167
167
|
|
168
168
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
169
|
-
|
169
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should print unnumbered collection" do
|
@@ -185,7 +185,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
185
185
|
}]
|
186
186
|
|
187
187
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
188
|
-
|
188
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should print unnumbered collection with one element" do
|
@@ -200,24 +200,24 @@ describe HammerCLI::Output::Adapter::Json do
|
|
200
200
|
}]
|
201
201
|
|
202
202
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
203
|
-
|
203
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
204
204
|
end
|
205
205
|
|
206
206
|
|
207
207
|
it "hides ids by default" do
|
208
|
-
fields = [id,
|
208
|
+
fields = [id, firstname]
|
209
209
|
hash = [{'Name' => 'John'}]
|
210
210
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
211
211
|
|
212
|
-
|
212
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
213
213
|
end
|
214
214
|
|
215
215
|
it "skips blank values" do
|
216
|
-
fields = [
|
216
|
+
fields = [firstname, blank]
|
217
217
|
hash = [{'Name' => 'John'}]
|
218
218
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
219
219
|
|
220
|
-
|
220
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
221
221
|
end
|
222
222
|
|
223
223
|
it "does not print fields which data are missing from api by default" do
|
@@ -225,7 +225,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
225
225
|
hash = [{ 'Surname' => 'Doe' }]
|
226
226
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
227
227
|
|
228
|
-
|
228
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
229
229
|
end
|
230
230
|
|
231
231
|
it "prints fields which data are missing from api when field has hide_missing flag set to false" do
|
@@ -233,7 +233,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
233
233
|
hash = [{ 'Surname' => 'Doe', 'Missing' => '' }]
|
234
234
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
235
235
|
|
236
|
-
|
236
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
237
237
|
end
|
238
238
|
|
239
239
|
it "should print key -> value" do
|
@@ -254,11 +254,11 @@ describe HammerCLI::Output::Adapter::Json do
|
|
254
254
|
}]
|
255
255
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
256
256
|
|
257
|
-
|
257
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
258
258
|
end
|
259
259
|
|
260
260
|
context 'capitalization' do
|
261
|
-
let(:fields) { [
|
261
|
+
let(:fields) { [firstname, surname] }
|
262
262
|
let(:raw_hash) { { 'Name' => 'John', 'Surname' => 'Doe' } }
|
263
263
|
let(:settings) { HammerCLI::Settings }
|
264
264
|
let(:context) { { :capitalization => HammerCLI.capitalization } }
|
@@ -270,7 +270,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
270
270
|
out, = capture_io do
|
271
271
|
adapter.print_collection(fields, data)
|
272
272
|
end
|
273
|
-
out.must_equal(expected_output)
|
273
|
+
_(out).must_equal(expected_output)
|
274
274
|
end
|
275
275
|
|
276
276
|
it 'should respect selected capitalize capitalization' do
|
@@ -280,7 +280,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
280
280
|
out, = capture_io do
|
281
281
|
adapter.print_collection(fields, data)
|
282
282
|
end
|
283
|
-
out.must_equal(expected_output)
|
283
|
+
_(out).must_equal(expected_output)
|
284
284
|
end
|
285
285
|
|
286
286
|
it 'should respect selected upcase capitalization' do
|
@@ -290,7 +290,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
290
290
|
out, = capture_io do
|
291
291
|
adapter.print_collection(fields, data)
|
292
292
|
end
|
293
|
-
out.must_equal(expected_output)
|
293
|
+
_(out).must_equal(expected_output)
|
294
294
|
end
|
295
295
|
|
296
296
|
it 'should print a warn for not supported capitalization' do
|
@@ -301,8 +301,8 @@ describe HammerCLI::Output::Adapter::Json do
|
|
301
301
|
out, err = capture_io do
|
302
302
|
adapter.print_collection(fields, data)
|
303
303
|
end
|
304
|
-
out.must_equal(expected_output)
|
305
|
-
err.must_equal(expected_error)
|
304
|
+
_(out).must_equal(expected_output)
|
305
|
+
_(err).must_equal(expected_error)
|
306
306
|
end
|
307
307
|
|
308
308
|
it "shouldn't change capitalization if wasn't selected" do
|
@@ -312,7 +312,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
312
312
|
out, = capture_io do
|
313
313
|
adapter.print_collection(fields, data)
|
314
314
|
end
|
315
|
-
out.must_equal(expected_output)
|
315
|
+
_(out).must_equal(expected_output)
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
@@ -328,7 +328,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
328
328
|
let(:collection_data) do
|
329
329
|
HammerCLI::Output::RecordCollection.new(collection)
|
330
330
|
end
|
331
|
-
let(:fields) { [id,
|
331
|
+
let(:fields) { [id, firstname] }
|
332
332
|
|
333
333
|
before do
|
334
334
|
settings.load(ui: { capitalization: :downcase })
|
@@ -340,7 +340,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
340
340
|
out, _err = capture_io do
|
341
341
|
adapter.print_collection(fields, collection_data)
|
342
342
|
end
|
343
|
-
out.must_equal(expected_output)
|
343
|
+
_(out).must_equal(expected_output)
|
344
344
|
end
|
345
345
|
|
346
346
|
it 'prints first chunk' do
|
@@ -351,7 +351,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
351
351
|
fields, collection_data[0...10], current_chunk: :first
|
352
352
|
)
|
353
353
|
end
|
354
|
-
out.must_equal(expected_output)
|
354
|
+
_(out).must_equal(expected_output)
|
355
355
|
end
|
356
356
|
|
357
357
|
it 'prints another chunk' do
|
@@ -362,7 +362,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
362
362
|
fields, collection_data[10...20], current_chunk: :another
|
363
363
|
)
|
364
364
|
end
|
365
|
-
out.must_equal(expected_output)
|
365
|
+
_(out).must_equal(expected_output)
|
366
366
|
end
|
367
367
|
|
368
368
|
it 'prints last chunk' do
|
@@ -373,7 +373,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
373
373
|
fields, collection_data[20...30], current_chunk: :last
|
374
374
|
)
|
375
375
|
end
|
376
|
-
out.must_equal(expected_output)
|
376
|
+
_(out).must_equal(expected_output)
|
377
377
|
end
|
378
378
|
end
|
379
379
|
|
@@ -382,13 +382,13 @@ describe HammerCLI::Output::Adapter::Json do
|
|
382
382
|
let(:context) { {:show_ids => true} }
|
383
383
|
|
384
384
|
it "shows ids if it's required in the context" do
|
385
|
-
fields = [id,
|
385
|
+
fields = [id, firstname]
|
386
386
|
hash = [{
|
387
387
|
'Id' => 112,
|
388
388
|
'Name' => 'John'
|
389
389
|
}]
|
390
390
|
expected_output = JSON.pretty_generate(hash) + "\n"
|
391
|
-
|
391
|
+
_{ adapter.print_collection(fields, data) }.must_output(expected_output)
|
392
392
|
end
|
393
393
|
|
394
394
|
end
|
@@ -399,13 +399,13 @@ describe HammerCLI::Output::Adapter::Json do
|
|
399
399
|
let(:context) { {:output_file => tempfile} }
|
400
400
|
|
401
401
|
it "should not print to stdout when --output-file is set" do
|
402
|
-
fields = [
|
402
|
+
fields = [firstname]
|
403
403
|
|
404
|
-
|
404
|
+
_{ adapter.print_collection(fields, data) }.must_output("")
|
405
405
|
end
|
406
406
|
|
407
407
|
it "should print to file if --output-file is set" do
|
408
|
-
fields = [
|
408
|
+
fields = [firstname]
|
409
409
|
hash = [{
|
410
410
|
'Name' => 'John'
|
411
411
|
}]
|
@@ -413,7 +413,7 @@ describe HammerCLI::Output::Adapter::Json do
|
|
413
413
|
|
414
414
|
adapter.print_collection(fields, data)
|
415
415
|
tempfile.close
|
416
|
-
IO.read(tempfile.path).must_equal(expected_output)
|
416
|
+
_(IO.read(tempfile.path)).must_equal(expected_output)
|
417
417
|
end
|
418
418
|
|
419
419
|
end
|