Module: Dockerspec::Helper::RSpecExampleHelpers

Defined in:
lib/dockerspec/helper/rspec_example_helpers.rb

Overview

Some Helper methods to work with RSpec Examples.

Class Method Summary collapse

Class Method Details

.metadata_has_parent?(metadata) ⇒ Boolean

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.

Checks if the parent RSpec example information exists in the metadata.

Parameters:

  • metadata (Hash)

    RSpec metadata.

Returns:

  • (Boolean)

    Returns true if the parent metadata is available.



35
36
37
# File 'lib/dockerspec/helper/rspec_example_helpers.rb', line 35

def self.()
  .key?(:parent_example_group) || .key?(:example_group)
end

.metadata_parent(metadata) ⇒ Hash

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.

Get the parent RSpec example metadata if available.

Parameters:

  • metadata (Hash)

    RSpec metadata.

Returns:

  • (Hash)

    RSpec metadata from the parent example.



48
49
50
51
52
53
54
# File 'lib/dockerspec/helper/rspec_example_helpers.rb', line 48

def self.()
  if .key?(:parent_example_group)
    [:parent_example_group]
  elsif .key?(:example_group)
    [:example_group]
  end
end

.restore_rspec_context(metadata) ⇒ Object

Restores the Docker running container instance in the Specinfra internal reference.

Gets the correct Runner::Base reference from the RSpec metadata.

Examples:

Restore Specinfra Backend

RSpec.configure do |c|
  c.before(:each) do
     = RSpec.current_example.
    Dockerspec::Runner::Base.restore_rspec_context()
  end
end

Parameters:

  • metadata (Hash)

    RSpec metadata.

Returns:

  • void

See Also:

  • restore


100
101
102
103
104
105
# File 'lib/dockerspec/helper/rspec_example_helpers.rb', line 100

def self.restore_rspec_context()
  o_ary =
    Helper::RSpecExampleHelpers
    .search_objects_with(, :restore_rspec_context)
  o_ary.each(&:restore_rspec_context)
end

.search_objects_with(metadata, meth) ⇒ Array<Object>

Searches for an object in the description of the parent RSpec examples that implements a specific method.

Parameters:

  • metadata (Hash)

    RSpec metadata.

  • meth (Symbol)

    The method name.

Returns:

  • (Array<Object>)

    Returns the objects list.



67
68
69
70
71
72
73
74
75
76
# File 'lib/dockerspec/helper/rspec_example_helpers.rb', line 67

def self.search_objects_with(, meth)
  o_ary = []
  return o_ary if .nil?
  if [:described_class].respond_to?(meth) &&
     [:described_class] != self
    o_ary << [:described_class]
  end
  return o_ary unless ()
  (search_objects_with((), meth) + o_ary).uniq
end