Skip to content

Commit

Permalink
Omit all Ruby < 1.9 only code from test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisarcand committed Apr 29, 2015
1 parent 714c1ed commit 60aae1e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rspec/matchers.rb
Expand Up @@ -933,11 +933,13 @@ def respond_to_missing?(method, *)
method =~ DYNAMIC_MATCHER_REGEX || super
end
else # for 1.8.7
# :nocov:
def respond_to?(method, *)
method = method.to_s
method =~ DYNAMIC_MATCHER_REGEX || super
end
public :respond_to?
# :nocov:
end

# @api private
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/matchers/built_in/base_matcher.rb
Expand Up @@ -116,9 +116,11 @@ def assert_ivars(*expected_ivars)
end

if RUBY_VERSION.to_f < 1.9
# :nocov:
def present_ivars
instance_variables.map { |v| v.to_sym }
end
# :nocov:
else
alias present_ivars instance_variables
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/matchers/built_in/be.rb
Expand Up @@ -220,9 +220,11 @@ def predicate_accessible?

# support 1.8.7, evaluate once at load time for performance
if String === methods.first
# :nocov:
def private_predicate?
@actual.private_methods.include? predicate.to_s
end
# :nocov:
else
def private_predicate?
@actual.private_methods.include? predicate
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/matchers/built_in/has.rb
Expand Up @@ -49,9 +49,11 @@ def predicate_accessible?

# support 1.8.7, evaluate once at load time for performance
if String === methods.first
# :nocov:
def private_predicate?
@actual.private_methods.include? predicate.to_s
end
# :nocov:
else
def private_predicate?
@actual.private_methods.include? predicate
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/matchers/built_in/yield.rb
Expand Up @@ -78,6 +78,7 @@ def assert_valid_expect_block!
"matcher. Pass the argument as a block on to the method you are testing."
end
else
# :nocov:
# On 1.8.7, `lambda { }.arity` and `lambda { |*a| }.arity` both return -1,
# so we can't distinguish between accepting no args and an arg splat.
# It's OK to skip, this, though; it just provides a nice error message
Expand All @@ -86,6 +87,7 @@ def assert_valid_expect_block!
def assert_valid_expect_block!
# nothing to do
end
# :nocov:
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/matchers/composable.rb
Expand Up @@ -148,6 +148,7 @@ def with_matchers_cloned(object)
end

if String.ancestors.include?(Enumerable) # 1.8.7
# :nocov:
# Strings are not enumerable on 1.9, and on 1.8 they are an infinitely
# nested enumerable: since ruby lacks a character class, it yields
# 1-character strings, which are themselves enumerable, composed of a
Expand All @@ -158,6 +159,7 @@ def should_enumerate?(item)
return false if String === item
Enumerable === item && !(Range === item)
end
# :nocov:
else
# @api private
def should_enumerate?(item)
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/matchers/dsl.rb
Expand Up @@ -24,9 +24,11 @@ def warn_about_block_args(name, declarations)
end
end
else
# :nocov:
def warn_about_block_args(*)
# There's no way to detect block params on 1.8 since the method reflection APIs don't expose it
end
# :nocov:
end

RSpec.configure { |c| c.extend self } if RSpec.respond_to?(:configure)
Expand Down Expand Up @@ -410,11 +412,13 @@ def respond_to_missing?(method, include_private=false)
super || @matcher_execution_context.respond_to?(method, include_private)
end
else # for 1.8.7
# :nocov:
# Indicates that this matcher responds to messages
# from the `@matcher_execution_context` as well.
def respond_to?(method, include_private=false)
super || @matcher_execution_context.respond_to?(method, include_private)
end
# :nocov:
end

private
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/matchers/matcher_delegator.rb
Expand Up @@ -19,9 +19,11 @@ def respond_to_missing?(name, include_all=false)
super || base_matcher.respond_to?(name, include_all)
end
else
# :nocov:
def respond_to?(name, include_all=false)
super || base_matcher.respond_to?(name, include_all)
end
# :nocov:
end

def initialize_copy(other)
Expand Down

0 comments on commit 60aae1e

Please sign in to comment.