Skip to content

Commit

Permalink
Use Gem::Version to determine deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcasper committed Apr 10, 2017
1 parent 3e5e598 commit d86735f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/airborne/request_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ module RequestExpectations
include RSpec
include PathMatcher

INTEGER_TYPES = if RUBY_VERSION.match(/^2.4/)
[Integer]
else
[Fixnum, Bignum]
end

def expect_json_types(*args)
call_with_path(args) do |param, body|
expect_json_types_impl(param, body)
Expand Down Expand Up @@ -237,17 +231,17 @@ def ensure_hash_contains_prop(prop_name, hash)
end

def property?(expectations)
[String, Regexp, Float, *INTEGER_TYPES, TrueClass, FalseClass, NilClass, Array].include?(expectations.class)
[String, Regexp, Float, *integer_types, TrueClass, FalseClass, NilClass, Array].include?(expectations.class)
end

def get_mapper
base_mapper = {
integer: INTEGER_TYPES,
array_of_integers: INTEGER_TYPES,
int: INTEGER_TYPES,
array_of_ints: INTEGER_TYPES,
float: [Float, *INTEGER_TYPES],
array_of_floats: [Float, *INTEGER_TYPES],
integer: integer_types,
array_of_integers: integer_types,
int: integer_types,
array_of_ints: integer_types,
float: [Float, *integer_types],
array_of_floats: [Float, *integer_types],
string: [String],
array_of_strings: [String],
boolean: [TrueClass, FalseClass],
Expand Down Expand Up @@ -289,5 +283,17 @@ def match_actual?
def match_expected?
Airborne.configuration.match_expected?
end

def integer_types
if fixnum_and_bignum_deprecated
[Integer]
else
[Fixnum, Bignum]
end
end

def fixnum_and_bignum_deprecated
@_deprecated ||= (Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4"))
end
end
end

0 comments on commit d86735f

Please sign in to comment.