Class: RSpec::Core::SharedExampleGroupModule

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

Overview

Represents some functionality that is shared with multiple example groups. The functionality is defined by the provided block, which is lazily eval'd when the `SharedExampleGroupModule` instance is included in an example group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, definition, metadata) ⇒ SharedExampleGroupModule

Returns a new instance of SharedExampleGroupModule



11
12
13
14
15
# File 'lib/rspec/core/shared_example_group.rb', line 11

def initialize(description, definition, )
  @description = description
  @definition  = definition
  @metadata    = 
end

Instance Attribute Details

#definitionObject (readonly)



9
10
11
# File 'lib/rspec/core/shared_example_group.rb', line 9

def definition
  @definition
end

Instance Method Details

#include_in(klass, inclusion_line, args, customization_block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rspec/core/shared_example_group.rb', line 32

def include_in(klass, inclusion_line, args, customization_block)
  klass.(@metadata) unless @metadata.empty?

  SharedExampleGroupInclusionStackFrame.with_frame(@description, inclusion_line) do
    klass.class_exec(*args, &@definition)
    klass.class_exec(&customization_block) if customization_block
  end
end

#included(klass) ⇒ Object

Ruby callback for when a module is included in another module is class. Our definition evaluates the shared group block in the context of the including example group.



26
27
28
29
# File 'lib/rspec/core/shared_example_group.rb', line 26

def included(klass)
  inclusion_line = klass.[:location]
  include_in klass, inclusion_line, [], nil
end

#inspectObject Also known as: to_s

Provides a human-readable representation of this module.



18
19
20
# File 'lib/rspec/core/shared_example_group.rb', line 18

def inspect
  "#<#{self.class.name} #{@description.inspect}>"
end