/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 :)
  3. def constantize(camel_cased_word)
  4. names = camel_cased_word.split('::')
  5. names.shift if names.empty? || names.first.empty?
  6. constant = Object
  7. names.each do |name|
  8. constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  9. end
  10. constant
  11. end
  12. Then /it should return an? ([\w\:]+)$/ do |class_string|
  13. expect(@response_from_httparty.parsed_response).to be_a(Object.const_get(class_string))
  14. end
  15. Then /the return value should match '(.*)'/ do |expected_text|
  16. expect(@response_from_httparty.parsed_response).to eq(expected_text)
  17. end
  18. Then /it should return a Hash equaling:/ do |hash_table|
  19. expect(@response_from_httparty.parsed_response).to be_a(Hash)
  20. expect(@response_from_httparty.keys.length).to eq(hash_table.rows.length)
  21. hash_table.hashes.each do |pair|
  22. key, value = pair["key"], pair["value"]
  23. expect(@response_from_httparty.keys).to include(key)
  24. expect(@response_from_httparty[key]).to eq(value)
  25. end
  26. end
  27. Then /it should return an Array equaling:/ do |array|
  28. expect(@response_from_httparty.parsed_response).to be_a(Array)
  29. expect(@response_from_httparty.parsed_response).to eq(array.raw)
  30. end
  31. Then /it should return a response with a (\d+) response code/ do |code|
  32. expect(@response_from_httparty.code).to eq(code.to_i)
  33. end
  34. Then /it should return a response without a content\-encoding$/ do
  35. expect(@response_from_httparty.headers['content-encoding']).to be_nil
  36. end
  37. Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
  38. expect(@exception_from_httparty).to_not be_nil
  39. expect(@exception_from_httparty).to be_a constantize(exception)
  40. end
  41. Then /it should not raise (?:an|a) ([\w:]+) exception/ do |exception|
  42. expect(@exception_from_httparty).to be_nil
  43. end