kronk 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,18 @@
1
- === 1.0.2 / 2010-12
1
+ === 1.0.3 / 2010-12-09
2
+
3
+ * Enhancements:
4
+
5
+ * Supports overriding the parser from the command line.
6
+
7
+ * Support for ignoring or collecting parents of matched data paths.
8
+
9
+ * Support for uri-specific options in the .kronk config.
10
+
11
+ * Bugfixes:
12
+
13
+ * Lines are displayed for non-diff requests.
14
+
15
+ === 1.0.2 / 2010-12-07
2
16
 
3
17
  * Enhancements:
4
18
 
data/Rakefile CHANGED
@@ -8,13 +8,13 @@ Hoe.plugin :isolate
8
8
  Hoe.spec 'kronk' do
9
9
  developer('Jeremie Castagna', 'yaksnrainbows@gmail.com')
10
10
 
11
- self.extra_deps << ['plist', '>=3.1.0']
12
- self.extra_deps << ['json', '>=1.2.0']
13
- self.extra_deps << ['nokogiri', '>=1.3.3']
14
- self.extra_deps << ['i18n', '>=0.5.0']
11
+ self.extra_deps << ['plist', '~>3.1.0']
12
+ self.extra_deps << ['json', '~>1.2']
13
+ self.extra_deps << ['nokogiri', '~>1.3']
14
+ self.extra_deps << ['i18n', '~>0.5']
15
15
  self.extra_deps << ['activesupport', '>=2.0.0']
16
16
 
17
- self.extra_dev_deps << ['mocha', '>=0.9.10']
17
+ self.extra_dev_deps << ['mocha', '~>0.9.10']
18
18
  end
19
19
 
20
20
  # vim: syntax=ruby
data/lib/kronk.rb CHANGED
@@ -17,7 +17,7 @@ require 'yaml'
17
17
  class Kronk
18
18
 
19
19
  # This gem's version.
20
- VERSION = '1.0.2'
20
+ VERSION = '1.0.3'
21
21
 
22
22
 
23
23
  require 'kronk/data_set'
@@ -51,7 +51,8 @@ class Kronk
51
51
  :diff_format => :ascii_diff,
52
52
  :show_lines => false,
53
53
  :cache_file => DEFAULT_CACHE_FILE,
54
- :requires => []
54
+ :requires => [],
55
+ :uri_options => {}
55
56
  }
56
57
 
57
58
 
@@ -69,6 +70,7 @@ class Kronk
69
70
  def self.load_config filepath=DEFAULT_CONFIG_FILE
70
71
  conf = YAML.load_file DEFAULT_CONFIG_FILE
71
72
  content_types = conf.delete :content_types
73
+ uri_options = conf.delete :uri_options
72
74
 
73
75
  if conf[:requires]
74
76
  requires = [*conf.delete(:requires)]
@@ -76,6 +78,8 @@ class Kronk
76
78
  self.config[:requires].concat requires
77
79
  end
78
80
 
81
+ self.config[:uri_options].merge! uri_options if uri_options
82
+
79
83
  self.config[:content_types].merge!(content_types) if content_types
80
84
  self.config.merge! conf
81
85
  end
@@ -132,6 +136,19 @@ class Kronk
132
136
  end
133
137
 
134
138
 
