kronk 1.5.1 → 1.5.2
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 +17 -0
- data/Manifest.txt +2 -2
- data/lib/kronk/constants.rb +3 -0
- data/lib/kronk/core_ext.rb +110 -0
- data/lib/kronk/plist_parser.rb +4 -1
- data/lib/kronk/response.rb +17 -4
- data/lib/kronk/test/helper_methods.rb +14 -26
- data/lib/kronk/test.rb +1 -1
- data/lib/kronk/xml_parser.rb +1 -1
- data/lib/kronk.rb +53 -8
- data/test/test_core_ext.rb +1 -1
- data/test/test_helper_methods.rb +36 -35
- data/test/test_kronk.rb +50 -0
- data/test/test_response.rb +11 -4
- metadata +8 -45
- data/lib/kronk/test/core_ext.rb +0 -113
data/.gemtest
ADDED
File without changes
|
data/History.rdoc
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
=== 1.5.2 / 2011-08-15
|
2
|
+
|
3
|
+
* Enhancements:
|
4
|
+
|
5
|
+
* Moved kronk/test/core_ext to kronk/core_ext.
|
6
|
+
|
7
|
+
* Options that take a constant name now support passing a file path only,
|
8
|
+
or a Constant:file/path pair.
|
9
|
+
|
10
|
+
* Bugfixes:
|
11
|
+
|
12
|
+
* Fixed unsupported struct options in helper_methods.
|
13
|
+
|
14
|
+
* Handling of invalid parser errors.
|
15
|
+
|
16
|
+
* More explicit parser errors for unparsable strings.
|
17
|
+
|
1
18
|
=== 1.5.1 / 2011-08-12
|
2
19
|
|
3
20
|
* Bugfixes:
|
data/Manifest.txt
CHANGED
@@ -5,8 +5,9 @@ README.rdoc
|
|
5
5
|
Rakefile
|
6
6
|
bin/kronk
|
7
7
|
lib/kronk.rb
|
8
|
-
lib/kronk/constants.rb
|
9
8
|
lib/kronk/cmd.rb
|
9
|
+
lib/kronk/constants.rb
|
10
|
+
lib/kronk/core_ext.rb
|
10
11
|
lib/kronk/data_renderer.rb
|
11
12
|
lib/kronk/diff.rb
|
12
13
|
lib/kronk/diff/ascii_format.rb
|
@@ -25,7 +26,6 @@ lib/kronk/request.rb
|
|
25
26
|
lib/kronk/response.rb
|
26
27
|
lib/kronk/test.rb
|
27
28
|
lib/kronk/test/assertions.rb
|
28
|
-
lib/kronk/test/core_ext.rb
|
29
29
|
lib/kronk/test/helper_methods.rb
|
30
30
|
lib/kronk/xml_parser.rb
|
31
31
|
script/kronk_completion
|
data/lib/kronk/constants.rb
CHANGED
@@ -0,0 +1,110 @@
|
|
1
|
+
class Kronk
|
2
|
+
|
3
|
+
##
|
4
|
+
# Data manipulation and retrieval methods for Array and Hash classes.
|
5
|
+
|
6
|
+
module DataExt
|
7
|
+
|
8
|
+
##
|
9
|
+
# Checks if the given path exists and returns the first matching path
|
10
|
+
# as an array of keys. Returns false if no path is found.
|
11
|
+
|
12
|
+
def has_path? path
|
13
|
+
Kronk::Path.find path, self do |d,k,p|
|
14
|
+
return !!p
|
15
|
+
end
|
16
|
+
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
##
|
22
|
+
# Looks for data at paths matching path. Returns a hash of
|
23
|
+
# path array => data value pairs.
|
24
|
+
#
|
25
|
+
# If given a block will pass the parent data structure, the key
|
26
|
+
# or index of the item at given path, and the full path
|
27
|
+
# as an array of keys for each found path.
|
28
|
+
#
|
29
|
+
# data = {:foo => "bar", :foobar => [:a, :b, {:foo => "other bar"}, :c]}
|
30
|
+
# data.find_data "**/foo" do |parent, key, path|
|
31
|
+
# p path
|
32
|
+
# p parent[key]
|
33
|
+
# puts "---"
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # outputs:
|
37
|
+
# # [:foo]
|
38
|
+
# # "bar"
|
39
|
+
# # ---
|
40
|
+
# # [:foobar, 2, :foo]
|
41
|
+
# # "other bar"
|
42
|
+
# # ---
|
43
|
+
#
|
44
|
+
# # returns:
|
45
|
+
# # {[:foo] => "bar", [:foobar, 2, :foo] => "other bar"}
|
46
|
+
|
47
|
+
def find_data path, &block
|
48
|
+
Kronk::Path.find path, self, &block
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
##
|
53
|
+
# Finds and replaces the value of any match with the given new value.
|
54
|
+
# Returns true if matches were replaced, otherwise false.
|
55
|
+
#
|
56
|
+
# data = {:foo => "bar", :foobar => [:a, :b, {:foo => "other bar"}, :c]}
|
57
|
+
# data.replace_at_path "**=*bar", "BAR"
|
58
|
+
# #=> true
|
59
|
+
#
|
60
|
+
# data
|
61
|
+
# #=> {:foo => "BAR", :foobar => [:a, :b, {:foo => "BAR"}, :c]}
|
62
|
+
#
|
63
|
+
# Note: Specifying a limit will allow only "limit" number of items to be
|
64
|
+
# set but may yield unpredictible results for non-ordered Hashes.
|
65
|
+
# It's also important to realize that arrays are modified starting with
|
66
|
+
# the last index, going down.
|
67
|
+
|
68
|
+
def replace_at_path path, value, limit=nil
|
69
|
+
count = 0
|
70
|
+
|
71
|
+
Kronk::Path.find path, self do |data, key, path_arr|
|
72
|
+
count = count.next
|
73
|
+
data[key] = value
|
74
|
+
|
75
|
+
return true if limit && count >= limit
|
76
|
+
end
|
77
|
+
|
78
|
+
return count > 0
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
##
|
83
|
+
# Similar to DataExt#replace_at_path but deletes found items.
|
84
|
+
# Returns a hash of path/value pairs of deleted items.
|
85
|
+
#
|
86
|
+
# data = {:foo => "bar", :foobar => [:a, :b, {:foo => "other bar"}, :c]}
|
87
|
+
# data.replace_at_path "**=*bar", "BAR"
|
88
|
+
# #=> {[:foo] => "bar", [:foobar, 2, :foo] => "other bar"}
|
89
|
+
|
90
|
+
def delete_at_path path, limit=nil
|
91
|
+
count = 0
|
92
|
+
out = {}
|
93
|
+
|
94
|
+
Kronk::Path.find path, self do |data, key, path_arr|
|
95
|
+
count = count.next
|
96
|
+
out[path_arr] = data[key]
|
97
|
+
|
98
|
+
data.respond_to(:delete_at) ? data.delete_at(key) : data.delete(key)
|
99
|
+
|
100
|
+
return true if limit && count >= limit
|
101
|
+
end
|
102
|
+
|
103
|
+
return count > 0
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
Array.send :include, Kronk::DataExt
|
110
|
+
Hash.send :include, Kronk::DataExt
|
data/lib/kronk/plist_parser.rb
CHANGED
@@ -10,7 +10,10 @@ class Kronk
|
|
10
10
|
|
11
11
|
def self.parse plist
|
12
12
|
require 'plist'
|
13
|
-
Plist.parse_xml
|
13
|
+
Plist.parse_xml(plist) || raise(ParserError, "invalid Plist")
|
14
|
+
|
15
|
+
rescue RuntimeError
|
16
|
+
raise(ParserError, "unparsable Plist")
|
14
17
|
|
15
18
|
rescue LoadError => e
|
16
19
|
raise unless e.message =~ /-- plist/
|
data/lib/kronk/response.rb
CHANGED
@@ -12,12 +12,15 @@ class Kronk
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
|
15
16
|
##
|
16
|
-
#
|
17
|
+
# Standard Kronk response object.
|
17
18
|
|
18
19
|
class Response
|
19
20
|
|
20
21
|
class MissingParser < Exception; end
|
22
|
+
class InvalidParser < Exception; end
|
23
|
+
|
21
24
|
|
22
25
|
ENCODING_MATCHER = /(^|;\s?)charset=(.*?)\s*(;|$)/
|
23
26
|
|
@@ -84,6 +87,7 @@ class Kronk
|
|
84
87
|
@parser = Kronk.parser_for @_res['Content-Type']
|
85
88
|
|
86
89
|
@uri = @request.uri if @request && @request.uri
|
90
|
+
@uri = URI.parse io.path if File === io
|
87
91
|
|
88
92
|
@byterate = 0
|
89
93
|
end
|
@@ -152,16 +156,25 @@ class Kronk
|
|
152
156
|
|
153
157
|
return @parsed_body if @parsed_body && !parser
|
154
158
|
|
155
|
-
|
159
|
+
begin
|
156
160
|
parser = Kronk.parser_for(parser) || Kronk.find_const(parser)
|
157
|
-
|
161
|
+
rescue NameError
|
162
|
+
raise InvalidParser, "No such parser: #{parser}"
|
163
|
+
end if String === parser
|
158
164
|
|
159
165
|
parser ||= @parser
|
160
166
|
|
161
167
|
raise MissingParser,
|
162
168
|
"No parser for Content-Type: #{@_res['Content-Type']}" unless parser
|
163
169
|
|
164
|
-
|
170
|
+
begin
|
171
|
+
@parsed_body = parser.parse(self.body) or raise RuntimeError
|
172
|
+
|
173
|
+
rescue RuntimeError, ::Exception => e
|
174
|
+
msg = ParserError === e ? e.message : "#{parser} failed parsing body"
|
175
|
+
msg << " returned by #{@uri}" if @uri
|
176
|
+
raise ParserError, msg
|
177
|
+
end
|
165
178
|
end
|
166
179
|
|
167
180
|
|
@@ -4,7 +4,8 @@ class Kronk
|
|
4
4
|
|
5
5
|
##
|
6
6
|
# Kronk test helper methods to easily make and mock requests.
|
7
|
-
# Sets @responses, @response, @datas, @data, and @diff
|
7
|
+
# Sets @kronk, @responses, @response, @datas, @data, and @diff
|
8
|
+
# instance variables.
|
8
9
|
|
9
10
|
module HelperMethods
|
10
11
|
|
@@ -49,37 +50,24 @@ class Kronk
|
|
49
50
|
def retrieve uri1, uri2=nil, options={}
|
50
51
|
uri2, options = nil, uri2.merge(options) if Hash === uri2
|
51
52
|
|
52
|
-
|
53
|
-
@responses = [Kronk.retrieve(uri1, options),
|
54
|
-
Kronk.retrieve(uri2, options)]
|
55
|
-
@response = @responses.last
|
56
|
-
|
57
|
-
@datas = @responses.map do |r|
|
58
|
-
begin
|
59
|
-
r.selective_data options
|
60
|
-
rescue Kronk::Response::MissingParser
|
61
|
-
r.body
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
@data = @datas.last
|
66
|
-
|
67
|
-
@diff = Diff.new_from_data(*@datas)
|
53
|
+
@kronk = Kronk.new options
|
68
54
|
|
69
|
-
|
70
|
-
@response = Kronk.retrieve uri1, options
|
71
|
-
@responses = [@response]
|
55
|
+
uri2 ? @kronk.compare(uri1, uri2) : @kronk.retrieve(uri1)
|
72
56
|
|
73
|
-
|
74
|
-
|
57
|
+
@responses = @kronk.responses
|
58
|
+
@response = @kronk.response
|
59
|
+
@datas = @responses.map do |r|
|
60
|
+
begin
|
61
|
+
r.selective_data options
|
75
62
|
rescue Kronk::Response::MissingParser
|
76
|
-
|
63
|
+
r.body
|
77
64
|
end
|
65
|
+
end
|
78
66
|
|
79
|
-
|
67
|
+
@data = @datas.last
|
68
|
+
@diff = @kronk.diff
|
80
69
|
|
81
|
-
|
82
|
-
end
|
70
|
+
@kronk
|
83
71
|
end
|
84
72
|
end
|
85
73
|
end
|
data/lib/kronk/test.rb
CHANGED
data/lib/kronk/xml_parser.rb
CHANGED
data/lib/kronk.rb
CHANGED
@@ -14,7 +14,7 @@ require 'yaml'
|
|
14
14
|
class Kronk
|
15
15
|
|
16
16
|
# This gem's version.
|
17
|
-
VERSION = '1.5.
|
17
|
+
VERSION = '1.5.2'
|
18
18
|
|
19
19
|
require 'kronk/constants'
|
20
20
|
require 'kronk/player'
|
@@ -64,15 +64,60 @@ class Kronk
|
|
64
64
|
##
|
65
65
|
# Find a fully qualified ruby namespace/constant.
|
66
66
|
|
67
|
-
def self.find_const
|
68
|
-
|
69
|
-
|
67
|
+
def self.find_const name_or_file, case_insensitive=false
|
68
|
+
if name_or_file =~ /[^:]:([^:]+)$/
|
69
|
+
req_file = $1
|
70
|
+
i = $1.length + 2
|
71
|
+
const = name_or_file[0..-i]
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
begin
|
74
|
+
require req_file
|
75
|
+
rescue LoadError
|
76
|
+
require File.expand_path(req_file)
|
77
|
+
end
|
78
|
+
|
79
|
+
find_const const
|
80
|
+
|
81
|
+
elsif name_or_file.include? File::SEPARATOR
|
82
|
+
begin
|
83
|
+
require name_or_file
|
84
|
+
rescue LoadError
|
85
|
+
require File.expand_path(name_or_file)
|
86
|
+
end
|
87
|
+
|
88
|
+
namespace = File.basename name_or_file, ".rb"
|
89
|
+
consts = File.dirname(name_or_file).split(File::SEPARATOR)
|
90
|
+
consts << namespace
|
91
|
+
|
92
|
+
name = ""
|
93
|
+
until consts.empty?
|
94
|
+
name = "::" << consts.pop.to_s << name
|
95
|
+
const = find_const name, true rescue nil
|
96
|
+
return const if const
|
97
|
+
end
|
98
|
+
|
99
|
+
raise NameError, "no constant match for #{name_or_file}"
|
74
100
|
|
75
|
-
|
101
|
+
else
|
102
|
+
consts = name_or_file.to_s.split "::"
|
103
|
+
curr = self
|
104
|
+
|
105
|
+
until consts.empty? do
|
106
|
+
const = consts.shift
|
107
|
+
next if const.to_s.empty?
|
108
|
+
|
109
|
+
if case_insensitive
|
110
|
+
const.gsub!(/(^|[\-_.]+)([a-z0-9])/i){|m| m[-1,1].upcase}
|
111
|
+
const = (curr.constants | Object.constants).find do |c|
|
112
|
+
c.to_s.downcase == const.to_s.downcase
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
curr = curr.const_get const.to_s
|
117
|
+
end
|
118
|
+
|
119
|
+
curr
|
120
|
+
end
|
76
121
|
end
|
77
122
|
|
78
123
|
|
data/test/test_core_ext.rb
CHANGED
data/test/test_helper_methods.rb
CHANGED
@@ -10,60 +10,65 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
10
10
|
@mock_resp = Kronk::Response.new io
|
11
11
|
@mock_resp2 = Kronk::Response.new \
|
12
12
|
StringIO.new mock_resp("200_response.json")
|
13
|
+
@mock_req = stub("mock_req", :retrieve => @mock_resp, :uri => "host.com")
|
14
|
+
@mock_req2 = stub("mock_req", :retrieve => @mock_resp2, :uri => "host.com")
|
13
15
|
|
14
|
-
|
16
|
+
@mock_thread = stub("mock_thread", :join => nil)
|
17
|
+
|
18
|
+
Thread.stubs(:new).yields.returns @mock_thread
|
19
|
+
Kronk::Request.any_instance.stubs(:new).returns @mock_req
|
15
20
|
end
|
16
21
|
|
17
22
|
|
18
23
|
def test_get
|
19
|
-
Kronk.expects(:
|
24
|
+
Kronk::Request.expects(:new).
|
20
25
|
with("host.com", :foo => "bar", :http_method => :get).
|
21
|
-
returns @
|
26
|
+
returns @mock_req
|
22
27
|
|
23
28
|
get "host.com", :foo => "bar", :http_method => :foobar
|
24
29
|
end
|
25
30
|
|
26
31
|
|
27
32
|
def test_get_two
|
28
|
-
Kronk.expects(:
|
33
|
+
Kronk::Request.expects(:new).times(2).
|
29
34
|
with("host.com", :foo => "bar", :http_method => :get).
|
30
|
-
returns @
|
35
|
+
returns @mock_req
|
31
36
|
|
32
37
|
get "host.com", "host.com", :foo => "bar", :http_method => :foobar
|
33
38
|
end
|
34
39
|
|
35
40
|
|
36
41
|
def test_post
|
37
|
-
|
42
|
+
Kronk::Request.expects(:new).
|
38
43
|
with("host.com", :foo => "bar", :http_method => :post).
|
39
|
-
returns @
|
44
|
+
returns @mock_req
|
40
45
|
|
41
46
|
post "host.com", :foo => "bar", :http_method => :foobar
|
42
47
|
end
|
43
48
|
|
44
49
|
|
45
50
|
def test_post_two
|
46
|
-
Kronk.expects(:
|
51
|
+
Kronk::Request.expects(:new).times(2).
|
47
52
|
with("host.com", :foo => "bar", :http_method => :post).
|
48
|
-
returns @
|
53
|
+
returns @mock_req
|
49
54
|
|
50
55
|
post "host.com", "host.com", :foo => "bar", :http_method => :foobar
|
51
56
|
end
|
52
57
|
|
53
58
|
|
54
59
|
def test_put
|
55
|
-
Kronk.expects(:
|
60
|
+
Kronk::Request.expects(:new).
|
56
61
|
with("host.com", :foo => "bar", :http_method => :put).
|
57
|
-
returns @
|
62
|
+
returns @mock_req
|
58
63
|
|
59
64
|
put "host.com", :foo => "bar", :http_method => :foobar
|
60
65
|
end
|
61
66
|
|
62
67
|
|
63
68
|
def test_put_two
|
64
|
-
Kronk.expects(:
|
69
|
+
Kronk::Request.expects(:new).times(2).
|
65
70
|
with("host.com", :foo => "bar", :http_method => :put).
|
66
|
-
returns @
|
71
|
+
returns @mock_req
|
67
72
|
|
68
73
|
put "host.com", "host.com", :foo => "bar", :http_method => :foobar
|
69
74
|
end
|
@@ -71,26 +76,26 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
71
76
|
|
72
77
|
|
73
78
|
def test_delete
|
74
|
-
|
79
|
+
Kronk::Request.expects(:new).
|
75
80
|
with("host.com", :foo => "bar", :http_method => :delete).
|
76
|
-
returns @
|
81
|
+
returns @mock_req
|
77
82
|
|
78
83
|
delete "host.com", :foo => "bar", :http_method => :foobar
|
79
84
|
end
|
80
85
|
|
81
86
|
|
82
87
|
def test_delete_two
|
83
|
-
Kronk.expects(:
|
88
|
+
Kronk::Request.expects(:new).times(2).
|
84
89
|
with("host.com", :foo => "bar", :http_method => :delete).
|
85
|
-
returns @
|
90
|
+
returns @mock_req
|
86
91
|
|
87
92
|
delete "host.com", "host.com", :foo => "bar", :http_method => :foobar
|
88
93
|
end
|
89
94
|
|
90
95
|
|
91
96
|
def test_retrieve_one
|
92
|
-
Kronk.expects(:
|
93
|
-
with("host.com", :foo => "bar", :test => "thing").returns @
|
97
|
+
Kronk::Request.expects(:new).
|
98
|
+
with("host.com", :foo => "bar", :test => "thing").returns @mock_req
|
94
99
|
|
95
100
|
@mock_resp.expects(:selective_data).with(:foo => "bar", :test => "thing").
|
96
101
|
returns @json
|
@@ -108,15 +113,14 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
108
113
|
|
109
114
|
|
110
115
|
def test_retrieve_two
|
111
|
-
Kronk.expects(:
|
112
|
-
with("host1.com", :foo => "bar").returns @
|
113
|
-
|
114
|
-
Kronk.expects(:retrieve).
|
115
|
-
with("host2.com", :foo => "bar").returns @mock_resp2
|
116
|
+
Kronk::Request.expects(:new).
|
117
|
+
with("host1.com", :foo => "bar").returns @mock_req
|
116
118
|
|
117
|
-
|
119
|
+
Kronk::Request.expects(:new).
|
120
|
+
with("host2.com", :foo => "bar").returns @mock_req2
|
118
121
|
|
119
|
-
@
|
122
|
+
@mock_resp.expects(:selective_data).twice.with(:foo => "bar").returns @json
|
123
|
+
@mock_resp2.expects(:selective_data).twice.with(:foo => "bar").returns @json
|
120
124
|
|
121
125
|
retrieve "host1.com", "host2.com", :foo => "bar"
|
122
126
|
|
@@ -135,9 +139,10 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
135
139
|
|
136
140
|
def test_retrieve_unparsable
|
137
141
|
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
142
|
+
mock_req = stub("mock_req", :retrieve => mock_resp, :uri => "host.com")
|
138
143
|
|
139
|
-
Kronk.expects(:
|
140
|
-
with("host.com", :foo => "bar").returns
|
144
|
+
Kronk::Request.expects(:new).
|
145
|
+
with("host.com", :foo => "bar").returns mock_req
|
141
146
|
|
142
147
|
retrieve "host.com", :foo => "bar"
|
143
148
|
|
@@ -154,12 +159,8 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
154
159
|
def test_retrieve_two_unparsable
|
155
160
|
mock_resp = Kronk::Response.new StringIO.new(mock_200_response)
|
156
161
|
|
157
|
-
Kronk.expects(:retrieve).
|
158
|
-
|
159
|
-
|
160
|
-
Kronk.expects(:retrieve).
|
161
|
-
with("host2.com", :foo => "bar").returns mock_resp
|
162
|
-
|
162
|
+
Kronk::Request.any_instance.expects(:retrieve).returns mock_resp
|
163
|
+
Kronk::Request.any_instance.expects(:retrieve).returns mock_resp
|
163
164
|
|
164
165
|
retrieve "host1.com", "host2.com", :foo => "bar"
|
165
166
|
|
@@ -169,7 +170,7 @@ class TestHelperMethods < Test::Unit::TestCase
|
|
169
170
|
assert_equal mock_resp.body, @data
|
170
171
|
assert_equal [mock_resp.body, mock_resp.body], @datas
|
171
172
|
|
172
|
-
expected_diff = Kronk::Diff.
|
173
|
+
expected_diff = Kronk::Diff.new(*@datas)
|
173
174
|
|
174
175
|
assert_equal expected_diff.str1, @diff.str1
|
175
176
|
assert_equal expected_diff.str2, @diff.str2
|
data/test/test_kronk.rb
CHANGED
@@ -132,6 +132,56 @@ class TestKronk < Test::Unit::TestCase
|
|
132
132
|
end
|
133
133
|
|
134
134
|
|
135
|
+
def test_find_const_file
|
136
|
+
$".delete_if{|path| path =~ %r{kronk/diff/ascii_format.rb}}
|
137
|
+
Kronk::Diff.send(:remove_const, :AsciiFormat)
|
138
|
+
assert_raises(NameError){ Kronk::Diff::AsciiFormat }
|
139
|
+
|
140
|
+
Kronk.find_const 'kronk/diff/ascii_format'
|
141
|
+
assert Kronk::Diff::AsciiFormat
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
def test_find_const_file_rb
|
146
|
+
$".delete_if{|path| path =~ %r{kronk/diff/ascii_format.rb}}
|
147
|
+
Kronk::Diff.send(:remove_const, :AsciiFormat)
|
148
|
+
assert_raises(NameError){ Kronk::Diff::AsciiFormat }
|
149
|
+
|
150
|
+
Kronk.find_const 'kronk/diff/ascii_format.rb'
|
151
|
+
assert Kronk::Diff::AsciiFormat
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def test_find_const_file_pair
|
156
|
+
$".delete_if{|path| path =~ %r{kronk/diff/ascii_format.rb}}
|
157
|
+
Kronk::Diff.send(:remove_const, :AsciiFormat)
|
158
|
+
assert_raises(NameError){ Kronk::Diff::AsciiFormat }
|
159
|
+
|
160
|
+
Kronk.find_const 'Kronk::Diff::AsciiFormat:kronk/diff/ascii_format'
|
161
|
+
assert Kronk::Diff::AsciiFormat
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
def test_find_const_file_pair_rb
|
166
|
+
$".delete_if{|path| path =~ %r{kronk/diff/ascii_format.rb}}
|
167
|
+
Kronk::Diff.send(:remove_const, :AsciiFormat)
|
168
|
+
assert_raises(NameError){ Kronk::Diff::AsciiFormat }
|
169
|
+
|
170
|
+
Kronk.find_const 'Kronk::Diff::AsciiFormat:kronk/diff/ascii_format.rb'
|
171
|
+
assert Kronk::Diff::AsciiFormat
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
def test_find_const_file_pair_rb_expanded
|
176
|
+
$".delete_if{|path| path =~ %r{kronk/diff/ascii_format.rb}}
|
177
|
+
Kronk::Diff.send(:remove_const, :AsciiFormat)
|
178
|
+
assert_raises(NameError){ Kronk::Diff::AsciiFormat }
|
179
|
+
|
180
|
+
Kronk.find_const 'Kronk::Diff::AsciiFormat:lib/kronk/diff/ascii_format.rb'
|
181
|
+
assert Kronk::Diff::AsciiFormat
|
182
|
+
end
|
183
|
+
|
184
|
+
|
135
185
|
def test_options_for_uri
|
136
186
|
with_uri_options do
|
137
187
|
assert_equal mock_uri_options['example'],
|
data/test/test_response.rb
CHANGED
@@ -106,7 +106,7 @@ class TestResponse < Test::Unit::TestCase
|
|
106
106
|
assert_equal expected, @json_resp.parsed_body
|
107
107
|
assert_equal @xml_resp.parsed_body, @json_resp.parsed_body
|
108
108
|
|
109
|
-
assert_raises
|
109
|
+
assert_raises Kronk::ParserError do
|
110
110
|
@json_resp.parsed_body Kronk::PlistParser
|
111
111
|
end
|
112
112
|
end
|
@@ -118,7 +118,7 @@ class TestResponse < Test::Unit::TestCase
|
|
118
118
|
|
119
119
|
assert_equal expected, @json_resp.parsed_body
|
120
120
|
|
121
|
-
assert_raises
|
121
|
+
assert_raises Kronk::ParserError do
|
122
122
|
@json_resp.parsed_body 'PlistParser'
|
123
123
|
end
|
124
124
|
end
|
@@ -149,8 +149,15 @@ class TestResponse < Test::Unit::TestCase
|
|
149
149
|
end
|
150
150
|
|
151
151
|
|
152
|
+
def test_parsed_body_invalid_parser
|
153
|
+
assert_raises Kronk::Response::InvalidParser do
|
154
|
+
@html_resp.parsed_body "FooBar"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
|
152
159
|
def test_parsed_body_bad_parser
|
153
|
-
assert_raises
|
160
|
+
assert_raises Kronk::ParserError do
|
154
161
|
@html_resp.parsed_body JSON
|
155
162
|
end
|
156
163
|
end
|
@@ -244,7 +251,7 @@ class TestResponse < Test::Unit::TestCase
|
|
244
251
|
|
245
252
|
|
246
253
|
def test_selective_data_parser
|
247
|
-
assert_raises
|
254
|
+
assert_raises Kronk::ParserError do
|
248
255
|
@json_resp.selective_data :parser => Kronk::PlistParser
|
249
256
|
end
|
250
257
|
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kronk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 1
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 1
|
10
|
-
version: 1.5.1
|
5
|
+
version: 1.5.2
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Jeremie Castagna
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-08-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-08-17 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
16
|
name: json
|
@@ -26,10 +20,6 @@ dependencies:
|
|
26
20
|
requirements:
|
27
21
|
- - ~>
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 5
|
33
23
|
version: "1.5"
|
34
24
|
type: :runtime
|
35
25
|
version_requirements: *id001
|
@@ -41,11 +31,6 @@ dependencies:
|
|
41
31
|
requirements:
|
42
32
|
- - ~>
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 19
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 3
|
48
|
-
- 0
|
49
34
|
version: 0.3.0
|
50
35
|
type: :runtime
|
51
36
|
version_requirements: *id002
|
@@ -57,11 +42,6 @@ dependencies:
|
|
57
42
|
requirements:
|
58
43
|
- - ~>
|
59
44
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 3
|
63
|
-
- 1
|
64
|
-
- 0
|
65
45
|
version: 3.1.0
|
66
46
|
type: :development
|
67
47
|
version_requirements: *id003
|
@@ -73,10 +53,6 @@ dependencies:
|
|
73
53
|
requirements:
|
74
54
|
- - ~>
|
75
55
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 7
|
77
|
-
segments:
|
78
|
-
- 1
|
79
|
-
- 4
|
80
56
|
version: "1.4"
|
81
57
|
type: :development
|
82
58
|
version_requirements: *id004
|
@@ -88,11 +64,6 @@ dependencies:
|
|
88
64
|
requirements:
|
89
65
|
- - ~>
|
90
66
|
- !ruby/object:Gem::Version
|
91
|
-
hash: 35
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
- 9
|
95
|
-
- 12
|
96
67
|
version: 0.9.12
|
97
68
|
type: :development
|
98
69
|
version_requirements: *id005
|
@@ -104,12 +75,7 @@ dependencies:
|
|
104
75
|
requirements:
|
105
76
|
- - ">="
|
106
77
|
- !ruby/object:Gem::Version
|
107
|
-
|
108
|
-
segments:
|
109
|
-
- 2
|
110
|
-
- 8
|
111
|
-
- 0
|
112
|
-
version: 2.8.0
|
78
|
+
version: 2.9.1
|
113
79
|
type: :development
|
114
80
|
version_requirements: *id006
|
115
81
|
description: |-
|
@@ -133,8 +99,9 @@ files:
|
|
133
99
|
- Rakefile
|
134
100
|
- bin/kronk
|
135
101
|
- lib/kronk.rb
|
136
|
-
- lib/kronk/constants.rb
|
137
102
|
- lib/kronk/cmd.rb
|
103
|
+
- lib/kronk/constants.rb
|
104
|
+
- lib/kronk/core_ext.rb
|
138
105
|
- lib/kronk/data_renderer.rb
|
139
106
|
- lib/kronk/diff.rb
|
140
107
|
- lib/kronk/diff/ascii_format.rb
|
@@ -153,7 +120,6 @@ files:
|
|
153
120
|
- lib/kronk/response.rb
|
154
121
|
- lib/kronk/test.rb
|
155
122
|
- lib/kronk/test/assertions.rb
|
156
|
-
- lib/kronk/test/core_ext.rb
|
157
123
|
- lib/kronk/test/helper_methods.rb
|
158
124
|
- lib/kronk/xml_parser.rb
|
159
125
|
- script/kronk_completion
|
@@ -180,7 +146,7 @@ files:
|
|
180
146
|
- test/test_response.rb
|
181
147
|
- test/test_transaction.rb
|
182
148
|
- test/test_xml_parser.rb
|
183
|
-
|
149
|
+
- .gemtest
|
184
150
|
homepage: https://github.com/yaksnrainbows/kronk
|
185
151
|
licenses: []
|
186
152
|
|
@@ -195,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
161
|
requirements:
|
196
162
|
- - ">="
|
197
163
|
- !ruby/object:Gem::Version
|
198
|
-
hash:
|
164
|
+
hash: -1250647076143869812
|
199
165
|
segments:
|
200
166
|
- 0
|
201
167
|
version: "0"
|
@@ -204,14 +170,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
170
|
requirements:
|
205
171
|
- - ">="
|
206
172
|
- !ruby/object:Gem::Version
|
207
|
-
hash: 3
|
208
|
-
segments:
|
209
|
-
- 0
|
210
173
|
version: "0"
|
211
174
|
requirements: []
|
212
175
|
|
213
176
|
rubyforge_project: kronk
|
214
|
-
rubygems_version: 1.
|
177
|
+
rubygems_version: 1.8.6
|
215
178
|
signing_key:
|
216
179
|
specification_version: 3
|
217
180
|
summary: Kronk runs diffs against data from live and cached http responses
|
data/lib/kronk/test/core_ext.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
class Kronk
|
2
|
-
|
3
|
-
module Test
|
4
|
-
|
5
|
-
##
|
6
|
-
# Data manipulation and retrieval methods for Array and Hash classes.
|
7
|
-
|
8
|
-
module DataExt
|
9
|
-
|
10
|
-
##
|
11
|
-
# Checks if the given path exists and returns the first matching path
|
12
|
-
# as an array of keys. Returns false if no path is found.
|
13
|
-
|
14
|
-
def has_path? path
|
15
|
-
Kronk::Path.find path, self do |d,k,p|
|
16
|
-
return !!p
|
17
|
-
end
|
18
|
-
|
19
|
-
false
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
##
|
24
|
-
# Looks for data at paths matching path. Returns a hash of
|
25
|
-
# path array => data value pairs.
|
26
|
-
#
|
27
|
-
# If given a block will pass the parent data structure, the key
|
28
|
-
# or index of the item at given path, and the full path
|
29
|
-
# as an array of keys for each found path.
|
30
|
-
#
|
31
|
-
# data = {:foo => "bar", :foobar => [:a, :b, {:foo => "other bar"}, :c]}
|
32
|
-
# data.find_data "**/foo" do |parent, key, path|
|
33
|
-
# p path
|
34
|
-
# p parent[key]
|
35
|
-
# puts "---"
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# # outputs:
|
39
|
-
# # [:foo]
|
40
|
-
# # "bar"
|
41
|
-
# # ---
|
42
|
-
# # [:foobar, 2, :foo]
|
43
|
-
# # "other bar"
|
44
|
-
# # ---
|
45
|
-
#
|
46
|
-
# # returns:
|
47
|
-
# # {[:foo] => "bar", [:foobar, 2, :foo] => "other bar"}
|
48
|
-
|
49
|
-
def find_data path, &block
|
50
|
-
Kronk::Path.find path, self, &block
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
##
|
55
|
-
# Finds and replaces the value of any match with the given new value.
|
56
|
-
# Returns true if matches were replaced, otherwise false.
|
57
|
-
#
|
58
|
-
# data = {:foo => "bar", :foobar => [:a, :b, {:foo => "other bar"}, :c]}
|
59
|
-
# data.replace_at_path "**=*bar", "BAR"
|
60
|
-
# #=> true
|
61
|
-
#
|
62
|
-
# data
|
63
|
-
# #=> {:foo => "BAR", :foobar => [:a, :b, {:foo => "BAR"}, :c]}
|
64
|
-
#
|
65
|
-
# Note: Specifying a limit will allow only "limit" number of items to be
|
66
|
-
# set but may yield unpredictible results for non-ordered Hashes.
|
67
|
-
# It's also important to realize that arrays are modified starting with
|
68
|
-
# the last index, going down.
|
69
|
-
|
70
|
-
def replace_at_path path, value, limit=nil
|
71
|
-
count = 0
|
72
|
-
|
73
|
-
Kronk::Path.find path, self do |data, key, path_arr|
|
74
|
-
count = count.next
|
75
|
-
data[key] = value
|
76
|
-
|
77
|
-
return true if limit && count >= limit
|
78
|
-
end
|
79
|
-
|
80
|
-
return count > 0
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
##
|
85
|
-
# Similar to DataExt#replace_at_path but deletes found items.
|
86
|
-
# Returns a hash of path/value pairs of deleted items.
|
87
|
-
#
|
88
|
-
# data = {:foo => "bar", :foobar => [:a, :b, {:foo => "other bar"}, :c]}
|
89
|
-
# data.replace_at_path "**=*bar", "BAR"
|
90
|
-
# #=> {[:foo] => "bar", [:foobar, 2, :foo] => "other bar"}
|
91
|
-
|
92
|
-
def delete_at_path path, limit=nil
|
93
|
-
count = 0
|
94
|
-
out = {}
|
95
|
-
|
96
|
-
Kronk::Path.find path, self do |data, key, path_arr|
|
97
|
-
count = count.next
|
98
|
-
out[path_arr] = data[key]
|
99
|
-
|
100
|
-
data.respond_to(:delete_at) ? data.delete_at(key) : data.delete(key)
|
101
|
-
|
102
|
-
return true if limit && count >= limit
|
103
|
-
end
|
104
|
-
|
105
|
-
return count > 0
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
Array.send :include, Kronk::Test::DataExt
|
113
|
-
Hash.send :include, Kronk::Test::DataExt
|