utensils 2.0.0 → 2.1.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/lib/utensils/json.rb +55 -0
- data/lib/utensils/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 669775ae6fad4267c69b86b4fcdae65695f9ec30
|
4
|
+
data.tar.gz: eb40b1ebaa3662b60f2aa38be48ba2224b74ff53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd15961348ec8d665dcfd3eecc7a0416bb6c3ee99ef84d6334c69cd476febf13afa28837e3cdb1d557f7b065579e0a32a22dd1116c4492f09559540a2728b140
|
7
|
+
data.tar.gz: dbaec06277fca68c937e6eba86ea99478806363e197471323507f6492d4fca7ff37aef7325f2898a15e6cde8df47fdaff379a19b2efb59ff25139f46a9749b1a
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module JsonHelpers
|
2
|
+
def expect_json_response(path = nil)
|
3
|
+
expect(json_response(path))
|
4
|
+
end
|
5
|
+
|
6
|
+
def expect_json(body, path = nil)
|
7
|
+
expect(parse_json(body, path))
|
8
|
+
end
|
9
|
+
|
10
|
+
def json_response(path = nil)
|
11
|
+
parse_json(spec_type_agnostic_response_body, path)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def spec_type_agnostic_response_body
|
17
|
+
if respond_to?(:response_body)
|
18
|
+
response_body
|
19
|
+
else
|
20
|
+
response.body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Stolen from https://github.com/collectiveidea/json_spec/blob/00855fdd9c2f8a8794eb418419202dc85ce0fa23/lib/json_spec/helpers.rb
|
25
|
+
def parse_json(json, path = nil)
|
26
|
+
ruby = MultiJson.decode("[#{json}]").first
|
27
|
+
result = value_at_json_path(ruby, path)
|
28
|
+
|
29
|
+
if result.respond_to?(:with_indifferent_access)
|
30
|
+
result.with_indifferent_access
|
31
|
+
else
|
32
|
+
result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def value_at_json_path(ruby, path)
|
37
|
+
return ruby unless path
|
38
|
+
|
39
|
+
path.split("/").inject(ruby) do |value, key|
|
40
|
+
case value
|
41
|
+
when Hash
|
42
|
+
value.fetch(key) { "Couldn't find JSON path #{path}" }
|
43
|
+
when Array
|
44
|
+
raise "Couldn't find JSON path #{path}" unless key =~ /^\d+$/
|
45
|
+
value.fetch(key.to_i) { raise "Couldn't find JSON path #{path}" }
|
46
|
+
else
|
47
|
+
raise "Couldn't find JSON path #{path}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
RSpec.configure do |config|
|
54
|
+
config.include JsonHelpers
|
55
|
+
end
|
data/lib/utensils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utensils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rspec stuff we use over and over again
|
14
14
|
email:
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/utensils/database_cleaner.rb
|
31
31
|
- lib/utensils/email.rb
|
32
32
|
- lib/utensils/factory_bot.rb
|
33
|
+
- lib/utensils/json.rb
|
33
34
|
- lib/utensils/omniauth.rb
|
34
35
|
- lib/utensils/timecop.rb
|
35
36
|
- lib/utensils/upload_macros.rb
|
@@ -55,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
56
|
version: '0'
|
56
57
|
requirements: []
|
57
58
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.
|
59
|
+
rubygems_version: 2.6.13
|
59
60
|
signing_key:
|
60
61
|
specification_version: 4
|
61
62
|
summary: Rspec stuff we use over and over again
|