Class: Quarry::Markup::Step

Inherits:
Object show all
Defined in:
lib/quarry/markup/step.rb

Overview

Step

Direct Known Subclasses

Table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, code, lineno, ioc = {}) ⇒ Step

Returns a new instance of Step.



16
17
18
19
20
21
22
23
# File 'lib/quarry/markup/step.rb', line 16

def initialize(spec, code, lineno, ioc={})
  @spec   = spec
  @code   = code.rstrip
  @lineno = lineno

  @before = ioc[:before]
  @after  = ioc[:after]
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



14
15
16
# File 'lib/quarry/markup/step.rb', line 14

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



13
14
15
# File 'lib/quarry/markup/step.rb', line 13

def before
  @before
end

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/quarry/markup/step.rb', line 10

def code
  @code
end

#linenoObject (readonly)

Returns the value of attribute lineno.



11
12
13
# File 'lib/quarry/markup/step.rb', line 11

def lineno
  @lineno
end

#specObject (readonly) Also known as: parent

Returns the value of attribute spec.



9
10
11
# File 'lib/quarry/markup/step.rb', line 9

def spec
  @spec
end

Instance Method Details

#run(runner, spec, context, output) ⇒ Object

Run specification step.

TODO: Would spec.before + spec.code be better?



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/quarry/markup/step.rb', line 35

def run(runner, spec, context, output)
  output.report_step(self)
  #context.instance_eval(runner.before, spec.file) if runner.before
  context.instance_eval(before.code, spec.file) if before
  begin
    context.instance_eval(code, spec.file, lineno)
    output.report_pass(self)
  rescue Assertion => error
    output.report_fail(self, error)
  rescue Exception => error
    output.report_error(self, error)
  ensure
    context.instance_eval(after.code, spec.file) if after
    #context.instance_eval(runner.after, spec.file) if runner.after
  end
end

#tabObject



53
54
55
# File 'lib/quarry/markup/step.rb', line 53

def tab
  @tab ||= to_s.index(/\S/)
end

#to_sObject



58
59
60
# File 'lib/quarry/markup/step.rb', line 58

def to_s
  code
end

#to_scriptObject

As could appear in stand-alone script.



63
64
65
66
67
68
69
# File 'lib/quarry/markup/step.rb', line 63

def to_script
  script = []
  script << before.code if before
  script << code
  script << before.code if after
  script .join("\n")
end