mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
fix brittle URI parser tests failing on Rubinius
The tests relied on the output of Method#to_s, which seems unreliable on non-MRI Rubies. Avoid that and ensure the default_uri_parser is restored.
This commit is contained in:
parent
8080e54f55
commit
bf973245b5
@ -5,10 +5,6 @@ class TestUtils < Faraday::TestCase
|
|||||||
@url = "http://example.com/abc"
|
@url = "http://example.com/abc"
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
|
||||||
Faraday::Utils.default_uri_parser = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# emulates ActiveSupport::SafeBuffer#gsub
|
# emulates ActiveSupport::SafeBuffer#gsub
|
||||||
FakeSafeBuffer = Struct.new(:string) do
|
FakeSafeBuffer = Struct.new(:string) do
|
||||||
def to_s() self end
|
def to_s() self end
|
||||||
@ -26,28 +22,37 @@ class TestUtils < Faraday::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_parses_with_default
|
def test_parses_with_default
|
||||||
assert_equal %(#<Method: Kernel.URI>), Faraday::Utils.default_uri_parser.to_s
|
with_default_uri_parser(nil) do
|
||||||
uri = normalize(@url)
|
uri = normalize(@url)
|
||||||
assert_equal 'example.com', uri.host
|
assert_equal 'example.com', uri.host
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_parses_with_URI
|
def test_parses_with_URI
|
||||||
Faraday::Utils.default_uri_parser = ::URI
|
with_default_uri_parser(::URI) do
|
||||||
assert_equal %(#<Method: URI.parse>), Faraday::Utils.default_uri_parser.to_s
|
|
||||||
uri = normalize(@url)
|
uri = normalize(@url)
|
||||||
assert_equal 'example.com', uri.host
|
assert_equal 'example.com', uri.host
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parses_with_block
|
|
||||||
Faraday::Utils.default_uri_parser = lambda do |uri|
|
|
||||||
"booya#{"!" * uri.size}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parses_with_block
|
||||||
|
with_default_uri_parser(lambda {|u| "booya#{"!" * u.size}" }) do
|
||||||
assert_equal 'booya!!!!!!!!!!!!!!!!!!!!!!', normalize(@url)
|
assert_equal 'booya!!!!!!!!!!!!!!!!!!!!!!', normalize(@url)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def normalize(url)
|
def normalize(url)
|
||||||
Faraday::Utils::URI(url)
|
Faraday::Utils::URI(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_default_uri_parser(parser)
|
||||||
|
old_parser = Faraday::Utils.default_uri_parser
|
||||||
|
begin
|
||||||
|
Faraday::Utils.default_uri_parser = parser
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Faraday::Utils.default_uri_parser = old_parser
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user