139
+ ##
140
+ # Returns config-defined options for a given uri.
141
+ # Returns empty Hash if none found.
142
+
143
+ def self.options_for_uri uri
144
+ config[:uri_options].each do |key, options|
145
+ return options if uri == key || uri =~ %r{#{key}}
146
+ end
147
+
148
+ Hash.new
149
+ end
150
+
151
+
135
152
  ##
136
153
  # Make requests, parse the responses and compare the data.
137
154
  # If the second argument is omitted or is passed :cache, will
@@ -142,8 +159,10 @@ class Kronk
142
159
  # :data:: Hash/String - the data to pass to the http request
143
160
  # :headers:: Hash - extra headers to pass to the request
144
161
  # :http_method:: Symbol - the http method to use; defaults to :get
162
+ # :only_data:: String/Array - extracts the data from given data paths
145
163
  # :ignore_data:: String/Array - defines which data points to exclude
146
164
  # :with_headers:: Bool/String/Array - defines which headers to include
165
+ # :parser:: Object - The parser to use for the body; default nil
147
166
  # :raw:: Bool - run diff on raw strings
148
167
  #
149
168
  # Returns a diff object.
@@ -164,10 +183,13 @@ class Kronk
164
183
  # Return a diff object from two responses' raw data.
165
184
 
166
185
  def self.raw_diff query1, query2, options={}
167
- resp1 = Request.retrieve query1, options
168
- resp2 = Request.retrieve query2, options
186
+ opts1 = options.merge options_for_uri(query1)
187
+ opts2 = options.merge options_for_uri(query2)
169
188
 
170
- Diff.new resp1.selective_string(options), resp2.selective_string(options)
189
+ resp1 = Request.retrieve query1, opts1
190
+ resp2 = Request.retrieve query2, opts2
191
+
192
+ Diff.new resp1.selective_string(opts1), resp2.selective_string(opts2)
171
193
  end
172
194
 
173
195
 
@@ -175,11 +197,14 @@ class Kronk
175
197
  # Return a diff object from two parsed responses.
176
198
 
177
199
  def self.data_diff query1, query2, options={}
178
- resp1 = Request.retrieve query1, options
179
- resp2 = Request.retrieve query2, options
200
+ opts1 = options.merge options_for_uri(query1)
201
+ opts2 = options.merge options_for_uri(query2)
202
+
203
+ resp1 = Request.retrieve query1, opts1
204
+ resp2 = Request.retrieve query2, opts2
180
205
 
181
- Diff.new_from_data resp1.selective_data(options),
182
- resp2.selective_data(options),
206
+ Diff.new_from_data resp1.selective_data(opts1),
207
+ resp2.selective_data(opts2),
183
208
  options
184
209
  end
185
210
 
@@ -215,11 +240,19 @@ class Kronk
215
240
  verbose "\n\nFound #{diff.count} diff(s).\n"
216
241
 
217
242
  elsif options[:raw]
218
- puts Request.retrieve(uri1, options).selective_string(options)
243
+ options = options.merge options_for_uri(uri1)
244
+
245
+ out = Request.retrieve(uri1, options).selective_string options
246
+ out = Diff.insert_line_nums out if config[:show_lines]
247
+ puts out
219
248
 
220
249
  else
250
+ options = options.merge options_for_uri(uri1)
251
+
221
252
  data = Request.retrieve(uri1, options).selective_data options
222
- puts Diff.ordered_data_string(data, options[:struct])
253
+ out = Diff.ordered_data_string data, options[:struct]
254
+ out = Diff.insert_line_nums out if config[:show_lines]
255
+ puts out
223
256
  end
224
257
 
225
258
  rescue Request::NotFoundError, Response::MissingParser => e
@@ -246,7 +279,7 @@ class Kronk
246
279
  :uris => []
247
280
  }
248
281
 
249
- options[:only_data], options[:ignore_data] = parse_data_path_args argv
282
+ options = parse_data_path_args options, argv
250
283
 
251
284
  opts = OptionParser.new do |opt|
252
285
  opt.program_name = File.basename $0
@@ -269,6 +302,8 @@ Kronk runs diffs against data from live and cached http responses.
269
302
 
270
303
  Arguments after -- will be used to focus the diff on specific data points.
271
304
  If the data paths start with a '-' the matched data points will be removed.
305
+ If the data paths start with a ":" the parent of the matched data is used.
306
+ The ':' and '-' modifiers may be used together in that order (':-').
272
307
 
273
308
  Options:
274
309
  STR
@@ -378,6 +413,12 @@ Kronk runs diffs against data from live and cached http responses.
378
413
  end
379
414
 
380
415
 
416
+ opt.on('--parser STR', String,
417
+ 'Override default parser') do |value|
418
+ options[:parser] = value
419
+ end
420
+
421
+
381
422
  opt.on('-V', '--verbose', 'Make the operation more talkative') do
382
423
  config[:verbose] = true
383
424
  end
