faraday 0.9.1 → 0.9.2
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.
- data/LICENSE.md +1 -1
- data/README.md +41 -16
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter/em_synchrony.rb +8 -0
- data/lib/faraday/adapter/excon.rb +1 -0
- data/lib/faraday/adapter/httpclient.rb +14 -3
- data/lib/faraday/adapter/net_http.rb +2 -2
- data/lib/faraday/adapter/net_http_persistent.rb +2 -1
- data/lib/faraday/adapter/patron.rb +8 -2
- data/lib/faraday/connection.rb +8 -3
- data/lib/faraday/options.rb +9 -0
- data/lib/faraday/parameters.rb +54 -38
- data/lib/faraday/rack_builder.rb +3 -2
- data/lib/faraday/request/retry.rb +9 -3
- data/lib/faraday/response.rb +2 -2
- data/lib/faraday/utils.rb +13 -1
- metadata +61 -124
- checksums.yaml +0 -7
- data/.document +0 -6
- data/CHANGELOG.md +0 -20
- data/CONTRIBUTING.md +0 -36
- data/Gemfile +0 -25
- data/Rakefile +0 -71
- data/faraday.gemspec +0 -34
- data/script/cached-bundle +0 -46
- data/script/console +0 -7
- data/script/generate_certs +0 -42
- data/script/package +0 -7
- data/script/proxy-server +0 -42
- data/script/release +0 -17
- data/script/s3-put +0 -71
- data/script/server +0 -36
- data/script/test +0 -172
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -20
- data/test/adapters/em_synchrony_test.rb +0 -20
- data/test/adapters/excon_test.rb +0 -20
- data/test/adapters/httpclient_test.rb +0 -21
- data/test/adapters/integration.rb +0 -254
- data/test/adapters/logger_test.rb +0 -82
- data/test/adapters/net_http_persistent_test.rb +0 -20
- data/test/adapters/net_http_test.rb +0 -14
- data/test/adapters/patron_test.rb +0 -20
- data/test/adapters/rack_test.rb +0 -31
- data/test/adapters/test_middleware_test.rb +0 -114
- data/test/adapters/typhoeus_test.rb +0 -28
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -111
- data/test/connection_test.rb +0 -522
- data/test/env_test.rb +0 -218
- data/test/helper.rb +0 -81
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -177
- data/test/middleware_stack_test.rb +0 -173
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -252
- data/test/parameters_test.rb +0 -64
- data/test/request_middleware_test.rb +0 -142
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -58
@@ -1,177 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helper", __FILE__)
|
2
|
-
|
3
|
-
module Middleware
|
4
|
-
class RetryTest < Faraday::TestCase
|
5
|
-
def setup
|
6
|
-
@times_called = 0
|
7
|
-
end
|
8
|
-
|
9
|
-
def conn(*retry_args)
|
10
|
-
Faraday.new do |b|
|
11
|
-
b.request :retry, *retry_args
|
12
|
-
b.adapter :test do |stub|
|
13
|
-
['get', 'post'].each do |method|
|
14
|
-
stub.send(method, '/unstable') {
|
15
|
-
@times_called += 1
|
16
|
-
@explode.call @times_called
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_unhandled_error
|
24
|
-
@explode = lambda {|n| raise "boom!" }
|
25
|
-
assert_raises(RuntimeError) { conn.get("/unstable") }
|
26
|
-
assert_equal 1, @times_called
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_handled_error
|
30
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
31
|
-
assert_raises(Errno::ETIMEDOUT) { conn.get("/unstable") }
|
32
|
-
assert_equal 3, @times_called
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_legacy_max_retries
|
36
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
37
|
-
assert_raises(Errno::ETIMEDOUT) { conn(1).get("/unstable") }
|
38
|
-
assert_equal 2, @times_called
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_legacy_max_negative_retries
|
42
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
43
|
-
assert_raises(Errno::ETIMEDOUT) { conn(-9).get("/unstable") }
|
44
|
-
assert_equal 1, @times_called
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_new_max_retries
|
48
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
49
|
-
assert_raises(Errno::ETIMEDOUT) { conn(:max => 3).get("/unstable") }
|
50
|
-
assert_equal 4, @times_called
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_new_max_negative_retries
|
54
|
-
@explode = lambda { |n| raise Errno::ETIMEDOUT }
|
55
|
-
assert_raises(Errno::ETIMEDOUT) { conn(:max => -9).get("/unstable") }
|
56
|
-
assert_equal 1, @times_called
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_interval
|
60
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
61
|
-
started = Time.now
|
62
|
-
assert_raises(Errno::ETIMEDOUT) {
|
63
|
-
conn(:max => 2, :interval => 0.1).get("/unstable")
|
64
|
-
}
|
65
|
-
assert_in_delta 0.2, Time.now - started, 0.04
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_calls_sleep_amount
|
69
|
-
explode_app = MiniTest::Mock.new
|
70
|
-
explode_app.expect(:call, nil, [{:body=>nil}])
|
71
|
-
def explode_app.call(env)
|
72
|
-
raise Errno::ETIMEDOUT
|
73
|
-
end
|
74
|
-
|
75
|
-
retry_middleware = Faraday::Request::Retry.new(explode_app)
|
76
|
-
class << retry_middleware
|
77
|
-
attr_accessor :sleep_amount_retries
|
78
|
-
|
79
|
-
def sleep_amount(retries)
|
80
|
-
self.sleep_amount_retries.delete(retries)
|
81
|
-
0
|
82
|
-
end
|
83
|
-
end
|
84
|
-
retry_middleware.sleep_amount_retries = [2, 1]
|
85
|
-
|
86
|
-
assert_raises(Errno::ETIMEDOUT) {
|
87
|
-
retry_middleware.call({:method => :get})
|
88
|
-
}
|
89
|
-
|
90
|
-
assert_empty retry_middleware.sleep_amount_retries
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_exponential_backoff
|
94
|
-
middleware = Faraday::Request::Retry.new(nil, :max => 5, :interval => 0.1, :backoff_factor => 2)
|
95
|
-
assert_equal middleware.sleep_amount(5), 0.1
|
96
|
-
assert_equal middleware.sleep_amount(4), 0.2
|
97
|
-
assert_equal middleware.sleep_amount(3), 0.4
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_random_additional_interval_amount
|
101
|
-
middleware = Faraday::Request::Retry.new(nil, :max => 2, :interval => 0.1, :interval_randomness => 1.0)
|
102
|
-
sleep_amount = middleware.sleep_amount(2)
|
103
|
-
assert_operator sleep_amount, :>=, 0.1
|
104
|
-
assert_operator sleep_amount, :<=, 0.2
|
105
|
-
middleware = Faraday::Request::Retry.new(nil, :max => 2, :interval => 0.1, :interval_randomness => 0.5)
|
106
|
-
sleep_amount = middleware.sleep_amount(2)
|
107
|
-
assert_operator sleep_amount, :>=, 0.1
|
108
|
-
assert_operator sleep_amount, :<=, 0.15
|
109
|
-
middleware = Faraday::Request::Retry.new(nil, :max => 2, :interval => 0.1, :interval_randomness => 0.25)
|
110
|
-
sleep_amount = middleware.sleep_amount(2)
|
111
|
-
assert_operator sleep_amount, :>=, 0.1
|
112
|
-
assert_operator sleep_amount, :<=, 0.125
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_custom_exceptions
|
116
|
-
@explode = lambda {|n| raise "boom!" }
|
117
|
-
assert_raises(RuntimeError) {
|
118
|
-
conn(:exceptions => StandardError).get("/unstable")
|
119
|
-
}
|
120
|
-
assert_equal 3, @times_called
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_should_stop_retrying_if_block_returns_false_checking_env
|
124
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
125
|
-
check = lambda { |env,exception| env[:method] != :post }
|
126
|
-
assert_raises(Errno::ETIMEDOUT) {
|
127
|
-
conn(:retry_if => check).post("/unstable")
|
128
|
-
}
|
129
|
-
assert_equal 1, @times_called
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_should_stop_retrying_if_block_returns_false_checking_exception
|
133
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
134
|
-
check = lambda { |env,exception| !exception.kind_of?(Errno::ETIMEDOUT) }
|
135
|
-
assert_raises(Errno::ETIMEDOUT) {
|
136
|
-
conn(:retry_if => check).post("/unstable")
|
137
|
-
}
|
138
|
-
assert_equal 1, @times_called
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_should_not_call_retry_if_for_idempotent_methods_if_methods_unspecified
|
142
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
143
|
-
check = lambda { |env,exception| raise "this should have never been called" }
|
144
|
-
assert_raises(Errno::ETIMEDOUT) {
|
145
|
-
conn(:retry_if => check).get("/unstable")
|
146
|
-
}
|
147
|
-
assert_equal 3, @times_called
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_should_not_retry_for_non_idempotent_method_if_methods_unspecified
|
151
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
152
|
-
assert_raises(Errno::ETIMEDOUT) {
|
153
|
-
conn.post("/unstable")
|
154
|
-
}
|
155
|
-
assert_equal 1, @times_called
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_should_not_call_retry_if_for_specified_methods
|
159
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
160
|
-
check = lambda { |env,exception| raise "this should have never been called" }
|
161
|
-
assert_raises(Errno::ETIMEDOUT) {
|
162
|
-
conn(:retry_if => check, :methods => [:post]).post("/unstable")
|
163
|
-
}
|
164
|
-
assert_equal 3, @times_called
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_should_call_retry_if_for_empty_method_list
|
168
|
-
@explode = lambda {|n| raise Errno::ETIMEDOUT }
|
169
|
-
check = lambda { |env,exception| @times_called < 2 }
|
170
|
-
assert_raises(Errno::ETIMEDOUT) {
|
171
|
-
conn(:retry_if => check, :methods => []).get("/unstable")
|
172
|
-
}
|
173
|
-
assert_equal 2, @times_called
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class MiddlewareStackTest < Faraday::TestCase
|
4
|
-
# mock handler classes
|
5
|
-
class Handler < Struct.new(:app)
|
6
|
-
def call(env)
|
7
|
-
(env[:request_headers]['X-Middleware'] ||= '') << ":#{self.class.name.split('::').last}"
|
8
|
-
app.call(env)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
class Apple < Handler; end
|
12
|
-
class Orange < Handler; end
|
13
|
-
class Banana < Handler; end
|
14
|
-
|
15
|
-
class Broken < Faraday::Middleware
|
16
|
-
dependency 'zomg/i_dont/exist'
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
@conn = Faraday::Connection.new
|
21
|
-
@builder = @conn.builder
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_sets_default_adapter_if_none_set
|
25
|
-
default_middleware = Faraday::Request.lookup_middleware :url_encoded
|
26
|
-
default_adapter_klass = Faraday::Adapter.lookup_middleware Faraday.default_adapter
|
27
|
-
assert @builder[0] == default_middleware
|
28
|
-
assert @builder[1] == default_adapter_klass
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_allows_rebuilding
|
32
|
-
build_stack Apple
|
33
|
-
build_stack Orange
|
34
|
-
assert_handlers %w[Orange]
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_allows_extending
|
38
|
-
build_stack Apple
|
39
|
-
@conn.use Orange
|
40
|
-
assert_handlers %w[Apple Orange]
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_builder_is_passed_to_new_faraday_connection
|
44
|
-
new_conn = Faraday::Connection.new :builder => @builder
|
45
|
-
assert_equal @builder, new_conn.builder
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_insert_before
|
49
|
-
build_stack Apple, Orange
|
50
|
-
@builder.insert_before Apple, Banana
|
51
|
-
assert_handlers %w[Banana Apple Orange]
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_insert_after
|
55
|
-
build_stack Apple, Orange
|
56
|
-
@builder.insert_after Apple, Banana
|
57
|
-
assert_handlers %w[Apple Banana Orange]
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_swap_handlers
|
61
|
-
build_stack Apple, Orange
|
62
|
-
@builder.swap Apple, Banana
|
63
|
-
assert_handlers %w[Banana Orange]
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_delete_handler
|
67
|
-
build_stack Apple, Orange
|
68
|
-
@builder.delete Apple
|
69
|
-
assert_handlers %w[Orange]
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_stack_is_locked_after_making_requests
|
73
|
-
build_stack Apple
|
74
|
-
assert !@builder.locked?
|
75
|
-
@conn.get('/')
|
76
|
-
assert @builder.locked?
|
77
|
-
|
78
|
-
assert_raises Faraday::RackBuilder::StackLocked do
|
79
|
-
@conn.use Orange
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_duped_stack_is_unlocked
|
84
|
-
build_stack Apple
|
85
|
-
assert !@builder.locked?
|
86
|
-
@builder.lock!
|
87
|
-
assert @builder.locked?
|
88
|
-
|
89
|
-
duped_connection = @conn.dup
|
90
|
-
assert_equal @builder, duped_connection.builder
|
91
|
-
assert !duped_connection.builder.locked?
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_handler_comparison
|
95
|
-
build_stack Apple
|
96
|
-
assert_equal @builder.handlers.first, Apple
|
97
|
-
assert_equal @builder.handlers[0,1], [Apple]
|
98
|
-
assert_equal @builder.handlers.first, Faraday::RackBuilder::Handler.new(Apple)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_unregistered_symbol
|
102
|
-
err = assert_raises(Faraday::Error){ build_stack :apple }
|
103
|
-
assert_equal ":apple is not registered on Faraday::Middleware", err.message
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_registered_symbol
|
107
|
-
Faraday::Middleware.register_middleware :apple => Apple
|
108
|
-
begin
|
109
|
-
build_stack :apple
|
110
|
-
assert_handlers %w[Apple]
|
111
|
-
ensure
|
112
|
-
unregister_middleware Faraday::Middleware, :apple
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_registered_symbol_with_proc
|
117
|
-
Faraday::Middleware.register_middleware :apple => lambda { Apple }
|
118
|
-
begin
|
119
|
-
build_stack :apple
|
120
|
-
assert_handlers %w[Apple]
|
121
|
-
ensure
|
122
|
-
unregister_middleware Faraday::Middleware, :apple
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_registered_symbol_with_array
|
127
|
-
Faraday::Middleware.register_middleware File.expand_path("..", __FILE__),
|
128
|
-
:strawberry => [lambda { Strawberry }, 'strawberry']
|
129
|
-
begin
|
130
|
-
build_stack :strawberry
|
131
|
-
assert_handlers %w[Strawberry]
|
132
|
-
ensure
|
133
|
-
unregister_middleware Faraday::Middleware, :strawberry
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_missing_dependencies
|
138
|
-
build_stack Broken
|
139
|
-
err = assert_raises RuntimeError do
|
140
|
-
@conn.get('/')
|
141
|
-
end
|
142
|
-
assert_match "missing dependency for MiddlewareStackTest::Broken: ", err.message
|
143
|
-
assert_match "zomg/i_dont/exist", err.message
|
144
|
-
end
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
# make a stack with test adapter that reflects the order of middleware
|
149
|
-
def build_stack(*handlers)
|
150
|
-
@builder.build do |b|
|
151
|
-
handlers.each { |handler| b.use(*handler) }
|
152
|
-
yield(b) if block_given?
|
153
|
-
|
154
|
-
b.adapter :test do |stub|
|
155
|
-
stub.get '/' do |env|
|
156
|
-
# echo the "X-Middleware" request header in the body
|
157
|
-
[200, {}, env[:request_headers]['X-Middleware'].to_s]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def assert_handlers(list)
|
164
|
-
echoed_list = @conn.get('/').body.to_s.split(':')
|
165
|
-
echoed_list.shift if echoed_list.first == ''
|
166
|
-
assert_equal list, echoed_list
|
167
|
-
end
|
168
|
-
|
169
|
-
def unregister_middleware(component, key)
|
170
|
-
# TODO: unregister API?
|
171
|
-
component.instance_variable_get('@registered_middleware').delete(key)
|
172
|
-
end
|
173
|
-
end
|
data/test/multibyte.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ファイル
|
data/test/options_test.rb
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class OptionsTest < Faraday::TestCase
|
4
|
-
class SubOptions < Faraday::Options.new(:sub); end
|
5
|
-
class ParentOptions < Faraday::Options.new(:a, :b, :c)
|
6
|
-
options :c => SubOptions
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_clear
|
10
|
-
options = SubOptions.new(1)
|
11
|
-
assert !options.empty?
|
12
|
-
assert options.clear
|
13
|
-
assert options.empty?
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_empty
|
17
|
-
options = SubOptions.new
|
18
|
-
assert options.empty?
|
19
|
-
options.sub = 1
|
20
|
-
assert !options.empty?
|
21
|
-
options.delete(:sub)
|
22
|
-
assert options.empty?
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_each_key
|
26
|
-
options = ParentOptions.new(1, 2, 3)
|
27
|
-
enum = options.each_key
|
28
|
-
assert_equal enum.next.to_sym, :a
|
29
|
-
assert_equal enum.next.to_sym, :b
|
30
|
-
assert_equal enum.next.to_sym, :c
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_key?
|
34
|
-
options = SubOptions.new
|
35
|
-
assert !options.key?(:sub)
|
36
|
-
options.sub = 1
|
37
|
-
if RUBY_VERSION >= '1.9'
|
38
|
-
assert options.key?(:sub)
|
39
|
-
else
|
40
|
-
assert options.key?("sub")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_each_value
|
45
|
-
options = ParentOptions.new(1, 2, 3)
|
46
|
-
enum = options.each_value
|
47
|
-
assert_equal enum.next, 1
|
48
|
-
assert_equal enum.next, 2
|
49
|
-
assert_equal enum.next, 3
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_value?
|
53
|
-
options = SubOptions.new
|
54
|
-
assert !options.value?(1)
|
55
|
-
options.sub = 1
|
56
|
-
assert options.value?(1)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_request_proxy_setter
|
60
|
-
options = Faraday::RequestOptions.new
|
61
|
-
assert_nil options.proxy
|
62
|
-
|
63
|
-
assert_raises NoMethodError do
|
64
|
-
options[:proxy] = {:booya => 1}
|
65
|
-
end
|
66
|
-
|
67
|
-
options[:proxy] = {:user => 'user'}
|
68
|
-
assert_kind_of Faraday::ProxyOptions, options.proxy
|
69
|
-
assert_equal 'user', options.proxy.user
|
70
|
-
|
71
|
-
options.proxy = nil
|
72
|
-
assert_nil options.proxy
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_proxy_options_from_string
|
76
|
-
options = Faraday::ProxyOptions.from 'http://user:pass@example.org'
|
77
|
-
assert_equal 'user', options.user
|
78
|
-
assert_equal 'pass', options.password
|
79
|
-
assert_kind_of URI, options.uri
|
80
|
-
assert_equal '', options.path
|
81
|
-
assert_equal 80, options.port
|
82
|
-
assert_equal 'example.org', options.host
|
83
|
-
assert_equal 'http', options.scheme
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_proxy_options_hash_access
|
87
|
-
proxy = Faraday::ProxyOptions.from 'http://a%40b:pw%20d@example.org'
|
88
|
-
assert_equal 'a@b', proxy[:user]
|
89
|
-
assert_equal 'a@b', proxy.user
|
90
|
-
assert_equal 'pw d', proxy[:password]
|
91
|
-
assert_equal 'pw d', proxy.password
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_proxy_options_no_auth
|
95
|
-
proxy = Faraday::ProxyOptions.from 'http://example.org'
|
96
|
-
assert_nil proxy.user
|
97
|
-
assert_nil proxy.password
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_from_options
|
101
|
-
options = ParentOptions.new(1)
|
102
|
-
|
103
|
-
value = ParentOptions.from(options)
|
104
|
-
assert_equal 1, value.a
|
105
|
-
assert_nil value.b
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_from_options_with_sub_object
|
109
|
-
sub = SubOptions.new(1)
|
110
|
-
options = ParentOptions.from :a => 1, :c => sub
|
111
|
-
assert_kind_of ParentOptions, options
|
112
|
-
assert_equal 1, options.a
|
113
|
-
assert_nil options.b
|
114
|
-
assert_kind_of SubOptions, options.c
|
115
|
-
assert_equal 1, options.c.sub
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_from_hash
|
119
|
-
options = ParentOptions.from :a => 1
|
120
|
-
assert_kind_of ParentOptions, options
|
121
|
-
assert_equal 1, options.a
|
122
|
-
assert_nil options.b
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_from_hash_with_sub_object
|
126
|
-
options = ParentOptions.from :a => 1, :c => {:sub => 1}
|
127
|
-
assert_kind_of ParentOptions, options
|
128
|
-
assert_equal 1, options.a
|
129
|
-
assert_nil options.b
|
130
|
-
assert_kind_of SubOptions, options.c
|
131
|
-
assert_equal 1, options.c.sub
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_inheritance
|
135
|
-
subclass = Class.new(ParentOptions)
|
136
|
-
options = subclass.from(:c => {:sub => 'hello'})
|
137
|
-
assert_kind_of SubOptions, options.c
|
138
|
-
assert_equal 'hello', options.c.sub
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_from_deep_hash
|
142
|
-
hash = {:b => 1}
|
143
|
-
options = ParentOptions.from :a => hash
|
144
|
-
assert_equal 1, options.a[:b]
|
145
|
-
|
146
|
-
hash[:b] = 2
|
147
|
-
assert_equal 1, options.a[:b]
|
148
|
-
|
149
|
-
options.a[:b] = 3
|
150
|
-
assert_equal 2, hash[:b]
|
151
|
-
assert_equal 3, options.a[:b]
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_from_nil
|
155
|
-
options = ParentOptions.from(nil)
|
156
|
-
assert_kind_of ParentOptions, options
|
157
|
-
assert_nil options.a
|
158
|
-
assert_nil options.b
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_invalid_key
|
162
|
-
assert_raises NoMethodError do
|
163
|
-
ParentOptions.from :invalid => 1
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_update
|
168
|
-
options = ParentOptions.new(1)
|
169
|
-
assert_equal 1, options.a
|
170
|
-
assert_nil options.b
|
171
|
-
|
172
|
-
updated = options.update :a => 2, :b => 3
|
173
|
-
assert_equal 2, options.a
|
174
|
-
assert_equal 3, options.b
|
175
|
-
assert_equal options, updated
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_delete
|
179
|
-
options = ParentOptions.new(1)
|
180
|
-
assert_equal 1, options.a
|
181
|
-
assert_equal 1, options.delete(:a)
|
182
|
-
assert_nil options.a
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_merge
|
186
|
-
options = ParentOptions.new(1)
|
187
|
-
assert_equal 1, options.a
|
188
|
-
assert_nil options.b
|
189
|
-
|
190
|
-
dup = options.merge :a => 2, :b => 3
|
191
|
-
assert_equal 2, dup.a
|
192
|
-
assert_equal 3, dup.b
|
193
|
-
assert_equal 1, options.a
|
194
|
-
assert_nil options.b
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_env_access_member
|
198
|
-
e = Faraday::Env.new
|
199
|
-
assert_nil e.method
|
200
|
-
e.method = :get
|
201
|
-
assert_equal :get, e.method
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_env_access_symbol_non_member
|
205
|
-
e = Faraday::Env.new
|
206
|
-
assert_nil e[:custom]
|
207
|
-
e[:custom] = :boom
|
208
|
-
assert_equal :boom, e[:custom]
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_env_access_string_non_member
|
212
|
-
e = Faraday::Env.new
|
213
|
-
assert_nil e["custom"]
|
214
|
-
e["custom"] = :boom
|
215
|
-
assert_equal :boom, e["custom"]
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_env_fetch_ignores_false
|
219
|
-
ssl = Faraday::SSLOptions.new
|
220
|
-
ssl.verify = false
|
221
|
-
assert !ssl.fetch(:verify, true)
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_fetch_grabs_value
|
225
|
-
opt = Faraday::SSLOptions.new
|
226
|
-
opt.verify = 1
|
227
|
-
assert_equal 1, opt.fetch(:verify, false) { |k| :blah }
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_fetch_uses_falsey_default
|
231
|
-
opt = Faraday::SSLOptions.new
|
232
|
-
assert_equal false, opt.fetch(:verify, false) { |k| :blah }
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_fetch_accepts_block
|
236
|
-
opt = Faraday::SSLOptions.new
|
237
|
-
assert_equal "yo :verify", opt.fetch(:verify) { |k| "yo #{k.inspect}"}
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_fetch_needs_a_default_if_key_is_missing
|
241
|
-
opt = Faraday::SSLOptions.new
|
242
|
-
assert_raises Faraday::Options.fetch_error_class do
|
243
|
-
opt.fetch :verify
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_fetch_works_with_key
|
248
|
-
opt = Faraday::SSLOptions.new
|
249
|
-
opt.verify = 1
|
250
|
-
assert_equal 1, opt.fetch(:verify)
|
251
|
-
end
|
252
|
-
end
|