Class: TestUtils

Inherits:
Faraday::TestCase show all
Defined in:
test/utils_test.rb

Defined Under Namespace

Classes: FakeSafeBuffer

Instance Method Summary collapse

Methods inherited from Faraday::TestCase

#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default

Methods included from Faraday::LiveServerConfig

#live_server, #live_server=, #live_server?

Instance Method Details

#normalize(url) ⇒ Object



44
45
46
# File 'test/utils_test.rb', line 44

def normalize(url)
  Faraday::Utils::URI(url)
end

#setupObject



4
5
6
# File 'test/utils_test.rb', line 4

def setup
  @url = "http://example.com/abc"
end

#test_escaping_safe_bufferObject



19
20
21
22
# File 'test/utils_test.rb', line 19

def test_escaping_safe_buffer
  str = FakeSafeBuffer.new('$32,000.00')
  assert_equal '%2432%2C000.00', Faraday::Utils.escape(str)
end

#test_parses_with_blockObject



38
39
40
41
42
# File 'test/utils_test.rb', line 38

def test_parses_with_block
  with_default_uri_parser(lambda {|u| "booya#{"!" * u.size}" }) do
    assert_equal 'booya!!!!!!!!!!!!!!!!!!!!!!', normalize(@url)
  end
end

#test_parses_with_defaultObject



24
25
26
27
28
29
# File 'test/utils_test.rb', line 24

def test_parses_with_default
  with_default_uri_parser(nil) do
    uri = normalize(@url)
    assert_equal 'example.com', uri.host
  end
end

#test_parses_with_URIObject



31
32
33
34
35
36
# File 'test/utils_test.rb', line 31

def test_parses_with_URI
  with_default_uri_parser(::URI) do
    uri = normalize(@url)
    assert_equal 'example.com', uri.host
  end
end

#with_default_uri_parser(parser) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'test/utils_test.rb', line 48

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