Class: SPV::Applier

Inherits:
Object
  • Object
show all
Defined in:
lib/site_prism_vcr/applier.rb

Overview

This class manages defining default fixtures and applying them on an event.

Defined Under Namespace

Classes: EventError

Instance Method Summary collapse

Constructor Details

#initialize(node, &block) ⇒ Applier

Returns a new instance of Applier.



7
8
9
10
11
12
13
14
15
16
# File 'lib/site_prism_vcr/applier.rb', line 7

def initialize(node, &block)
  @node, @options = node, Options.new
  adjuster = DSL::InitialAdjuster.new(@options)

  if block_given?
    adjuster.instance_eval &block
  end

  @fixtures = adjuster.prepare_fixtures
end

Instance Method Details

#alter_fixtures(&block) ⇒ void

This method returns an undefined value.

Alters default fixtures and options.

Parameters:

  • adjusting_block (Proc)

    It allows to change fixtures through DSL (@see SPV::DSL::InitialAdjuster and @see SPV::DSL::Adjuster)



48
49
50
51
52
# File 'lib/site_prism_vcr/applier.rb', line 48

def alter_fixtures(&block)
  @fixtures = adjust_fixtures(
    @options, &block
  )
end

#apply_vcr(&block) ⇒ void

This method returns an undefined value.

Applies fixtures to be used for stubbing HTTP interactions caused by an event (click on an element or page loading).

Makes a defined waiter to meet expectation before ejecting fixtures from VCR.

Parameters:

  • adjusting_block (nil, Proc)

    If an adjusting block is given, it allows to change fixtures through DSL (@see SPV::DSL::InitialAdjuster and @see SPV::DSL::Adjuster)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/site_prism_vcr/applier.rb', line 67

def apply_vcr(&block)
  verify_define_event!

  fixtures, options = @fixtures, @options.clone_options

  if block_given?
    fixtures = adjust_fixtures(options, &block)
  end

  fixtures_manager = Fixtures::Manager.inject(
    fixtures, options
  )

  @event_action.call

  Waiter.wait(
    @node,
    fixtures_manager,
    options
  )
end

#shift_event(&block) ⇒ SPV::Applier

Stores a block with an action (click, scroll down, mouse over etc) VCR should be applied on.

This block will be called over an object VCR linked to.

Example:
  @my_element.shift_event do
    self.click
  end

Parameters:

  • block (Proc)

Returns:



33
34
35
36
37
# File 'lib/site_prism_vcr/applier.rb', line 33

def shift_event(&block)
  @event_action = block

  self
end