evil-client 0.3.3 → 1.0.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.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -11
  3. data/.gitignore +1 -0
  4. data/.rspec +0 -1
  5. data/.rubocop.yml +22 -19
  6. data/.travis.yml +1 -0
  7. data/CHANGELOG.md +251 -6
  8. data/LICENSE.txt +3 -1
  9. data/README.md +47 -81
  10. data/docs/helpers/body.md +93 -0
  11. data/docs/helpers/connection.md +19 -0
  12. data/docs/helpers/headers.md +72 -0
  13. data/docs/helpers/http_method.md +39 -0
  14. data/docs/helpers/let.md +14 -0
  15. data/docs/helpers/logger.md +24 -0
  16. data/docs/helpers/middleware.md +56 -0
  17. data/docs/helpers/operation.md +103 -0
  18. data/docs/helpers/option.md +50 -0
  19. data/docs/helpers/path.md +37 -0
  20. data/docs/helpers/query.md +59 -0
  21. data/docs/helpers/response.md +40 -0
  22. data/docs/helpers/scope.md +121 -0
  23. data/docs/helpers/security.md +102 -0
  24. data/docs/helpers/validate.md +68 -0
  25. data/docs/index.md +70 -78
  26. data/docs/license.md +5 -1
  27. data/docs/rspec.md +96 -0
  28. data/evil-client.gemspec +10 -8
  29. data/lib/evil/client.rb +126 -72
  30. data/lib/evil/client/builder.rb +47 -0
  31. data/lib/evil/client/builder/operation.rb +40 -0
  32. data/lib/evil/client/builder/scope.rb +31 -0
  33. data/lib/evil/client/chaining.rb +17 -0
  34. data/lib/evil/client/connection.rb +60 -20
  35. data/lib/evil/client/container.rb +66 -0
  36. data/lib/evil/client/container/operation.rb +23 -0
  37. data/lib/evil/client/container/scope.rb +28 -0
  38. data/lib/evil/client/exceptions/definition_error.rb +15 -0
  39. data/lib/evil/client/exceptions/name_error.rb +32 -0
  40. data/lib/evil/client/exceptions/response_error.rb +42 -0
  41. data/lib/evil/client/exceptions/type_error.rb +29 -0
  42. data/lib/evil/client/exceptions/validation_error.rb +27 -0
  43. data/lib/evil/client/formatter.rb +49 -0
  44. data/lib/evil/client/formatter/form.rb +45 -0
  45. data/lib/evil/client/formatter/multipart.rb +33 -0
  46. data/lib/evil/client/formatter/part.rb +66 -0
  47. data/lib/evil/client/formatter/text.rb +21 -0
  48. data/lib/evil/client/resolver.rb +84 -0
  49. data/lib/evil/client/resolver/body.rb +22 -0
  50. data/lib/evil/client/resolver/format.rb +30 -0
  51. data/lib/evil/client/resolver/headers.rb +46 -0
  52. data/lib/evil/client/resolver/http_method.rb +34 -0
  53. data/lib/evil/client/resolver/middleware.rb +36 -0
  54. data/lib/evil/client/resolver/query.rb +39 -0
  55. data/lib/evil/client/resolver/request.rb +96 -0
  56. data/lib/evil/client/resolver/response.rb +26 -0
  57. data/lib/evil/client/resolver/security.rb +113 -0
  58. data/lib/evil/client/resolver/uri.rb +35 -0
  59. data/lib/evil/client/rspec.rb +127 -0
  60. data/lib/evil/client/schema.rb +105 -0
  61. data/lib/evil/client/schema/operation.rb +177 -0
  62. data/lib/evil/client/schema/scope.rb +73 -0
  63. data/lib/evil/client/settings.rb +172 -0
  64. data/lib/evil/client/settings/validator.rb +64 -0
  65. data/mkdocs.yml +21 -15
  66. data/spec/features/custom_connection_spec.rb +17 -0
  67. data/spec/features/operation/middleware_spec.rb +50 -0
  68. data/spec/features/operation/options_spec.rb +71 -0
  69. data/spec/features/operation/request_spec.rb +94 -0
  70. data/spec/features/operation/response_spec.rb +48 -0
  71. data/spec/features/scope/options_spec.rb +52 -0
  72. data/spec/fixtures/locales/en.yml +16 -0
  73. data/spec/fixtures/test_client.rb +76 -0
  74. data/spec/spec_helper.rb +18 -6
  75. data/spec/support/fixtures_helper.rb +7 -0
  76. data/spec/unit/builder/operation_spec.rb +90 -0
  77. data/spec/unit/builder/scope_spec.rb +84 -0
  78. data/spec/unit/client_spec.rb +137 -0
  79. data/spec/unit/connection_spec.rb +78 -0
  80. data/spec/unit/container/operation_spec.rb +81 -0
  81. data/spec/unit/container/scope_spec.rb +61 -0
  82. data/spec/unit/container_spec.rb +107 -0
  83. data/spec/unit/exceptions/definition_error_spec.rb +15 -0
  84. data/spec/unit/exceptions/name_error_spec.rb +77 -0
  85. data/spec/unit/exceptions/response_error_spec.rb +22 -0
  86. data/spec/unit/exceptions/type_error_spec.rb +71 -0
  87. data/spec/unit/exceptions/validation_error_spec.rb +13 -0
  88. data/spec/unit/formatter/form_spec.rb +27 -0
  89. data/spec/unit/formatter/multipart_spec.rb +23 -0
  90. data/spec/unit/formatter/part_spec.rb +49 -0
  91. data/spec/unit/formatter/text_spec.rb +37 -0
  92. data/spec/unit/formatter_spec.rb +46 -0
  93. data/spec/unit/resolver/body_spec.rb +65 -0
  94. data/spec/unit/resolver/format_spec.rb +66 -0
  95. data/spec/unit/resolver/headers_spec.rb +93 -0
  96. data/spec/unit/resolver/http_method_spec.rb +67 -0
  97. data/spec/unit/resolver/middleware_spec.rb +83 -0
  98. data/spec/unit/resolver/query_spec.rb +85 -0
  99. data/spec/unit/resolver/request_spec.rb +121 -0
  100. data/spec/unit/resolver/response_spec.rb +64 -0
  101. data/spec/unit/resolver/security_spec.rb +156 -0
  102. data/spec/unit/resolver/uri_spec.rb +117 -0
  103. data/spec/unit/rspec_spec.rb +342 -0
  104. data/spec/unit/schema/operation_spec.rb +309 -0
  105. data/spec/unit/schema/scope_spec.rb +110 -0
  106. data/spec/unit/schema_spec.rb +157 -0
  107. data/spec/unit/settings/validator_spec.rb +128 -0
  108. data/spec/unit/settings_spec.rb +248 -0
  109. metadata +192 -135
  110. data/docs/base_url.md +0 -38
  111. data/docs/documentation.md +0 -9
  112. data/docs/headers.md +0 -59
  113. data/docs/http_method.md +0 -31
  114. data/docs/model.md +0 -173
  115. data/docs/operation.md +0 -0
  116. data/docs/overview.md +0 -0
  117. data/docs/path.md +0 -48
  118. data/docs/query.md +0 -99
  119. data/docs/responses.md +0 -66
  120. data/docs/security.md +0 -102
  121. data/docs/settings.md +0 -32
  122. data/lib/evil/client/connection/net_http.rb +0 -57
  123. data/lib/evil/client/dsl.rb +0 -127
  124. data/lib/evil/client/dsl/base.rb +0 -26
  125. data/lib/evil/client/dsl/files.rb +0 -37
  126. data/lib/evil/client/dsl/headers.rb +0 -16
  127. data/lib/evil/client/dsl/http_method.rb +0 -24
  128. data/lib/evil/client/dsl/operation.rb +0 -91
  129. data/lib/evil/client/dsl/operations.rb +0 -41
  130. data/lib/evil/client/dsl/path.rb +0 -25
  131. data/lib/evil/client/dsl/query.rb +0 -16
  132. data/lib/evil/client/dsl/response.rb +0 -61
  133. data/lib/evil/client/dsl/responses.rb +0 -29
  134. data/lib/evil/client/dsl/scope.rb +0 -27
  135. data/lib/evil/client/dsl/security.rb +0 -57
  136. data/lib/evil/client/dsl/verifier.rb +0 -35
  137. data/lib/evil/client/middleware.rb +0 -81
  138. data/lib/evil/client/middleware/base.rb +0 -11
  139. data/lib/evil/client/middleware/merge_security.rb +0 -20
  140. data/lib/evil/client/middleware/normalize_headers.rb +0 -17
  141. data/lib/evil/client/middleware/stringify_form.rb +0 -40
  142. data/lib/evil/client/middleware/stringify_json.rb +0 -19
  143. data/lib/evil/client/middleware/stringify_multipart.rb +0 -36
  144. data/lib/evil/client/middleware/stringify_multipart/part.rb +0 -36
  145. data/lib/evil/client/middleware/stringify_query.rb +0 -35
  146. data/lib/evil/client/operation.rb +0 -34
  147. data/lib/evil/client/operation/request.rb +0 -26
  148. data/lib/evil/client/operation/response.rb +0 -39
  149. data/lib/evil/client/operation/response_error.rb +0 -13
  150. data/lib/evil/client/operation/unexpected_response_error.rb +0 -19
  151. data/spec/features/instantiation_spec.rb +0 -68
  152. data/spec/features/middleware_spec.rb +0 -79
  153. data/spec/features/operation_with_documentation_spec.rb +0 -41
  154. data/spec/features/operation_with_files_spec.rb +0 -40
  155. data/spec/features/operation_with_form_body_spec.rb +0 -158
  156. data/spec/features/operation_with_headers_spec.rb +0 -99
  157. data/spec/features/operation_with_http_method_spec.rb +0 -45
  158. data/spec/features/operation_with_json_body_spec.rb +0 -156
  159. data/spec/features/operation_with_nested_responses_spec.rb +0 -95
  160. data/spec/features/operation_with_path_spec.rb +0 -47
  161. data/spec/features/operation_with_query_spec.rb +0 -84
  162. data/spec/features/operation_with_security_spec.rb +0 -228
  163. data/spec/features/scoping_spec.rb +0 -48
  164. data/spec/support/test_client.rb +0 -15
  165. data/spec/unit/evil/client/connection/net_http_spec.rb +0 -38
  166. data/spec/unit/evil/client/dsl/files_spec.rb +0 -37
  167. data/spec/unit/evil/client/dsl/operation_spec.rb +0 -374
  168. data/spec/unit/evil/client/dsl/operations_spec.rb +0 -29
  169. data/spec/unit/evil/client/dsl/scope_spec.rb +0 -32
  170. data/spec/unit/evil/client/dsl/security_spec.rb +0 -135
  171. data/spec/unit/evil/client/middleware/merge_security_spec.rb +0 -32
  172. data/spec/unit/evil/client/middleware/normalize_headers_spec.rb +0 -17
  173. data/spec/unit/evil/client/middleware/stringify_form_spec.rb +0 -63
  174. data/spec/unit/evil/client/middleware/stringify_json_spec.rb +0 -61
  175. data/spec/unit/evil/client/middleware/stringify_multipart/part_spec.rb +0 -59
  176. data/spec/unit/evil/client/middleware/stringify_multipart_spec.rb +0 -62
  177. data/spec/unit/evil/client/middleware/stringify_query_spec.rb +0 -40
  178. data/spec/unit/evil/client/middleware_spec.rb +0 -46
  179. data/spec/unit/evil/client/operation/request_spec.rb +0 -49
  180. data/spec/unit/evil/client/operation/response_spec.rb +0 -63
