poller-json 0.1.1
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/lib/matchers/json/document_contains_json_path.rb +20 -0
- data/lib/matchers/json/json_path.rb +37 -0
- data/lib/matchers/json/json_path_has_array.rb +12 -0
- data/lib/matchers/json/json_path_has_object.rb +12 -0
- data/lib/matchers/json/json_path_has_value.rb +18 -0
- data/lib/poller/json/version.rb +5 -0
- data/lib/poller/poller_json.rb +7 -0
- metadata +117 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module Matchers
|
2
|
+
module JSON
|
3
|
+
class DocumentContainsJSONPath
|
4
|
+
include JSONPath
|
5
|
+
|
6
|
+
def initialize(json_path)
|
7
|
+
@json_path = json_path
|
8
|
+
end
|
9
|
+
|
10
|
+
# @param document_s [String] - the document given as String
|
11
|
+
# Exceptions caught by JSON Parserwill be thrown up the stack
|
12
|
+
# ::JSON::ParserError in the case of invalid JSON
|
13
|
+
def matches?(document_s)
|
14
|
+
json_hash = ::JSON.parse(document_s)
|
15
|
+
!value_on_path(json_hash, @json_path).nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This is by no means an implementation of JSONPath as outlined in
|
2
|
+
# http://goessner.net/articles/JsonPath/ and implemented in
|
3
|
+
# https://github.com/joshbuddy/jsonpath.
|
4
|
+
#
|
5
|
+
# Instead, the module can handle only a very limited subset of JSONPath and
|
6
|
+
# operates on a Hash (result of ::JSON.parse(document)). It makes sense in the
|
7
|
+
# context of poller-json and its current set of features.
|
8
|
+
|
9
|
+
module Matchers
|
10
|
+
module JSON
|
11
|
+
module JSONPath
|
12
|
+
def value_on_path(json_hash, path)
|
13
|
+
path = path[1..-1] if path.start_with?('$') # TODO: check jsonpath syntax and raise error
|
14
|
+
path_items = path.split('.')
|
15
|
+
child_node = json_hash
|
16
|
+
path_items.each do |path_item|
|
17
|
+
path_item = path_item.sub('[\'', '').sub('\']', '') if path_item.start_with?('[\'')
|
18
|
+
path_item, index = path_item.split('[')
|
19
|
+
begin
|
20
|
+
child_node = child_node.send(:fetch, path_item)
|
21
|
+
rescue IndexError
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
if index
|
25
|
+
index = index[0..-2].to_i
|
26
|
+
begin
|
27
|
+
child_node = child_node.send(:fetch, index)
|
28
|
+
rescue IndexError
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
child_node
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Matchers
|
2
|
+
module JSON
|
3
|
+
class JSONPathHasValue
|
4
|
+
include JSONPath
|
5
|
+
|
6
|
+
def initialize(json_path, value)
|
7
|
+
@json_path = json_path
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(document_s)
|
12
|
+
json_hash = ::JSON.parse(document_s)
|
13
|
+
value_on_path(json_hash, @json_path) == @value
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poller-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Markus Krogemann
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: poller
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.7.2
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.7.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.13.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.13.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.7.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.7.1
|
78
|
+
description: JSON matchers that can be used on top of the 'poller' gem
|
79
|
+
email:
|
80
|
+
- markus@krogemann.de
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- lib/matchers/json/document_contains_json_path.rb
|
86
|
+
- lib/matchers/json/json_path.rb
|
87
|
+
- lib/matchers/json/json_path_has_array.rb
|
88
|
+
- lib/matchers/json/json_path_has_object.rb
|
89
|
+
- lib/matchers/json/json_path_has_value.rb
|
90
|
+
- lib/poller/json/version.rb
|
91
|
+
- lib/poller/poller_json.rb
|
92
|
+
homepage: https://github.com/mkrogemann/poller-json
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.25
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: JSON matchers
|
117
|
+
test_files: []
|