Module: RSpec::SleepingKingStudios::Deferred

Defined in:
lib/rspec/sleeping_king_studios/deferred.rb,
lib/rspec/sleeping_king_studios/deferred/dsl.rb,
lib/rspec/sleeping_king_studios/deferred/call.rb,
lib/rspec/sleeping_king_studios/deferred/calls.rb,
lib/rspec/sleeping_king_studios/deferred/missing.rb,
lib/rspec/sleeping_king_studios/deferred/consumer.rb,
lib/rspec/sleeping_king_studios/deferred/examples.rb,
lib/rspec/sleeping_king_studios/deferred/provider.rb,
lib/rspec/sleeping_king_studios/deferred/definitions.rb,
lib/rspec/sleeping_king_studios/deferred/dependencies.rb

Overview

Namespace for deferred example functionality.

Defined Under Namespace

Modules: Calls, Consumer, Definitions, Dependencies, Dsl, Examples, Missing, Provider Classes: Call

Class Method Summary collapse

Class Method Details

.reflect(example, source_locations: false) ⇒ String

Returns the full path of an example, including deferred example groups.

By default, returns the path in a single-line format similar to an example group description. Deferred example groups are parenthesized. When the :source_locations flag is set to true, it instead returns each example group or deferred group on its own line, along with the source location for that group.

Examples:

Displaying the full path of failing specs:

config.after(:example) do |example|
  next unless ENV['REFLECT_ON_FAILURE']
  next unless example.[:last_run_status] == 'failed'

  STDERR.puts "\nFailing spec at:"

  path =
    RSpec::SleepingKingStudios::Deferred
      .reflect(example, source_locations: true)
  path =
    SleepingKingStudios::Tools::Toolbelt
      .instance
      .string_tools
      .indent(path)

  STDERR.puts path
end


51
52
53
54
55
56
57
58
59
60
# File 'lib/rspec/sleeping_king_studios/deferred.rb', line 51

def reflect(example, source_locations: false)
  return short_description_for(example) unless source_locations

  each_ancestor_group_for(example)
    .reverse_each
    .reduce([]) do |lines, group|
      lines << format_full_description(group)
    end
    .join("\n")
end