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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 781dcd45b4ea9347717fba375241286931b28444
4
- data.tar.gz: 3319242e32b49c30316711918748809e736880fa
3
+ metadata.gz: a486ccadfe2ebef7a59324907fd282d8895a6e6c
4
+ data.tar.gz: cfeda2d0d5d1f029ef4108d1855c017803de5446
5
5
  SHA512:
6
- metadata.gz: 6d81ef7d638acb74488d729ccb22e41d749b6aa55afc00b8236d8ca84e1fd80e2798ca7e300a3c8a89e6af73a7bd9eacc913fa113d0b9f8331bd2031c271ab69
7
- data.tar.gz: d2d00b634e8e052a15d0b819f813b417184722234253e5cc92cd8bd69b3f196a1d75d1fd5a26eb5e186c81930a3b134573f3a225cd2708ec0a3ede31fde44fde
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
- self.context = context
45
+ @_context = context
54
46
  yield block
55
- self.context = nil
47
+ @_context = nil
56
48
  end
57
49
 
58
50
  private
59
51
 
60
52
  def _request(verb, path, params)
61
- _validate_request(verb, path, params)
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 _validate_request(verb, path, params)
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
- if (request = action['request'])
82
- unless Utils.symbolize_keys(request) == params
83
- fail Errors::StubError,
84
- "#{verb} #{path} with context '#{context}' params don't match stub"
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
@@ -1,3 +1,3 @@
1
1
  module Rester
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
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.0
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-10 00:00:00.000000000 Z
12
+ date: 2015-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack