dialers 0.1.2 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dialers.rb +1 -0
- data/lib/dialers/mockable_caller.rb +83 -0
- data/lib/dialers/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee5f58fe1534d389b5273964b75dd1e438fe862
|
4
|
+
data.tar.gz: 0e4ea6c5e02dc173ea8d65215c50f01728753aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d60af32ba7072656941772b1597bc59e7a9d0b20badde1d4b274ce46ae63141277a42f846f418e277df1a0e56a17dd14d0f17bb404a3d3ab5285a529bc0f4aea
|
7
|
+
data.tar.gz: 4a88dc5a44718d25d9ec2232d80df566ceaf0ca8d65f4327db70bc43562700a4155ba75e791ccca0eb79a4b63b828c20be87b330fbb1f8888bb5ab26dfb39bea
|
data/lib/dialers.rb
CHANGED
@@ -0,0 +1,83 @@
|
|
1
|
+
module Dialers
|
2
|
+
class MockableCaller
|
3
|
+
def mock_routes(&routes_definition)
|
4
|
+
self.routes_definition = MockedRoutesDefinition.new(&routes_definition)
|
5
|
+
end
|
6
|
+
|
7
|
+
%i(get head delete options post put patch).each do |http_method|
|
8
|
+
define_method(http_method) do |url, params = {}, headers = {}|
|
9
|
+
mocked_response = MockedResponse.new(
|
10
|
+
http_method: http_method,
|
11
|
+
url: url,
|
12
|
+
params: params,
|
13
|
+
headers: headers,
|
14
|
+
routes_definition: routes_definition
|
15
|
+
)
|
16
|
+
Dialers::Transformable.new(mocked_response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_accessor :routes_definition
|
23
|
+
end
|
24
|
+
|
25
|
+
class MockedRoutesDefinition
|
26
|
+
def initialize(&block)
|
27
|
+
self.routes = []
|
28
|
+
self.current_response = {}
|
29
|
+
block.call(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to(http_method, url)
|
33
|
+
self.current_response = route_from(http_method, url)
|
34
|
+
routes << current_response
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def respond_with(status, body)
|
39
|
+
current_response[:status] = status
|
40
|
+
current_response[:body] = body
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_route(http_method, url)
|
44
|
+
routes.find do |route|
|
45
|
+
route[:http_method] == http_method && route[:url] == url
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def route_from(http_method, url)
|
52
|
+
{ http_method: http_method, url: url }
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_accessor :routes, :current_response
|
56
|
+
end
|
57
|
+
|
58
|
+
class MockedResponse
|
59
|
+
def initialize(http_method: nil, url: "", params: {}, headers: {}, routes_definition: nil)
|
60
|
+
self.http_method = http_method
|
61
|
+
self.url = url
|
62
|
+
self.params = params
|
63
|
+
self.headers = headers
|
64
|
+
self.route = routes_definition.get_route(http_method, url)
|
65
|
+
|
66
|
+
if route.nil?
|
67
|
+
fail "Route is not defined for: #{http_method} to #{url}."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def status
|
72
|
+
route[:status]
|
73
|
+
end
|
74
|
+
|
75
|
+
def body
|
76
|
+
route[:body]
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
attr_accessor :http_method, :url, :params, :headers, :route
|
82
|
+
end
|
83
|
+
end
|
data/lib/dialers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dialers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juliogarciag
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- lib/dialers/assign_attributes.rb
|
227
227
|
- lib/dialers/caller.rb
|
228
228
|
- lib/dialers/errors.rb
|
229
|
+
- lib/dialers/mockable_caller.rb
|
229
230
|
- lib/dialers/request_options.rb
|
230
231
|
- lib/dialers/short_circuit.rb
|
231
232
|
- lib/dialers/short_circuits_collection.rb
|