rester 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rester/client/adapters/stub_adapter.rb +24 -23
- data/lib/rester/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a486ccadfe2ebef7a59324907fd282d8895a6e6c
|
4
|
+
data.tar.gz: cfeda2d0d5d1f029ef4108d1855c017803de5446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 456cd0d730812c7b1f643bda679c45ad83e83f091ab3cc2a59d2040044bdcc7e17ceed70aacc38272b620617e8efbbc76656bf9a3ca69c291fe2a458af5076c2
|
7
|
+
data.tar.gz: 5e930154548a07aafe4e828c92a1a70b1655657701b2968eabace6d733c40700c2858ff9131ccc01194a6dcba9c494e845ea9e48a890af121233a22f28552812
|
@@ -41,49 +41,50 @@ module Rester
|
|
41
41
|
_request('DELETE', path, params)
|
42
42
|
end
|
43
43
|
|
44
|
-
def context
|
45
|
-
@_context
|
46
|
-
end
|
47
|
-
|
48
|
-
def context=(context)
|
49
|
-
@_context = context
|
50
|
-
end
|
51
|
-
|
52
44
|
def with_context(context, &block)
|
53
|
-
|
45
|
+
@_context = context
|
54
46
|
yield block
|
55
|
-
|
47
|
+
@_context = nil
|
56
48
|
end
|
57
49
|
|
58
50
|
private
|
59
51
|
|
60
52
|
def _request(verb, path, params)
|
61
|
-
|
62
|
-
|
63
|
-
# At this point, the 'request' is valid by matching a corresponding
|
64
|
-
# request in the stub yaml file. Grab the response from the file and
|
65
|
-
# reset the context
|
66
|
-
response = stub[path][verb][context]['response']
|
67
|
-
context = nil
|
53
|
+
response = _process_request(path, verb, params)
|
68
54
|
[response['code'], response['body'].to_json]
|
69
55
|
end
|
70
56
|
|
71
|
-
def
|
57
|
+
def _process_request(path, verb, params)
|
72
58
|
fail Errors::StubError, "#{path} not found" unless stub[path]
|
73
59
|
fail Errors::StubError, "#{verb} #{path} not found" unless stub[path][verb]
|
74
60
|
|
61
|
+
context = @_context || _find_context_by_params(path, verb, params)
|
62
|
+
|
75
63
|
unless (action = stub[path][verb][context])
|
76
64
|
fail Errors::StubError,
|
77
65
|
"#{verb} #{path} with context '#{context}' not found"
|
78
66
|
end
|
79
67
|
|
80
68
|
# Verify body, if there is one
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
69
|
+
request = action['request'] || {}
|
70
|
+
unless Utils.symbolize_keys(request) == params
|
71
|
+
fail Errors::StubError,
|
72
|
+
"#{verb} #{path} with context '#{context}' params don't match stub. Expected: #{request} Got: #{params}"
|
86
73
|
end
|
74
|
+
|
75
|
+
# At this point, the 'request' is valid by matching a corresponding
|
76
|
+
# request in the stub yaml file. Grab the response from the file and
|
77
|
+
# reset the context
|
78
|
+
stub[path][verb][context]['response']
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Find the first request object with the same params as what's passed in.
|
83
|
+
# Useful for testing without having to set the context.
|
84
|
+
def _find_context_by_params(path, verb, params)
|
85
|
+
(stub[path][verb].find { |context, action|
|
86
|
+
Utils.symbolize_keys(action['request'] || {}) == params
|
87
|
+
} || []).first
|
87
88
|
end
|
88
89
|
end # StubAdapter
|
89
90
|
end # Client::Adapters
|
data/lib/rester/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Honer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|