@@ -404,23 +445,27 @@ Kronk runs diffs against data from live and cached http responses.
404
445
  # Searches ARGV and returns data paths to add or exclude in the diff.
405
446
  # Returns the array [only_paths, except_paths]
406
447
 
407
- def self.parse_data_path_args argv
408
- return unless argv.include? "--"
448
+ def self.parse_data_path_args options, argv
449
+ return options unless argv.include? "--"
409
450
 
410
451
  data_paths = argv.slice! argv.index("--")..-1
411
452
  data_paths.shift
412
453
 
413
- only_paths = nil
414
- except_paths = nil
415
-
416
454
  data_paths.each do |path|
417
455
  if path[0,1] == "-"
418
- (except_paths ||= []) << path[1..-1]
456
+ (options[:ignore_data] ||= []) << path[1..-1]
457
+
458
+ elsif path[0,2] == ":-"
459
+ (options[:ignore_data_with] ||= []) << path[2..-1]
460
+
461
+ elsif path[0,1] == ":"
462
+ (options[:only_data_with] ||= []) << path[1..-1]
463
+
419
464
  else
420
- (only_paths ||= []) << path
465
+ (options[:only_data] ||= []) << path
421
466
  end
422
467
  end
423
468
 
424
- [only_paths, except_paths]
469
+ options
425
470
  end
426
471
  end
@@ -12,10 +12,55 @@ class Kronk
12
12
  end
13
13
 
14
14
 
15
+ ##
16
+ # Retrieves the data at the given path array.
17
+
18
+ def data_at_path path
19
+ self.class.data_at_path @data, path
20
+ end
21
+
22
+
23
+ ##
24
+ # Checks if data is available at the given path.
25
+
26
+ def data_at_path? path
27
+ self.class.data_at_path? @data, path
28
+ end
29
+
30
+
31
+ ##
32
+ # Modify the data object by passing inclusive or exclusive data paths.
33
+ # Supports the following options:
34
+ # :only_data:: String/Array - keep data with that matches the paths
35
+ # :only_data_with:: String/Array - keep data with a matched child
36
+ # :ignore_data:: String/Array - remove data with that matches the paths
37
+ # :ignore_data_with:: String/Array - remove data with a matched child
38
+ #
39
+ # Note: the data is processed in the following order:
40
+ # * only_data_with
41
+ # * ignore_data_with
42
+ # * only_data
43
+ # * ignore_data
44
+
45
+ def modify options
46
+ collect_data_points options[:only_data_with], true if
47
+ options[:only_data_with]
48
+
49
+ delete_data_points options[:ignore_data_with], true if
50
+ options[:ignore_data_with]
51
+
52
+ collect_data_points options[:only_data] if options[:only_data]
53
+
54
+ delete_data_points options[:ignore_data] if options[:ignore_data]
55
+
56
+ @data
57
+ end
58
+
59
+
15
60
  ##
16
61
  # Keep only specific data points from the data structure.
17
62
 
18
- def collect_data_points data_paths
63
+ def collect_data_points data_paths, affect_parent=false
19
64
  new_data = @data.class.new
20
65
 
21
66
  [*data_paths].each do |data_path|
@@ -26,8 +71,13 @@ class Kronk
26
71
 
27
72
  path.each_with_index do |key, i|
28
73
 
29
- if i == path.length - 1
74
+ if i == path.length - 1 && !affect_parent
30
75
  new_curr_data[key] = curr_data[key]
76
+
77
+ elsif i == path.length - 2 && affect_parent
78
+ new_curr_data[key] = curr_data[key]
79
+ break
80
+
31
81
  else
32
82
  new_curr_data[key] ||= curr_data[key].class.new
33
83
  new_curr_data = new_curr_data[key]
@@ -44,12 +94,19 @@ class Kronk
44
94
  ##
45
95
  # Remove specific data points from the data structure.
46
96
 
47
- def delete_data_points data_paths
97
+ def delete_data_points data_paths, affect_parent=false
48
98
  [*data_paths].each do |data_path|
