Class: SPV::DSL::Adjuster

Inherits:
InitialAdjuster show all
Defined in:
lib/site_prism_vcr/dsl/adjuster.rb

Overview

This class extends SPV::DSL::InitialAdjuster with new methods which can be used in a block for manipulating fixtures before applying them.

Defined Under Namespace

Classes: Action

Instance Method Summary collapse

Methods inherited from InitialAdjuster

#fixtures, #home_path, #path, #shortcut_path, #waiter

Constructor Details

#initialize(options, fixtures) ⇒ Adjuster

Returns a new instance of Adjuster.



8
9
10
11
12
13
# File 'lib/site_prism_vcr/dsl/adjuster.rb', line 8

def initialize(options, fixtures)
  super options

  @options, @fixtures = options, fixtures
  @action = Action.new(:replace)
end

Instance Method Details

#exchange(old_fixtures, new_fixtures) ⇒ void

This method returns an undefined value.

Exchanges certain default fixtures with another fixtures.

Parameters:

  • old_fixtures (String, Array<String>)

    List of fixtures which should be removed. If string is passed instead of an array, it will be converted to an array.

  • new_fixtures (String, Array<String>)

    List of fixtures which should added. If string is passed instead of an array, it will be converted to an array.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/site_prism_vcr/dsl/adjuster.rb', line 63

def exchange(old_fixtures, new_fixtures)
  home_path_modifier = Fixtures::Modifiers::ShortcutPath.new(@options)

  old_fixtures = [old_fixtures] unless old_fixtures.is_a?(Array)
  new_fixtures = [new_fixtures] unless new_fixtures.is_a?(Array)

  old_fixtures, new_fixtures = @fixtures_handler.handle_set_raws(
    old_fixtures,
    new_fixtures,
    [home_path_modifier]
  )

  @fixtures = @fixtures.exchange(
    old_fixtures,
    new_fixtures
  )
end

#prepare_fixturesSPV::Fixtures

Performs the replace action when no explicit action is defined in a block for manipulating fixtures before applying them. Otherwise, performs a defined action (union or replace).

Returns:



101
102
103
104
105
106
# File 'lib/site_prism_vcr/dsl/adjuster.rb', line 101

def prepare_fixtures
  @fixtures.public_send(
    @action.action,
    @tmp_keeper.fixtures
  )
end

#replacevoid

This method returns an undefined value.

Defines the replace action as an action which will be performed over cassettes while adjusting cassettes.

Example:

@page.details_link.click_and_apply_vcr do
  fixtures ['no_found']
  replace
end

In this case ‘no_found’ cassette will be used instead of default cassettes defined for ‘details_link’.



30
31
32
# File 'lib/site_prism_vcr/dsl/adjuster.rb', line 30

def replace
  @action.action = :replace
end

#unionvoid

This method returns an undefined value.

Defines the union action as an action which will be performed over cassettes while adjusting cassettes.

Example:

@page.details_link.click_and_apply_vcr do
  fixtures ['no_found']
  union
end

In this case ‘no_found’ cassette will be used a long with default cassettes.



49
50
51
# File 'lib/site_prism_vcr/dsl/adjuster.rb', line 49

def union
  @action.action = :union
end

#waiter_options(options) ⇒ void

This method returns an undefined value.

Redefines default waiter options or if default waiter options is not defined, it defines new options for a waiter. This method doesn’t redefine all default options, it redefines only options passed in a hash.

Parameters:

  • options (Hash)

    Options for a waiter



90
91
92
# File 'lib/site_prism_vcr/dsl/adjuster.rb', line 90

def waiter_options(options)
  @options.merge_waiter_options!(options)
end