Module: Crabfarm::RSpec

Defined in:
lib/crabfarm/rspec.rb

Instance Method Summary collapse

Instance Method Details

#crawl(_state = nil, _params = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crabfarm/rspec.rb', line 23

def crawl(_state=nil, _params={})
  if _state.is_a? Hash
    _params = _state
    _state = nil
  end

  if _state.nil?
    return nil unless described_class < BaseState # TODO: maybe raise an error here.
    @state = @last_state = TransitionService.apply_state CF_TEST_CONTEXT, described_class, _params
  else
    @last_state = TransitionService.apply_state CF_TEST_CONTEXT, _state, _params
  end
end

#last_stateObject



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

def last_state
  @last_state
end

#parse(_snap_or_url, _options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/crabfarm/rspec.rb', line 10

def parse(_snap_or_url, _options={})
  fixture = Pathname.new(File.join(ENV['SNAPSHOT_DIR'], _snap_or_url))
  html = if fixture.exist?
    File.read fixture.realpath
  else
    Net::HTTP.get(URI.parse _snap_or_url)
  end

  parser = described_class.new html, _options
  parser.parse
  parser
end

#parserObject



45
46
47
# File 'lib/crabfarm/rspec.rb', line 45

def parser
  @parser
end

#stateObject



37
38
39
# File 'lib/crabfarm/rspec.rb', line 37

def state
  @state ||= crawl
end