Module: SimpleCov::RSpec::DescribedSourceFiles Private
- Defined in:
- lib/simplecov-rspec/described_source_files.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Finds the source files that define the classes an RSpec run described.
This is the scope most people want from list_uncovered_files: on a focused run:
"report on the code I am actually testing". Deriving it means reaching into
RSpec.world, which is not part of RSpec's public API, so it lives here rather
than in each project's spec_helper.rb, where it could not be fixed centrally.
Class Method Summary collapse
-
.call(example_groups: ::RSpec.world.example_groups) ⇒ Array<String>
private
The source files defining the classes the run described.
-
.source_file(group) ⇒ String?
private
The source file defining one group's described class, if it has one.
-
.with_nested(groups) ⇒ Array<Class>
private
The given example groups, plus every group nested within them.
Class Method Details
.call(example_groups: ::RSpec.world.example_groups) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The source files defining the classes the run described
A group that describes something other than a Module contributes nothing, as does one whose described class is anonymous, defined in C, or no longer reachable by name. Such a group has no source file to report on, and saying so is not useful, so it is skipped silently.
33 34 35 |
# File 'lib/simplecov-rspec/described_source_files.rb', line 33 def call(example_groups: ::RSpec.world.example_groups) with_nested(example_groups).filter_map { |group| source_file(group) }.uniq end |
.source_file(group) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The source file defining one group's described class, if it has one
66 67 68 69 70 71 72 73 |
# File 'lib/simplecov-rspec/described_source_files.rb', line 66 def source_file(group) described_class = group.described_class return nil unless described_class.is_a?(Module) # A class defined in C answers [], one whose constant is gone answers nil name = described_class.name name && Object.const_source_location(name)&.first end |
.with_nested(groups) ⇒ Array<Class>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The given example groups, plus every group nested within them
A nested group can describe a different class than the group containing it, so the whole tree is walked rather than just the top level.
51 52 53 |
# File 'lib/simplecov-rspec/described_source_files.rb', line 51 def with_nested(groups) groups.flat_map { |group| [group, *with_nested(group.children)] } end |