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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18607fd3b21dbaaa696cc72af03258f5b25f7446
4
- data.tar.gz: 10863ece3e774b24c780c6074cb5f752db02f126
3
+ metadata.gz: aee5f58fe1534d389b5273964b75dd1e438fe862
4
+ data.tar.gz: 0e4ea6c5e02dc173ea8d65215c50f01728753aa4
5
5
  SHA512:
6
- metadata.gz: 5d38ca52de4740aa4fb44dbe92fd5efe0f18cd5b0796be3425cf2dc50db3c1359acfff5f77e189628de224795096e61a5a0d9b7895e8d9e05522149bdad22bbe
7
- data.tar.gz: 17d0af802a2a7b2b6ceb6d6008c17128f185133a09a5c818115e5badb2710650afe9adc1c319c676fc98f19ef94964c3eac9a6bdbdf2494f6ba8b05b24175ef6
6
+ metadata.gz: d60af32ba7072656941772b1597bc59e7a9d0b20badde1d4b274ce46ae63141277a42f846f418e277df1a0e56a17dd14d0f17bb404a3d3ab5285a529bc0f4aea
7
+ data.tar.gz: 4a88dc5a44718d25d9ec2232d80df566ceaf0ca8d65f4327db70bc43562700a4155ba75e791ccca0eb79a4b63b828c20be87b330fbb1f8888bb5ab26dfb39bea
@@ -11,3 +11,4 @@ require "dialers/short_circuits_collection"
11
11
  require "dialers/status"
12
12
  require "dialers/caller"
13
13
  require "dialers/wrapper"
14
+ require "dialers/mockable_caller"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dialers
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.2"
3
3
  end
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.1.2
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-09-17 00:00:00.000000000 Z
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