49
- find_data data_path do |obj, k, p|
50
- case obj
51
- when Hash then obj.delete k
52
- when Array then obj.delete_at k
99
+ find_data data_path do |obj, k, path|
100
+
101
+ if affect_parent && data_at_path?(path)
102
+ parent_data = data_at_path path[0..-3]
103
+ del_method = Array === parent_data ? :delete_at : :delete
104
+
105
+ parent_data.send del_method, path[-2]
106
+
107
+ else
108
+ del_method = Array === obj ? :delete_at : :delete
109
+ obj.send del_method, k
53
110
  end
54
111
  end
55
112
  end
@@ -100,6 +157,33 @@ class Kronk
100
157
  end
101
158
 
102
159
 
160
+ ##
161
+ # Checks if data is available at the given path.
162
+
163
+ def self.data_at_path? data, path
164
+ data_at_path(data, path)
165
+ true
166
+
167
+ rescue NoMethodError, TypeError
168
+ false
169
+ end
170
+
171
+
172
+ ##
173
+ # Retrieve the data at the given path array location.
174
+
175
+ def self.data_at_path data, path
176
+ curr = data
177
+ path.each do |p|
178
+ raise TypeError, "Expected instance of Array or Hash" unless
179
+ Array === curr || Hash === curr
180
+ curr = curr[p]
181
+ end
182
+
183
+ curr
184
+ end
185
+
186
+
103
187
  ##
104
188
  # Parses a given data point and returns an array with the following:
105
189
  # - Key to match
@@ -175,6 +259,8 @@ class Kronk
175
259
  found = match_data_item(mkey, key) &&
176
260
  match_data_item(mvalue, value)
177
261
 
262
+ #puts "Found: #{data.inspect} #{mkey.inspect} -> #{key.inspect}" if found
263
+
178
264
  yield data, key, curr_path if found
179
265
  yield_data_points data[key], mkey, mvalue, true, curr_path, &block if
180
266
  recursive
data/lib/kronk/diff.rb CHANGED
@@ -12,8 +12,13 @@ class Kronk
12
12
 
13
13
  class AsciiFormat
14
14
 
15
- def self.lines d_line, a_line, col_width
16
- "#{d_line.to_s.rjust(col_width)}|#{a_line.to_s.rjust(col_width)} "
15
+ def self.lines line_nums, col_width
16
+ out =
17
+ [*line_nums].map do |lnum|
18
+ lnum.to_s.rjust col_width
19
+ end.join "|"
20
+
21
+ "#{out} "
17
22
  end
18
23
 
19
24
 
@@ -38,11 +43,13 @@ class Kronk
38
43
 
39
44
  class ColorFormat
40
45
 
41
- def self.lines d_line, a_line, col_width
42
- d_line = d_line.to_s.rjust col_width
43
- a_line = a_line.to_s.rjust col_width
46
+ def self.lines line_nums, col_width
47
+ out =
48
+ [*line_nums].map do |lnum|
49
+ lnum.to_s.rjust col_width
50
+ end.join "\033[32m"
44
51
 
45
- "\033[7;31m#{d_line}\033[32m#{a_line.to_s.rjust(col_width)}\033[0m "
52
+ "\033[7;31m#{out}\033[0m "
46
53
  end
47
54
 
48
55
 
@@ -116,6 +123,23 @@ class Kronk
116
123
  end
117
124
 
118
125
 
126
+ ##
127
+ # Adds line numbers to each lines of a String.
128
+
129
+ def self.insert_line_nums str, formatter=nil
130
+ format = Diff.formatter formatter || Kronk.config[:diff_format]
131
+
132
+ out = ""
133
+ width = str.lines.count.to_s.length
134
+
135
+ str.split("\n").each_with_index do |line, i|
136
+ out << "#{format.lines(i+1, width)}#{line}\n"
137
+ end
138
+
139
+ out
140
+ end
141
+
142
+
119
143
  ##
120
144
  # Returns a formatter from a symbol or string. Returns nil if not found.
121
145
 
@@ -235,7 +259,7 @@ class Kronk
235
259
  line1 = line1.next
236
260
  line2 = line2.next
237
261
 
238
- lines = format.lines line1, line2, width if options[:show_lines]
262
+ lines = format.lines [line1, line2], width if options[:show_lines]
239
263
  "#{lines}#{format.common item}"
