Class: Sitespec::Artifact

Inherits:
Object
  • Object
show all
Defined in:
lib/sitespec/artifact.rb

Overview

“Artifact” is corresponding to each response body to an endpoint. This class has ActiveRecord-like interface like Sitespec::Artifact.create.

Examples:

Sitespec::Artifact.create(example: example, example_group: example_group)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example: nil, example_group: nil) ⇒ Artifact

Returns a new instance of Artifact.

Parameters:

  • example (RSpec::Core::Example) (defaults to: nil)

    In almost cases, ‘RSpec.current_example` is passed

  • example_group (RSpec::Core::ExampleGroup) (defaults to: nil)

    In almost cases, ‘self` is passed



22
23
24
25
# File 'lib/sitespec/artifact.rb', line 22

def initialize(example: nil, example_group: nil)
  @example = example
  @example_group = example_group
end

Class Method Details

.create(**args) ⇒ Sitespec::Artifact

Short-hand method to call ‘.new` and `#save`

Returns:



15
16
17
# File 'lib/sitespec/artifact.rb', line 15

def create(**args)
  new(**args).tap(&:save)
end

Instance Method Details

#savefalse, true

Validate its attributes and generate a new file

Returns:

  • (false, true)

    True for successful case, otherwise false



29
30
31
32
33
34
35
36
37
# File 'lib/sitespec/artifact.rb', line 29

def save
  if valid?
    write
    increment
    true
  else
    false
  end
end