Class: EnvTest

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

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

#setupObject



4
5
6
7
8
9
10
11
12
13
# File 'test/env_test.rb', line 4

def setup
  @conn = Faraday.new :url => 'http://sushi.com/api',
    :headers => {'Mime-Version' => '1.0'},
    :request => {:oauth => {:consumer_key => 'anonymous'}}

  @conn.options.timeout      = 3
  @conn.options.open_timeout = 5
  @conn.ssl.verify           = false
  @conn.proxy 'http://proxy.com'
end

#test_global_request_optionsObject



43
44
45
46
47
# File 'test/env_test.rb', line 43

def test_global_request_options
  env = make_env
  assert_equal 3, env.request.timeout
  assert_equal 5, env.request.open_timeout
end

#test_per_request_optionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'test/env_test.rb', line 49

def test_per_request_options
  env = make_env do |req|
    req.options.timeout = 10
    req.options.boundary = 'boo'
    req.options.oauth[:consumer_secret] = 'xyz'
  end
  assert_equal 10, env.request.timeout
  assert_equal 5, env.request.open_timeout
  assert_equal 'boo', env.request.boundary

  oauth_expected = {:consumer_secret => 'xyz', :consumer_key => 'anonymous'}
  assert_equal oauth_expected, env.request.oauth
end

#test_request_create_stores_bodyObject



36
37
38
39
40
41
# File 'test/env_test.rb', line 36

def test_request_create_stores_body
  env = make_env do |req|
    req.body = 'hi'
  end
  assert_equal 'hi', env.body
end

#test_request_create_stores_headersObject



27
28
29
30
31
32
33
34
# File 'test/env_test.rb', line 27

def test_request_create_stores_headers
  env = make_env do |req|
    req['Server'] = 'Faraday'
  end
  headers = env.request_headers
  assert_equal '1.0', headers['mime-version']
  assert_equal 'Faraday', headers['server']
end

#test_request_create_stores_methodObject



15
16
17
18
# File 'test/env_test.rb', line 15

def test_request_create_stores_method
  env = make_env(:get)
  assert_equal :get, env.method
end

#test_request_create_stores_proxy_optionsObject



68
69
70
71
# File 'test/env_test.rb', line 68

def test_request_create_stores_proxy_options
  env = make_env
  assert_equal 'proxy.com', env.request.proxy.host
end

#test_request_create_stores_ssl_optionsObject



63
64
65
66
# File 'test/env_test.rb', line 63

def test_request_create_stores_ssl_options
  env = make_env
  assert_equal false, env.ssl.verify
end

#test_request_create_stores_uriObject



20
21
22
23
24
25
# File 'test/env_test.rb', line 20

def test_request_create_stores_uri
  env = make_env do |req|
    req.url 'foo.json', 'a' => 1
  end
  assert_equal 'http://sushi.com/api/foo.json?a=1', env.url.to_s
end