240
264
 
241
265
  when Array
@@ -243,13 +267,13 @@ class Kronk
243
267
 
244
268
  item[0] = item[0].map do |str|
245
269
  line1 = line1.next
246
- lines = format.lines line1, nil, width if options[:show_lines]
270
+ lines = format.lines [line1, nil], width if options[:show_lines]
247
271
  "#{lines}#{format.deleted str}"
248
272
  end
249
273
 
250
274
  item[1] = item[1].map do |str|
251
275
  line2 = line2.next
252
- lines = format.lines nil, line2, width if options[:show_lines]
276
+ lines = format.lines [nil, line2], width if options[:show_lines]
253
277
  "#{lines}#{format.added str}"
254
278
  end
255
279
 
@@ -87,6 +87,11 @@ class Kronk
87
87
  @parsed_body ||= nil
88
88
 
89
89
  return @parsed_body if @parsed_body && !parser
90
+
91
+ if String === parser
92
+ parser = Kronk.parser_for(parser) || Kronk.find_const(parser)
93
+ end
94
+
90
95
  parser ||= Kronk.parser_for self['Content-Type']
91
96
 
92
97
  raise MissingParser,
@@ -165,6 +170,7 @@ class Kronk
165
170
  # the response. Supports the following options:
166
171
  # :no_body:: Bool - Don't return the body; default nil
167
172
  # :with_headers:: Bool/String/Array - Return headers; default nil
173
+ # :parser:: Object - The parser to use for the body; default nil
168
174
  # :ignore_data:: String/Array - Removes the data from given data paths
169
175
  # :only_data:: String/Array - Extracts the data from given data paths
170
176
 
@@ -172,12 +178,7 @@ class Kronk
172
178
  data = nil
173
179
 
174
180
  unless options[:no_body]
175
- ds = DataSet.new parsed_body
176
-
177
- ds.collect_data_points options[:only_data] if options[:only_data]
178
- ds.delete_data_points options[:ignore_data] if options[:ignore_data]
179
-
180
- data = ds.data
181
+ data = DataSet.new(parsed_body(options[:parser])).modify options
181
182
  end
182
183
 
183
184
  if options[:with_headers]
@@ -31,6 +31,52 @@ class TestDataSet < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
 
34
+ def test_modify_only_data
35
+ data = @dataset_mock.modify :only_data => "subs/1"
36
+ assert_equal({"subs" => [nil, "b"]}, data)
37
+ end
38
+
39
+
40
+ def test_modify_ignore_data
41
+ data = @dataset_mock.modify :ignore_data => "subs/1"
42
+
43
+ expected = mock_data
44
+ expected['subs'].delete_at 1
45
+
46
+ assert_equal expected, data
47
+ end
48
+
49
+
50
+ def test_modify_only_data
51
+ data = @dataset_mock.modify :only_data => "subs/1"
52
+ assert_equal({"subs" => [nil, "b"]}, data)
53
+ end
54
+
55
+
56
+ def test_modify_only_and_ignored_data
57
+ data = @dataset_mock.modify :ignore_data => "subs/1", :only_data => "subs/1"
58
+ assert_equal({"subs" => [nil]}, data)
59
+ end
60
+
61
+
62
+ def test_collect_data_points_affect_parent_array
63
+ data = @dataset_mock.collect_data_points "**=(A|a)?", true
64
+
65
+ expected = {
66
+ "root" => [nil, ["A1", "A2"]],
67
+ "subs" => ["a", "b"]
68
+ }
69
+
70
+ assert_equal expected, data
71
+ end
72
+
73
+
74
+ def test_collect_data_points_affect_parent_hash
75
+ data = @dataset_mock.collect_data_points "**=bar?", true
76
+ assert_equal({"tests"=>{:foo=>:bar, "test"=>[[1, 2], 2.123]}}, data)
77
+ end
78
+
79
+
34
80
  def test_collect_data_points_single
35
81
  data = @dataset_mock.collect_data_points "subs/1"
36
82
  assert_equal({"subs" => [nil, "b"]}, data)
