PageRenderTime 414ms CodeModel.GetById 141ms app.highlight 11ms RepoModel.GetById 139ms app.codeStats 1ms

/features/steps/httparty_response_steps.rb

http://github.com/jnunemaker/httparty
Ruby | 52 lines | 41 code | 9 blank | 2 comment | 2 complexity | 8600883aa5828f65095a7eb51094d510 MD5 | raw file
 1# Not needed anymore in ruby 2.0, but needed to resolve constants
 2# in nested namespaces. This is taken from rails :)
 3def constantize(camel_cased_word)
 4  names = camel_cased_word.split('::')
 5  names.shift if names.empty? || names.first.empty?
 6
 7  constant = Object
 8  names.each do |name|
 9    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
10  end
11  constant
12end
13
14Then /it should return an? ([\w\:]+)$/ do |class_string|
15  expect(@response_from_httparty.parsed_response).to be_a(Object.const_get(class_string))
16end
17
18Then /the return value should match '(.*)'/ do |expected_text|
19  expect(@response_from_httparty.parsed_response).to eq(expected_text)
20end
21
22Then /it should return a Hash equaling:/ do |hash_table|
23  expect(@response_from_httparty.parsed_response).to be_a(Hash)
24  expect(@response_from_httparty.keys.length).to eq(hash_table.rows.length)
25  hash_table.hashes.each do |pair|
26    key, value = pair["key"], pair["value"]
27    expect(@response_from_httparty.keys).to include(key)
28    expect(@response_from_httparty[key]).to eq(value)
29  end
30end
31
32Then /it should return an Array equaling:/ do |array|
33  expect(@response_from_httparty.parsed_response).to be_a(Array)
34  expect(@response_from_httparty.parsed_response).to eq(array.raw)
35end
36
37Then /it should return a response with a (\d+) response code/ do |code|
38  expect(@response_from_httparty.code).to eq(code.to_i)
39end
40
41Then /it should return a response without a content\-encoding$/ do
42  expect(@response_from_httparty.headers['content-encoding']).to be_nil
43end
44
45Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
46  expect(@exception_from_httparty).to_not be_nil
47  expect(@exception_from_httparty).to be_a constantize(exception)
48end
49
50Then /it should not raise (?:an|a) ([\w:]+) exception/ do |exception|
51  expect(@exception_from_httparty).to be_nil
52end