lib/airborne/request_expectations.rb in airborne-0.1.14 vs lib/airborne/request_expectations.rb in airborne-0.1.15
- old
+ new
@@ -1,7 +1,8 @@
require 'rspec'
require 'date'
+require 'rack/utils'
module Airborne
class ExpectationError < StandardError; end
module RequestExpectations
include RSpec
@@ -30,11 +31,11 @@
expect_json_types(*args)
end
def expect_status(code)
- expect(response.code).to eq(code)
+ expect(response.code).to eq(resolve_status(code, response.code))
end
def expect_header(key, content)
expect_header_impl(key, content)
end
@@ -222,7 +223,22 @@
def is_property?(expectations)
[String, Regexp, Float, Fixnum, Bignum, TrueClass, FalseClass, NilClass].include?(expectations.class)
end
+ # Resolve a supplied status to the appropriate class for the returned
+ # status being tested. This helps reduce brittleness due to '200' != 200
+ # when for the purposes of testing a response it is the same thing.
+ #
+ # @param candidate
+ # @param authority
+ # @return [String]
+ def resolve_status(candidate, authority)
+ candidate = Rack::Utils::SYMBOL_TO_STATUS_CODE[candidate] if candidate.kind_of?(Symbol)
+ case authority
+ when String then candidate.to_s
+ when Fixnum then candidate.to_i
+ else candidate
+ end
+ end
end
end