@@ -0,0 +1,137 @@
1
+ RSpec.describe Evil::Client do
2
+ let(:klass) { Class.new(described_class) }
3
+
4
+ describe ".schema" do
5
+ subject { klass.schema }
6
+
7
+ it "returns a schema for the root scope" do
8
+ expect(subject).to be_a described_class::Schema::Scope
9
+ expect(subject.client).to eq klass
10
+ end
11
+ end
12
+
13
+ describe ".scopes" do
14
+ before { klass.schema.scope(:users) {} }
15
+ subject { klass.scopes }
16
+
17
+ it "returns subscopes from the root schema" do
18
+ expect(subject).to eq klass.schema.scopes
19
+ end
20
+ end
21
+
22
+ describe ".operations" do
23
+ before { klass.schema.operation(:users) {} }
24
+ subject { klass.operations }
25
+
26
+ it "returns operationss from the root schema" do
27
+ expect(subject).to eq klass.schema.operations
28
+ end
29
+ end
30
+
31
+ describe ".option" do
32
+ subject { klass.option(:users, optional: true) }
33
+
34
+ it "updates settings of the root schema" do
35
+ expect(klass.schema.settings)
36
+ .to receive(:option)
37
+ .with :users, nil, optional: true
38
+
39
+ subject
40
+ end
41
+ end
42
+
43
+ describe ".scope" do
44
+ subject { klass.scope(:users) {} }
45
+
46
+ it "updates root schema scopes" do
47
+ expect(klass.schema).to receive(:scope).with :users
48
+
49
+ subject
50
+ end
51
+ end
52
+
53
+ describe ".operation" do
54
+ subject { klass.operation(:users) {} }
55
+
56
+ it "updates root schema scopes" do
57
+ expect(klass.schema).to receive(:operation).with :users
58
+
59
+ subject
60
+ end
61
+ end
62
+
63
+ describe ".connection" do
64
+ subject { klass.connection }
65
+
66
+ it "return Evil::Client::Connection module by default" do
67
+ expect(subject).to eq Evil::Client::Connection
68
+ end
69
+ end
70
+
71
+ describe ".connection=" do
72
+ let(:new_connection) { double call: nil }
73
+ subject { klass.connection = new_connection }
74
+
75
+ it "sets new connection" do
76
+ expect { subject }.to change { klass.connection }.to new_connection
77
+ end
78
+
79
+ context "with nil" do
80
+ before { klass.connection = new_connection }
81
+ subject { klass.connection = nil }
82
+
83
+ it "resets connection to default" do
84
+ expect { subject }
85
+ .to change { klass.connection }
86
+ .to Evil::Client::Connection
87
+ end
88
+ end
89
+ end
90
+
91
+ let(:client) do
92
+ klass.option :token
93
+ klass.new(token: "foo", version: 1)
94
+ end
95
+
96
+ describe "#options" do
97
+ subject { client.options }
98
+
99
+ it "returns options assigned to client settings" do
100
+ expect(subject).to eq token: "foo"
101
+ end
102
+ end
103
+
104
+ describe "#scopes" do
105
+ subject { client.scopes }
106
+
107
+ it "returns root scope scopes" do
108
+ expect(subject).to eq client.scope.scopes
109
+ end
110
+ end
111
+
112
+ describe "#operations" do
113
+ subject { client.operations }
114
+
115
+ it "returns root scope operations" do
116
+ expect(subject).to eq client.scope.operations
117
+ end
118
+ end
119
+
120
+ describe "#logger" do
121
+ before { client.scope.logger = double :logger }
122
+ subject { client.logger }
123
+
124
+ it "returns root scope logger" do
125
+ expect(subject).to eq client.scope.logger
126
+ end
127
+ end
128
+
129
+ describe "#logger=" do
130
+ let(:new_logger) { double :logger }
131
+ subject { client.logger = new_logger }
132
+
133
+ it "sets root scope logger" do
134
+ expect { subject }.to change { client.scope.logger }.to new_logger
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,78 @@
1
+ RSpec.describe Evil::Client::Connection, ".call" do
2
+ let(:logger) { Logger.new log }
3
+ let(:log) { StringIO.new }
4
+ let(:env) do
5
+ {
6
+ "REQUEST_METHOD" => "POST",
7
+ "SCRIPT_NAME" => "",
8
+ "PATH_INFO" => "/api/v77/users/43",
9
+ "QUERY_STRING" => "version=77&verbose=true",
10
+ "SERVER_NAME" => "foo.com",
11
+ "SERVER_PORT" => 443,
12
+ "HTTP_Variables" => {
13
+ "Foo" => "BAR",
14
+ "Baz" => "QUX",
15
+ "Authorization" => "Bearer eoiqopr==",
16
+ "Content-Type" => "application/json"
17
+ },
18
+ "rack.version" => Rack::VERSION,
19
+ "rack.input" => "name=Andrew&age=46",
20
+ "rack.url_scheme" => "https",
21
+ "rack.multithread" => false,
22
+ "rack.multiprocess" => false,
23
+ "rack.run_once" => false,
24
+ "rack.hijack?" => false,
25
+ "rack.logger" => logger
26
+ }
27
+ end
28
+
29
+ let(:request) do
30
+ a_request(:post, "https://foo.com/api/v77/users/43?version=77&verbose=true")
31
+ .with body: "name=Andrew&age=46",
32
+ headers: {
33
+ "Foo" => "BAR",
34
+ "Baz" => "QUX",
35
+ "Authorization" => "Bearer eoiqopr==",
36
+ "Content-Type" => "application/json"
37
+ }
38
+ end
39
+
40
+ before do
41
+ stub_request(:any, //).to_return status: 200,
42
+ headers: { "Content-Language" => "en_AU" },
43
+ body: "Done!"
44
+ end
45
+
46
+ subject { described_class.call(env) }
47
+
48
+ it "sends a request" do
49
+ subject
50
+ expect(request).to have_been_made
51
+ end
52
+
53
+ it "returns a response" do
54
+ expect(subject).to eq [200, { "content-language" => ["en_AU"] }, ["Done!"]]
55
+ end
56
+
57
+ it "logs the request" do
58
+ subject
59
+
60
+ <<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
61
+ |INFO -- Evil::Client::Connection: sending request:
62
+ |INFO -- Evil::Client::Connection: Url | https://foo.com/api/v77/users/43?version=77&verbose=true
63
+ |INFO -- Evil::Client::Connection: Headers | {"Foo"=>"BAR", "Baz"=>"QUX", "Authorization"=>"Bearer eoiqopr==", "Content-Type"=>"application/json"}
64
+ |INFO -- Evil::Client::Connection: Body | name=Andrew&age=46
65
+ LOG
66
+ end
67
+
68
+ it "logs the response" do
69
+ subject
70
+
71
+ <<-LOG.gsub(/^ +\|/, "").lines.each { |l| expect(log.string).to include l }
72
+ |INFO -- Evil::Client::Connection: receiving response:
73
+ |INFO -- Evil::Client::Connection: Status | 200
74
+ |INFO -- Evil::Client::Connection: Headers | {\"content-language\"=>[\"en_AU\"]}
75
+ |INFO -- Evil::Client::Connection: Body | [\"Done!\"]
76
+ LOG
77
+ end
78
+ end
@@ -0,0 +1,81 @@
1
+ RSpec.describe Evil::Client::Container::Operation do
2
+ before do
3
+ Test::Middleware = Struct.new(:app) do
4
+ def call(env)
5
+ env["HTTP_Variables"].update("Accept-Language" => "ru_RU")
6
+ app.call env
7
+ end
8
+ end
9
+ end
10
+
11
+ let(:operation) { described_class.new schema, nil, opts }
12
+ let(:connection) { Evil::Client::Connection }
13
+ let(:schema) do
14
+ double :schema,
15
+ to_s: "MyApi.users.update",
16
+ client: double(:client, connection: connection),
17
+ parent: nil,
18
+ settings: settings_klass,
19
+ definitions: {
20
+ path: -> { "https://example.com/users/#{id}" },
21
+ http_method: -> { "PATCH" },
22
+ format: -> { :json },
23
+ security: -> { { headers: { "Authentication" => token } } },
24
+ headers: -> { { "Content-Language" => language } },
25
+ query: -> { { language: language } },
26
+ body: -> { { name: name } },
27
+ middleware: -> { Test::Middleware },
28
+ responses: { 200 => proc { |_, _, body| JSON.parse body.first } }
29
+ }
30
+ end
31
+
32
+ let(:settings_klass) do
33
+ Class.new(Evil::Client::Settings) do
34
+ option :token
35
+ option :id
36
+ option :language
37
+ option :name
38
+ end
39
+ end
40
+
41
+ let(:opts) { { token: "qux", id: 7, language: "en_US", name: "Joe", age: 9 } }
42
+
43
+ before do
44
+ stub_request(:any, //).to_return status: 200, body: '{"result":"success"}'
45
+ end
46
+
47
+ it "is a subclass of base container" do
48
+ expect(described_class.superclass).to eq Evil::Client::Container
49
+ end
50
+
51
+ describe "#call" do
52
+ subject { operation.call }
53
+
54
+ let(:request) do
55
+ a_request(:patch, "https://example.com/users/7?language=en_US") do |r|
56
+ expect(r.body).to eq '{"name":"Joe"}'
57
+ expect(r.headers).to include "Authentication" => "qux",
58
+ "Content-Language" => "en_US",
59
+ "Accept-Language" => "ru_RU"
60
+ end
61
+ end
62
+
63
+ it "sends resolved request" do
64
+ subject
65
+ expect(request).to have_been_made
66
+ end
67
+
68
+ it "returns parsed response" do
69
+ expect(subject).to eq "result" => "success"
70
+ end
71
+
72
+ context "whe a client has custom connection" do
73
+ let(:connection) { double call: [200, {}, %w[{"result":"wow"}]] }
74
+
75
+ it "sends request to selected connection" do
76
+ expect(connection).to receive(:call)
77
+ expect(subject).to eq "result" => "wow"
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,61 @@
1
+ RSpec.describe Evil::Client::Container::Scope do
2
+ let(:scope) { described_class.new schema, nil, opts }
3
+ let(:opts) { { token: "qux", id: 7, language: "en_US", name: "Joe", age: 9 } }
4
+ let(:update_schema) { double :update_schema, name: :update }
5
+ let(:admins_schema) { double :admins_schema, name: :admins }
6
+
7
+ let(:settings_klass) do
8
+ Class.new(Evil::Client::Settings) do
9
+ option :token
10
+ option :id
11
+ option :language
12
+ option :name
13
+ end
14
+ end
15
+
16
+ let(:schema) do
17
+ double :schema,
18
+ parent: nil,
19
+ settings: settings_klass,
20
+ operations: { update: update_schema },
21
+ scopes: { admins: admins_schema }
22
+ end
23
+
24
+ it "is a subclass of base container" do
25
+ expect(described_class.superclass).to eq Evil::Client::Container
26
+ end
27
+
28
+ describe "#operations" do
29
+ subject { scope.operations[:update] }
30
+
31
+ it "contains sub-schemas with current settings" do
32
+ expect(subject).to be_a Evil::Client::Builder::Operation
33
+ expect(subject.schema).to eq update_schema
34
+ expect(subject.parent).to eq scope.settings
35
+ end
36
+ end
37
+
38
+ describe "#scopes" do
39
+ subject { scope.scopes[:admins] }
40
+
41
+ it "contains sub-schemas with current settings" do
42
+ expect(subject).to be_a Evil::Client::Builder::Scope
43
+ expect(subject.schema).to eq admins_schema
44
+ expect(subject.parent).to eq scope.settings
45
+ end
46
+ end
47
+
48
+ describe "chaining" do
49
+ before do
50
+ allow(scope.scopes[:admins])
51
+ .to receive(:call) { |id:, **| "admins #{id}" }
52
+ allow(scope.operations[:update])
53
+ .to receive(:call) { |id:, **| "update #{id}" }
54
+ end
55
+
56
+ it "is supported" do
57
+ expect(scope.admins(id: 8)).to eq "admins 8"
58
+ expect(scope.update(id: 9)).to eq "update 9"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,107 @@
1
+ RSpec.describe Evil::Client::Container do
2
+ let(:container) { described_class.new schema, logger, opts }
3
+ let(:logger) { Logger.new log }
4
+ let(:log) { StringIO.new }
5
+ let(:opts) do
6
+ { token: "qux", id: 7, language: "en_US", name: "Joe", age: 9 }
7
+ end
8
+
9
+ let(:settings_klass) do
10
+ Class.new(Evil::Client::Settings) do
11
+ option :token
12
+ option :id
13
+ option :language
14
+ option :name
15
+ end
16
+ end
17
+
18
+ let(:schema) do
19
+ double :schema,
20
+ to_s: "MyApi.users",
21
+ parent: nil,
22
+ settings: settings_klass,
23
+ definitions: {}
24
+ end
25
+
26
+ describe ".new" do
27
+ subject { container }
28
+
29
+ it "logs given options" do
30
+ subject
31
+ expect(log.string).to include opts.to_s
32
+ end
33
+
34
+ it "logs initialized settings" do
35
+ subject
36
+ expect(log.string).to include container.settings.to_s
37
+ end
38
+ end
39
+
40
+ describe "#to_s" do
41
+ subject { container.to_s }
42
+
43
+ it "returns human-friendly representation of container" do
44
+ expect(subject).to eq \
45
+ "#<MyApi.users @token=qux, @id=7, @language=en_US, @name=Joe>"
46
+ end
47
+ end
48
+
49
+ describe "#to_str" do
50
+ subject { container.to_str }
51
+
52
+ it "returns human-friendly representation of container" do
53
+ expect(subject).to eq \
54
+ "#<MyApi.users @token=qux, @id=7, @language=en_US, @name=Joe>"
55
+ end
56
+ end
57
+
58
+ describe "#inspect" do
59
+ subject { container.inspect }
60
+
61
+ it "returns human-friendly representation of container" do
62
+ expect(subject).to eq \
63
+ "#<MyApi.users @token=qux, @id=7, @language=en_US, @name=Joe>"
64
+ end
65
+ end
66
+
67
+ describe "#logger" do
68
+ subject { container.logger }
69
+
70
+ it "returns current logger" do
71
+ expect(subject).to eq logger
72
+ end
73
+ end
74
+
75
+ describe "#logger=" do
76
+ let(:new_logger) { Logger.new log }
77
+ subject { container.logger = new_logger }
78
+
79
+ it "sets new logger" do
80
+ expect { subject }.to change { container.logger }.to new_logger
81
+ end
82
+ end
83
+
84
+ describe "#schema" do
85
+ subject { container.schema }
86
+
87
+ it "returns current schema" do
88
+ expect(subject).to eq schema
89
+ end
90
+ end
91
+
92
+ describe "#settings" do
93
+ subject { container.settings }
94
+
95
+ it "returns current settings" do
96
+ expect(subject).to be_a settings_klass
97
+ end
98
+ end
99
+
100
+ describe "#options" do
101
+ subject { container.options }
102
+
103
+ it "returns settings options" do
104
+ expect(subject).to eq token: "qux", id: 7, language: "en_US", name: "Joe"
105
+ end
106
+ end
107
+ end