kronk 1.2.5 → 1.3.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.
- data/.gemtest +0 -0
- data/History.rdoc +30 -2
- data/Manifest.txt +14 -0
- data/README.rdoc +5 -7
- data/Rakefile +88 -4
- data/bin/kronk +2 -1
- data/bin/yzma +13 -0
- data/lib/kronk.rb +112 -430
- data/lib/kronk/cmd.rb +469 -0
- data/lib/kronk/data_set.rb +38 -44
- data/lib/kronk/diff.rb +105 -112
- data/lib/kronk/diff/ascii_format.rb +35 -0
- data/lib/kronk/diff/color_format.rb +49 -0
- data/lib/kronk/request.rb +6 -6
- data/lib/kronk/test.rb +15 -0
- data/lib/kronk/test/assertions.rb +97 -0
- data/lib/kronk/test/core_ext.rb +65 -0
- data/lib/kronk/test/helper_methods.rb +86 -0
- data/lib/yzma.rb +174 -0
- data/lib/yzma/randomizer.rb +54 -0
- data/lib/yzma/report.rb +47 -0
- data/test/test_assertions.rb +93 -0
- data/test/test_core_ext.rb +74 -0
- data/test/test_data_set.rb +41 -32
- data/test/test_diff.rb +50 -24
- data/test/test_helper_methods.rb +177 -0
- data/test/test_kronk.rb +3 -1
- metadata +36 -19
@@ -0,0 +1,54 @@
|
|
1
|
+
class Yzma
|
2
|
+
|
3
|
+
##
|
4
|
+
# Randomizes params, data, and headers for Yzma requests.
|
5
|
+
|
6
|
+
class Randomizer
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@options = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def to_options
|
14
|
+
@options.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def randomize_param name, values, options={}
|
19
|
+
@options[:query] ||= {}
|
20
|
+
assign_random @options[:query], name, values, options
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def randomize_data name, values, options={}
|
25
|
+
@options[:data] ||= {}
|
26
|
+
assign_random @options[:data], name, values, options
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def randomize_header name, values, options={}
|
31
|
+
@options[:headers] ||= {}
|
32
|
+
assign_random @options[:headers], name, values, options
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def assign_random obj, key, values, options={}
|
37
|
+
random_value = pick_random values, options
|
38
|
+
obj[key] = random_value if random_value
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def pick_random val, options={}
|
43
|
+
val = File.readlines val if String === val
|
44
|
+
val = val.to_a if Range === val
|
45
|
+
|
46
|
+
val << "" if options[:allow_blank]
|
47
|
+
val << nil if options[:optional]
|
48
|
+
|
49
|
+
return if val.empty?
|
50
|
+
|
51
|
+
val[rand(val.length)]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/yzma/report.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Yzma
|
2
|
+
|
3
|
+
##
|
4
|
+
# Used to build and display Yzma reports.
|
5
|
+
# Other report types can be created by inheriting this class and
|
6
|
+
# overridding the 'write' method to use @data as desired.
|
7
|
+
|
8
|
+
class Report
|
9
|
+
|
10
|
+
attr_accessor :data, :header, :footer, :name
|
11
|
+
|
12
|
+
def initialize name
|
13
|
+
@name = name
|
14
|
+
@data = []
|
15
|
+
@header = ["#{@name} #{Time.now}"]
|
16
|
+
@footer = ["\n"]
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
##
|
21
|
+
# Adds data and a related piece of data identification to
|
22
|
+
# the report.
|
23
|
+
|
24
|
+
def add identifier, data
|
25
|
+
@data << [identifier, data]
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
##
|
30
|
+
# Generates and writes the report to the given IO instance.
|
31
|
+
# Defaults to STDOUT.
|
32
|
+
|
33
|
+
def write io=$stdout
|
34
|
+
io << @header.join("\n")
|
35
|
+
|
36
|
+
@data.each do |identifier, data|
|
37
|
+
if block_given?
|
38
|
+
io << yield(identifier, data)
|
39
|
+
else
|
40
|
+
io << "\n#{identifier.inspect}\n#{data.inspect}\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
io << @footer.join("\n")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'lib/kronk/test/assertions'
|
3
|
+
|
4
|
+
class TestAssertions < Test::Unit::TestCase
|
5
|
+
include Kronk::Test::Assertions
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@array = [:a, :b, {:foo => "bar", :bar => [:a, :b, {:foo => "other"}]}, :c]
|
9
|
+
@hash = {:foo => "bar", :bar => [:a, :b, {:foo => "other"}], :a => [1,2,3]}
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def test_assert_data_at
|
14
|
+
assert_data_at @array, "2/bar/2"
|
15
|
+
assert_data_at @hash, "bar/2"
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_assert_data_at_failure
|
20
|
+
self.expects(:assert).with(false, "OOPS")
|
21
|
+
assert_data_at @array, "foobar", "OOPS"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_assert_no_data_at
|
26
|
+
assert_no_data_at @array, "foobar"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def test_assert_no_data_at_failure
|
31
|
+
self.expects(:assert).with(false, "OOPS")
|
32
|
+
assert_no_data_at @array, "**/foo", "OOPS"
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_assert_data_at_equal
|
37
|
+
assert_data_at_equal @array, "2/bar/2/foo", "other"
|
38
|
+
assert_data_at_equal @hash, "bar/2/foo", "other"
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def test_assert_data_at_equal_failure
|
43
|
+
self.expects(:assert).with(false, "OOPS")
|
44
|
+
self.expects(:assert_equal).with("nodice", nil, "OOPS")
|
45
|
+
assert_data_at_equal @array, "foobar", "nodice", "OOPS"
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def test_assert_data_at_not_equal
|
50
|
+
assert_data_at_not_equal @array, "foobar", "thing"
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_assert_data_at_not_equal_failure
|
55
|
+
self.expects(:assert_not_equal).with("bar", "bar", "OOPS")
|
56
|
+
assert_data_at_not_equal @array, "**/foo", "bar", "OOPS"
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def test_assert_equal_responses
|
61
|
+
io = StringIO.new mock_resp("200_response.json")
|
62
|
+
mock_resp = Kronk::Response.read_new io
|
63
|
+
|
64
|
+
Kronk::Request.expects(:retrieve).times(2).
|
65
|
+
with("host.com", :foo => "bar").returns mock_resp
|
66
|
+
|
67
|
+
assert_equal_responses "host.com", "host.com", :foo => "bar"
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def test_assert_equal_responses_failure
|
72
|
+
mock_resp1 = Kronk::Response.read_new \
|
73
|
+
StringIO.new mock_resp("200_response.json")
|
74
|
+
|
75
|
+
mock_resp2 = Kronk::Response.read_new \
|
76
|
+
StringIO.new mock_resp("301_response.txt")
|
77
|
+
|
78
|
+
Kronk::Request.expects(:retrieve).
|
79
|
+
with("host1.com", :foo => "bar").returns mock_resp1
|
80
|
+
|
81
|
+
Kronk::Request.expects(:retrieve).
|
82
|
+
with("host2.com", :foo => "bar").returns mock_resp2
|
83
|
+
|
84
|
+
left = Kronk::Diff.ordered_data_string mock_resp1.selective_data
|
85
|
+
right = mock_resp2.body
|
86
|
+
|
87
|
+
assert_not_equal left, right
|
88
|
+
|
89
|
+
self.expects(:assert_equal).with left, right
|
90
|
+
|
91
|
+
assert_equal_responses "host1.com", "host2.com", :foo => "bar"
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'lib/kronk/test/core_ext'
|
3
|
+
|
4
|
+
class TestCoreExt < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@array = [:a, :b, {:foo => "bar", :bar => [:a, :b, {:foo => "other"}]}, :c]
|
8
|
+
@hash = {:foo => "bar", :bar => [:a, :b, {:foo => "other"}], :a => [1,2,3]}
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def test_has_path_array
|
13
|
+
assert @array.has_path?("**/foo")
|
14
|
+
assert @array.has_path?("**/foo=other")
|
15
|
+
assert_nil @array.has_path?("**/foobar")
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_has_path_hash
|
20
|
+
assert @hash.has_path?("**/foo")
|
21
|
+
assert @hash.has_path?("**/foo=other")
|
22
|
+
assert_nil @hash.has_path?("**/foobar")
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def test_find_data_array
|
27
|
+
out = @array.find_data "**/foo"
|
28
|
+
assert_equal({[2, :foo] => "bar", [2, :bar, 2, :foo] => "other"}, out)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_find_data_array_empty
|
33
|
+
out = @array.find_data "**/foobar"
|
34
|
+
assert_equal({}, out)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_find_data_array_block
|
39
|
+
collected = []
|
40
|
+
|
41
|
+
@array.find_data "**/foo" do |data, key, path|
|
42
|
+
collected << [data, key, path]
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_equal 2, collected.length
|
46
|
+
assert collected.include?([@array[2], :foo, [2, :foo]])
|
47
|
+
assert collected.include?([@array[2][:bar][2], :foo, [2, :bar, 2, :foo]])
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def test_find_data_hash
|
52
|
+
out = @hash.find_data "**/foo"
|
53
|
+
assert_equal({[:foo] => "bar", [:bar, 2, :foo] => "other"}, out)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_find_data_hash_empty
|
58
|
+
out = @hash.find_data "**/foobar"
|
59
|
+
assert_equal({}, out)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def test_find_data_hash_block
|
64
|
+
collected = []
|
65
|
+
|
66
|
+
@hash.find_data "**/foo" do |data, key, path|
|
67
|
+
collected << [data, key, path]
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_equal 2, collected.length
|
71
|
+
assert collected.include?([@hash, :foo, [:foo]])
|
72
|
+
assert collected.include?([@hash[:bar][2], :foo, [:bar, 2, :foo]])
|
73
|
+
end
|
74
|
+
end
|
data/test/test_data_set.rb
CHANGED
@@ -284,7 +284,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
284
284
|
|
285
285
|
def test_parse_data_path
|
286
286
|
data_path = "key1/key\\/2=value/key*=*value/**=value2/key\\=thing"
|
287
|
-
key, value, rec, data_path =
|
287
|
+
key, value, rec, data_path = @dataset.parse_data_path data_path
|
288
288
|
|
289
289
|
assert_equal "key1", key
|
290
290
|
assert_nil value
|
@@ -295,7 +295,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
295
295
|
|
296
296
|
def test_parse_data_path_escaped_slash
|
297
297
|
key, value, rec, data_path =
|
298
|
-
|
298
|
+
@dataset.parse_data_path \
|
299
299
|
"key\\/2=value/key*=*value/**=value2/key\\=thing"
|
300
300
|
|
301
301
|
assert_equal "key/2", key
|
@@ -306,9 +306,9 @@ class TestDataSet < Test::Unit::TestCase
|
|
306
306
|
|
307
307
|
|
308
308
|
def test_parse_data_path_wildcard
|
309
|
-
key, value, rec, data_path =
|
309
|
+
key, value, rec, data_path = @dataset.parse_data_path "*/key1?"
|
310
310
|
|
311
|
-
assert_equal(/^(.*)
|
311
|
+
assert_equal(/^(.*)$/i, key)
|
312
312
|
assert_nil value
|
313
313
|
assert !rec, "Should not return recursive = true"
|
314
314
|
assert_equal "key1?", data_path
|
@@ -317,7 +317,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
317
317
|
|
318
318
|
def test_parse_data_path_recursive_value
|
319
319
|
key, value, rec, data_path =
|
320
|
-
|
320
|
+
@dataset.parse_data_path "**=value2/key\\=thing"
|
321
321
|
|
322
322
|
assert_equal(/.*/, key)
|
323
323
|
assert_equal "value2", value
|
@@ -328,7 +328,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
328
328
|
|
329
329
|
def test_parse_data_path_recursive
|
330
330
|
data_path = "**"
|
331
|
-
key, value, rec, data_path =
|
331
|
+
key, value, rec, data_path = @dataset.parse_data_path "**"
|
332
332
|
|
333
333
|
assert_equal(/.*/, key)
|
334
334
|
assert_nil value
|
@@ -339,7 +339,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
339
339
|
|
340
340
|
def test_parse_data_path_recursive_key
|
341
341
|
data_path = "**"
|
342
|
-
key, value, rec, data_path =
|
342
|
+
key, value, rec, data_path = @dataset.parse_data_path "**/key"
|
343
343
|
|
344
344
|
assert_equal "key", key
|
345
345
|
assert_nil value
|
@@ -349,7 +349,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
349
349
|
|
350
350
|
|
351
351
|
def test_parse_data_path_escaped_equal
|
352
|
-
key, value, rec, data_path =
|
352
|
+
key, value, rec, data_path = @dataset.parse_data_path "key\\=thing"
|
353
353
|
|
354
354
|
assert_equal "key=thing", key
|
355
355
|
assert_nil value
|
@@ -359,9 +359,9 @@ class TestDataSet < Test::Unit::TestCase
|
|
359
359
|
|
360
360
|
|
361
361
|
def test_parse_data_path_last
|
362
|
-
key, value, rec, data_path =
|
362
|
+
key, value, rec, data_path = @dataset.parse_data_path "key*"
|
363
363
|
|
364
|
-
assert_equal(/^(key.*)
|
364
|
+
assert_equal(/^(key.*)$/i, key)
|
365
365
|
assert_nil value
|
366
366
|
assert !rec, "Should not return recursive = true"
|
367
367
|
assert_equal nil, data_path
|
@@ -369,7 +369,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
369
369
|
|
370
370
|
|
371
371
|
def test_parse_data_path_empty
|
372
|
-
key, value, rec, data_path =
|
372
|
+
key, value, rec, data_path = @dataset.parse_data_path ""
|
373
373
|
|
374
374
|
assert_equal nil, key
|
375
375
|
assert_nil value
|
@@ -379,25 +379,29 @@ class TestDataSet < Test::Unit::TestCase
|
|
379
379
|
|
380
380
|
|
381
381
|
def test_parse_path_item
|
382
|
-
assert_equal "foo",
|
382
|
+
assert_equal "foo", @dataset.parse_path_item("foo")
|
383
383
|
|
384
|
-
assert_equal(/^(foo.*bar)
|
385
|
-
assert_equal(/^(foo|bar)
|
386
|
-
assert_equal(/^(foo.?bar)
|
384
|
+
assert_equal(/^(foo.*bar)$/i, @dataset.parse_path_item("foo*bar"))
|
385
|
+
assert_equal(/^(foo|bar)$/i, @dataset.parse_path_item("foo|bar"))
|
386
|
+
assert_equal(/^(foo.?bar)$/i, @dataset.parse_path_item("foo?bar"))
|
387
387
|
|
388
|
-
assert_equal(/^(foo.?\?bar)
|
389
|
-
assert_equal(/^(key.*)
|
388
|
+
assert_equal(/^(foo.?\?bar)$/i, @dataset.parse_path_item("foo?\\?bar"))
|
389
|
+
assert_equal(/^(key.*)$/i, @dataset.parse_path_item("key*"))
|
390
390
|
|
391
|
-
assert_equal "foo*bar",
|
392
|
-
assert_equal "foo|bar",
|
393
|
-
assert_equal "foo?bar",
|
391
|
+
assert_equal "foo*bar", @dataset.parse_path_item("foo\\*bar")
|
392
|
+
assert_equal "foo|bar", @dataset.parse_path_item("foo\\|bar")
|
393
|
+
assert_equal "foo?bar", @dataset.parse_path_item("foo\\?bar")
|
394
|
+
|
395
|
+
assert_equal 1..3, @dataset.parse_path_item("1..3")
|
396
|
+
assert_equal 1...3, @dataset.parse_path_item("1...3")
|
397
|
+
assert_equal 3...6, @dataset.parse_path_item("3,3")
|
394
398
|
end
|
395
399
|
|
396
400
|
|
397
401
|
def test_yield_data_points
|
398
402
|
keys = []
|
399
403
|
|
400
|
-
|
404
|
+
@dataset.yield_data_points @data, /key/ do |data, key|
|
401
405
|
keys << key.to_s
|
402
406
|
assert_equal @data, data
|
403
407
|
end
|
@@ -410,7 +414,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
410
414
|
keys = []
|
411
415
|
data_points = []
|
412
416
|
|
413
|
-
|
417
|
+
@dataset.yield_data_points @data, :findme, nil, true do |data, key|
|
414
418
|
keys << key.to_s
|
415
419
|
data_points << data
|
416
420
|
end
|
@@ -430,7 +434,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
430
434
|
keys = []
|
431
435
|
data_points = []
|
432
436
|
|
433
|
-
|
437
|
+
@dataset.yield_data_points @data, nil, "findme" do |data, key|
|
434
438
|
keys << key.to_s
|
435
439
|
data_points << data
|
436
440
|
end
|
@@ -438,7 +442,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
438
442
|
assert keys.empty?
|
439
443
|
assert data_points.empty?
|
440
444
|
|
441
|
-
|
445
|
+
@dataset.yield_data_points @data, nil, "findme", true do |data, key|
|
442
446
|
keys << key.to_s
|
443
447
|
data_points << data
|
444
448
|
end
|
@@ -449,14 +453,19 @@ class TestDataSet < Test::Unit::TestCase
|
|
449
453
|
|
450
454
|
|
451
455
|
def test_match_data_item
|
452
|
-
assert
|
453
|
-
assert
|
456
|
+
assert @dataset.match_data_item(:key, "key")
|
457
|
+
assert @dataset.match_data_item("key", :key)
|
458
|
+
|
459
|
+
assert @dataset.match_data_item(/key/, "foo_key")
|
460
|
+
assert !@dataset.match_data_item("foo_key", /key/)
|
461
|
+
assert @dataset.match_data_item(/key/, /key/)
|
454
462
|
|
455
|
-
assert
|
456
|
-
assert
|
463
|
+
assert @dataset.match_data_item(nil, "foo_key")
|
464
|
+
assert !@dataset.match_data_item("foo_key", nil)
|
457
465
|
|
458
|
-
assert
|
459
|
-
assert
|
466
|
+
assert @dataset.match_data_item(1..3, 1)
|
467
|
+
assert !@dataset.match_data_item(1, 1..3)
|
468
|
+
assert @dataset.match_data_item(1..3, 1..3)
|
460
469
|
end
|
461
470
|
|
462
471
|
|
@@ -470,7 +479,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
470
479
|
keys = []
|
471
480
|
values = []
|
472
481
|
|
473
|
-
|
482
|
+
@dataset.each_data_item hash do |key, val|
|
474
483
|
keys << key
|
475
484
|
values << val
|
476
485
|
end
|
@@ -486,7 +495,7 @@ class TestDataSet < Test::Unit::TestCase
|
|
486
495
|
keys = []
|
487
496
|
values = []
|
488
497
|
|
489
|
-
|
498
|
+
@dataset.each_data_item ary do |key, val|
|
490
499
|
keys << key
|
491
500
|
values << val
|
492
501
|
end
|