@@ -69,6 +115,47 @@ class TestDataSet < Test::Unit::TestCase
69
115
  end
70
116
 
71
117
 
118
+ def test_delete_data_points_affect_parent_array
119
+ data = @dataset_mock.delete_data_points "**/test/0/*", true
120
+
121
+ expected = mock_data
122
+ expected['root'][3]['test'].delete_at 0
123
+ expected['tests']['test'].delete_at 0
124
+
125
+ assert_equal expected, data
126
+ end
127
+
128
+
129
+ def test_delete_data_points_affect_parent_array_value
130
+ data = @dataset_mock.delete_data_points "**/test/0/*=D*", true
131
+
132
+ expected = mock_data
133
+ expected['root'][3]['test'].delete_at 0
134
+
135
+ assert_equal expected, data
136
+ end
137
+
138
+
139
+ def test_delete_data_points_affect_parent_hash
140
+ data = @dataset_mock.delete_data_points "subs/1", true
141
+
142
+ expected = mock_data
143
+ expected.delete 'subs'
144
+
145
+ assert_equal expected, data
146
+ end
147
+
148
+
149
+ def test_delete_data_points_affect_parent_hash_value
150
+ data = @dataset_mock.delete_data_points "**/*=a", true
151
+
152
+ expected = mock_data
153
+ expected.delete 'subs'
154
+
155
+ assert_equal expected, data
156
+ end
157
+
158
+
72
159
  def test_delete_data_points_single
73
160
  data = @dataset_mock.delete_data_points "subs/1"
74
161
 
data/test/test_kronk.rb CHANGED
@@ -13,7 +13,8 @@ class TestKronk < Test::Unit::TestCase
13
13
  :cache_file => Kronk::DEFAULT_CACHE_FILE,
14
14
  :diff_format => :ascii_diff,
15
15
  :show_lines => false,
16
- :requires => []
16
+ :requires => [],
17
+ :uri_options => {}
17
18
  }
18
19
 
19
20
  assert_equal expected, Kronk::DEFAULT_CONFIG
@@ -30,6 +31,7 @@ class TestKronk < Test::Unit::TestCase
30
31
  :cache_file => Kronk::DEFAULT_CACHE_FILE,
31
32
  :show_lines => false,
32
33
  :requires => [],
34
+ :uri_options => {'example.com' => {:parser => 'JSON'}},
33
35
  :foo => :bar
34
36
  }
35
37
 
@@ -51,6 +53,7 @@ class TestKronk < Test::Unit::TestCase
51
53
  :requires => [],
52
54
  :show_lines => false,
53
55
  :ignore_headers => ["Content-Type"],
56
+ :uri_options => {'example.com' => {:parser => 'JSON'}},
54
57
  :foo => :bar
55
58
  }
56
59
 
@@ -106,6 +109,20 @@ class TestKronk < Test::Unit::TestCase
106
109
  end
107
110
 
108
111
 
112
+ def test_options_for_uri
113
+ old_uri_opts = Kronk.config[:uri_options].dup
114
+ Kronk.config[:uri_options] = {
115
+ 'example' => 'options1',
116
+ 'example.com' => 'options2'
117
+ }
118
+
119
+ assert_equal 'options1', Kronk.options_for_uri("http://example.com/path")
120
+ assert_equal Hash.new, Kronk.options_for_uri("http://thing.com/path")
121
+
122
+ Kronk.config[:uri_options] = old_uri_opts
123
+ end
124
+
125
+
109
126
  def test_compare_raw
110
127
  diff = Kronk.compare "test/mocks/200_response.json",
111
128
  "test/mocks/200_response.xml",
@@ -145,6 +162,7 @@ class TestKronk < Test::Unit::TestCase
145
162
  assert_equal exp_diff.formatted, diff.formatted
146
163
  end
147
164
 
165
+
148
166
  def test_raw_diff
149
167
  diff = Kronk.raw_diff "test/mocks/200_response.json",
150
168
  "test/mocks/200_response.xml",
@@ -185,10 +203,16 @@ class TestKronk < Test::Unit::TestCase
185
203
 
186
204
 
187
205
  def test_parse_data_path_args
