Class: RSpec::Core::SharedExampleGroupInclusionStackFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/example_group.rb

Overview

Contains information about the inclusion site of a shared example group.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shared_group_name, inclusion_location) ⇒ SharedExampleGroupInclusionStackFrame

Returns a new instance of SharedExampleGroupInclusionStackFrame



769
770
771
772
# File 'lib/rspec/core/example_group.rb', line 769

def initialize(shared_group_name, inclusion_location)
  @shared_group_name  = shared_group_name
  @inclusion_location = inclusion_location
end

Instance Attribute Details

#inclusion_locationString (readonly)

Returns the location where the shared example was included

Returns:

  • (String)

    the location where the shared example was included



767
768
769
# File 'lib/rspec/core/example_group.rb', line 767

def inclusion_location
  @inclusion_location
end

#shared_group_nameString (readonly)

Returns the name of the shared example group

Returns:

  • (String)

    the name of the shared example group



765
766
767
# File 'lib/rspec/core/example_group.rb', line 765

def shared_group_name
  @shared_group_name
end

Class Method Details

.current_backtraceObject



791
792
793
# File 'lib/rspec/core/example_group.rb', line 791

def self.current_backtrace
  shared_example_group_inclusions.reverse
end

.shared_example_group_inclusionsObject



809
810
811
# File 'lib/rspec/core/example_group.rb', line 809

def self.shared_example_group_inclusions
  RSpec::Support.thread_local_data[:shared_example_group_inclusions] ||= []
end

.with_frame(name, location) ⇒ Object



796
797
798
799
800
801
802
803
804
805
806
# File 'lib/rspec/core/example_group.rb', line 796

def self.with_frame(name, location)
  current_stack = shared_example_group_inclusions
  if current_stack.any? { |frame| frame.shared_group_name == name }
    raise ArgumentError, "can't include shared examples recursively"
  else
    current_stack << new(name, location)
    yield
  end
ensure
  current_stack.pop
end

Instance Method Details

#descriptionString

Returns Description of this stack frame, in the form used by RSpec's built-in formatters.

Returns:

  • (String)

    Description of this stack frame, in the form used by RSpec's built-in formatters.



785
786
787
788
# File 'lib/rspec/core/example_group.rb', line 785

def description
  @description ||= "Shared Example Group: #{shared_group_name.inspect} " \
    "called from #{formatted_inclusion_location}"
end

#formatted_inclusion_locationString

Returns The #inclusion_location, formatted for display by a formatter.

Returns:



775
776
777
778
779
780
781
# File 'lib/rspec/core/example_group.rb', line 775

def formatted_inclusion_location
  @formatted_inclusion_location ||= begin
    RSpec.configuration.backtrace_formatter.backtrace_line(
      inclusion_location.sub(/(:\d+):in .+$/, '\1')
    )
  end
end