Skip to content

Commit

Permalink
Exclude version/platform-specific code from simplecov.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Mar 18, 2015
1 parent 2ecdecc commit 76e6976
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,8 @@ def safe_include(mod, host)
def safe_extend(mod, host)
host.extend(mod) unless host.singleton_class < mod
end
else
else # for 1.8.7
# :nocov:
# @private
def safe_include(mod, host)
host.__send__(:include, mod) unless host.included_modules.include?(mod)
Expand All @@ -1271,6 +1272,7 @@ def safe_include(mod, host)
def safe_extend(mod, host)
host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
end
# :nocov:
end

# @private
Expand Down Expand Up @@ -1665,6 +1667,7 @@ def file_glob_from(path, pattern)
end

if RSpec::Support::OS.windows?
# :nocov:
def absolute_pattern?(pattern)
pattern =~ /\A[A-Z]:\\/ || windows_absolute_network_path?(pattern)
end
Expand All @@ -1673,6 +1676,7 @@ def windows_absolute_network_path?(pattern)
return false unless ::File::ALT_SEPARATOR
pattern.start_with?(::File::ALT_SEPARATOR + ::File::ALT_SEPARATOR)
end
# :nocov:
else
def absolute_pattern?(pattern)
pattern.start_with?(File::Separator)
Expand Down
8 changes: 8 additions & 0 deletions lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def self.superclass_before_context_ivars
superclass.before_context_ivars
end
else # 1.8.7
# :nocov:
# @private
def self.superclass_before_context_ivars
if superclass.respond_to?(:before_context_ivars)
Expand All @@ -496,6 +497,7 @@ def self.superclass_before_context_ivars
ancestors.find { |a| a.respond_to?(:before_context_ivars) }.before_context_ivars
end
end
# :nocov:
end

# @private
Expand Down Expand Up @@ -603,8 +605,10 @@ def self.set_ivars(instance, ivars)
end

if RUBY_VERSION.to_f < 1.9
# :nocov:
# @private
INSTANCE_VARIABLE_TO_IGNORE = '@__inspect_output'.freeze
# :nocov:
else
# @private
INSTANCE_VARIABLE_TO_IGNORE = :@__inspect_output
Expand All @@ -627,10 +631,12 @@ def inspect
end

unless method_defined?(:singleton_class) # for 1.8.7
# :nocov:
# @private
def singleton_class
class << self; self; end
end
# :nocov:
end

# Raised when an RSpec API is called in the wrong scope, such as `before`
Expand Down Expand Up @@ -774,13 +780,15 @@ def self.base_name_for(group)
end

if RUBY_VERSION == '1.9.2'
# :nocov:
class << self
alias _base_name_for base_name_for
def base_name_for(group)
_base_name_for(group) + '_'
end
end
private_class_method :_base_name_for
# :nocov:
end

def self.disambiguate(name, const_scope)
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/flat_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ def flat_map(array, &block)
array.flat_map(&block)
end
else # for 1.8.7
# :nocov:
def flat_map(array, &block)
array.map(&block).flatten(1)
end
# :nocov:
end

module_function :flat_map
Expand Down
6 changes: 5 additions & 1 deletion lib/rspec/core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,12 @@ def execute_with(example, procsy)
def hook_description
"around hook at #{Metadata.relative_path(block.source_location.join(':'))}"
end
else
else # for 1.8.7
# :nocov:
def hook_description
"around hook"
end
# :nocov:
end
end

Expand Down Expand Up @@ -622,9 +624,11 @@ def owner_parent_groups
@owner.parent_groups
end
else # Ruby < 2.1 (see https://bugs.ruby-lang.org/issues/8035)
# :nocov:
def owner_parent_groups
@owner_parent_groups ||= [@owner] + @owner.parent_groups
end
# :nocov:
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/memoized_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,15 @@ def self.define_helpers_on(example_group)
# Gets the named constant or yields.
# On 1.8, const_defined? / const_get do not take into
# account the inheritance hierarchy.
# :nocov:
def self.get_constant_or_yield(example_group, name)
if example_group.const_defined?(name)
example_group.const_get(name)
else
yield
end
end
# :nocov:
else
# @private
#
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/core/metadata_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def items_for(request_meta)
end

unless [].respond_to?(:each_with_object) # For 1.8.7
# :nocov:
undef items_for
def items_for(request_meta)
@items_and_filters.inject([]) do |to_return, (item, item_meta)|
Expand All @@ -135,6 +136,7 @@ def items_for(request_meta)
to_return
end
end
# :nocov:
end
end

Expand Down Expand Up @@ -217,13 +219,15 @@ def proc_keys_from(metadata)
end

unless [].respond_to?(:each_with_object) # For 1.8.7
# :nocov:
undef proc_keys_from
def proc_keys_from(metadata)
metadata.inject([]) do |to_return, (key, value)|
to_return << key if Proc === value
to_return
end
end
# :nocov:
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/rspec/core/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,15 @@ def encoding_of(string)
def encoded_string(string)
RSpec::Support::EncodedString.new(string, Encoding.default_external)
end
else
else # for 1.8.7
# :nocov:
def encoding_of(_string)
end

def encoded_string(string)
RSpec::Support::EncodedString.new(string)
end
# :nocov:
end

def backtrace_formatter
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/core/ordering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ module Core
# @private
RandomNumberGenerator = ::Random
else
# :nocov:
RSpec::Support.require_rspec_core "backport_random"
# @private
RandomNumberGenerator = RSpec::Core::Backports::Random
# :nocov:
end

# @private
Expand Down Expand Up @@ -42,6 +44,7 @@ def shuffle(list, rng)
list.shuffle(:random => rng)
end
else
# :nocov:
def shuffle(list, rng)
shuffled = list.dup
shuffled.size.times do |i|
Expand All @@ -52,6 +55,7 @@ def shuffle(list, rng)

shuffled
end
# :nocov:
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ def file_inclusion_specification
end

if RSpec::Support::OS.windows?
# :nocov:
def escape(shell_command)
"'#{shell_command.gsub("'", "\\\\'")}'"
end
# :nocov:
else
require 'shellwords'

Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/shared_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ def formatted_location(block)
if Proc.method_defined?(:source_location)
def ensure_block_has_source_location(_block); end
else # for 1.8.7
# :nocov:
def ensure_block_has_source_location(block)
source_location = yield.split(':')
block.extend Module.new { define_method(:source_location) { source_location } }
end
# :nocov:
end
end
end
Expand Down

0 comments on commit 76e6976

Please sign in to comment.