188
- argv = %w{this is --argv -- one -two -- -three four}
206
+ options = {}
207
+ argv = %w{this is --argv -- one -two -- -three four :parents :-not_parents}
208
+
209
+ options = Kronk.parse_data_path_args options, argv
210
+
211
+ assert_equal %w{one four}, options[:only_data]
212
+ assert_equal %w{two - three}, options[:ignore_data]
189
213
 
190
- assert_equal [%w{one four}, %w{two - three}],
191
- Kronk.parse_data_path_args(argv)
214
+ assert_equal %w{parents}, options[:only_data_with]
215
+ assert_equal %w{not_parents}, options[:ignore_data_with]
192
216
 
193
217
  assert_equal %w{this is --argv}, argv
194
218
  end
@@ -54,6 +54,18 @@ class TestResponse < Test::Unit::TestCase
54
54
  end
55
55
 
56
56
 
57
+ def test_parsed_body_string_parser
58
+ raw = File.read "test/mocks/200_response.json"
59
+ expected = JSON.parse raw.split("\r\n\r\n")[1]
60
+
61
+ assert_equal expected, @json_resp.parsed_body
62
+
63
+ assert_raises RuntimeError do
64
+ @json_resp.parsed_body 'PlistParser'
65
+ end
66
+ end
67
+
68
+
57
69
  def test_parsed_body_plist
58
70
  raw = File.read "test/mocks/200_response.plist"
59
71
  expected = Kronk::PlistParser.parse raw.split("\r\n\r\n")[1]
@@ -173,6 +185,15 @@ class TestResponse < Test::Unit::TestCase
173
185
  end
174
186
 
175
187
 
188
+ def test_selective_data_parser
189
+ assert_raises RuntimeError do
190
+ @json_resp.selective_data :parser => Kronk::PlistParser
191
+ end
192
+
193
+ assert @json_resp.selective_data(:parser => JSON)
194
+ end
195
+
196
+
176
197
  def test_selective_data_single_header
177
198
  body = JSON.parse @json_resp.body
178
199
  expected =
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 2
9
- version: 1.0.2
8
+ - 3
9
+ version: 1.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeremie Castagna
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-07 00:00:00 -08:00
17
+ date: 2010-12-09 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 3
@@ -38,13 +38,12 @@ dependencies:
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ">="
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
43
  segments:
44
44
  - 1
45
45
  - 2
46
- - 0
47
- version: 1.2.0
46
+ version: "1.2"
48
47
  type: :runtime
49
48
  version_requirements: *id002
50
49
  - !ruby/object:Gem::Dependency
@@ -53,13 +52,12 @@ dependencies:
53
52
  requirement: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
56
- - - ">="
55
+ - - ~>
57
56
  - !ruby/object:Gem::Version
58
57
  segments:
59
58
  - 1
60
59
  - 3
61
- - 3
62
- version: 1.3.3
60
+ version: "1.3"
63
61
  type: :runtime
64
62
  version_requirements: *id003
65
63
  - !ruby/object:Gem::Dependency
@@ -68,13 +66,12 @@ dependencies:
68
66
  requirement: &id004 !ruby/object:Gem::Requirement
69
67
  none: false
70
68
  requirements:
71
- - - ">="
69
+ - - ~>
72
70
  - !ruby/object:Gem::Version
73
71
  segments:
74
72
  - 0
75
73
  - 5
76
- - 0
77
- version: 0.5.0
74
+ version: "0.5"
78
75
  type: :runtime
79
76
  version_requirements: *id004
80
77
  - !ruby/object:Gem::Dependency
@@ -113,7 +110,7 @@ dependencies:
113
110
  requirement: &id007 !ruby/object:Gem::Requirement
114
111
  none: false
115
112
  requirements:
116
- - - ">="
113
+ - - ~>
117
114
  - !ruby/object:Gem::Version
118
115
  segments:
119
116
  - 0
@@ -186,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
183
  requirements:
187
184
  - - ">="
188
185
  - !ruby/object:Gem::Version
189
- hash: 1889693282695565885
186
+ hash: 2734576429023002030
190
187
  segments:
191
188
  - 0
192
189
  version: "0"