Module: Crabfarm::RSpec

Defined in:
lib/crabfarm/rspec.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#browser(_session_id = nil) ⇒ Object



56
57
58
# File 'lib/crabfarm/rspec.rb', line 56

def browser(_session_id=nil)
  @context.pool.browser(_session_id)
end

#last_stateObject



48
49
50
# File 'lib/crabfarm/rspec.rb', line 48

def last_state
  @last_state
end


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/crabfarm/rspec.rb', line 25

def navigate(_name=nil, _params={})

  raise Error.new "'navigate' is only available in navigator specs" if @context.nil?

  if _name.is_a? Hash
    _params = _name
    _name = nil
  end

  if _name.nil?
    return nil unless described_class < BaseNavigator # TODO: maybe raise an error here.
    @state = @last_state = TransitionService.transition @context, described_class, _params
  else
    @last_state = TransitionService.transition @context, _name, _params
  end
end

#reduce(_snapshot = nil, _options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/crabfarm/rspec.rb', line 6

def reduce(_snapshot=nil, _options={})

  raise Error.new "'reduce' is only available in reducer specs" unless described_class < Crabfarm::BaseReducer

  if _snapshot.is_a? Hash
    raise ArgumentException.new 'Invalid arguments' unless _options.nil?
    _options = _snapshot
    _snapshot = nil
  end

  snapshot_path = described_class.snapshot_path _snapshot
  raise Error.new "Snapshot does not exist #{_snapshot}" unless File.exist? snapshot_path

  data = File.read snapshot_path
  reducer = described_class.new data, _options
  reducer.run
  reducer
end

#reducerObject



52
53
54
# File 'lib/crabfarm/rspec.rb', line 52

def reducer
  @reducer ||= reduce
end

#stateObject Also known as: navigator



42
43
44
# File 'lib/crabfarm/rspec.rb', line 42

def state
  @state ||= navigate
end