Class: Quarry::Spec::Runner

Inherits:
Object show all
Defined in:
lib/quarry/spec/runner.rb

Overview

Specificaton Runner

The Runner class loops through a set of specifications and executes each one in turn.

The current working directory is changed to that of the specification script’s. So any relative file references within a spec must take that into account.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specs, output = nil) ⇒ Runner

New Specification



45
46
47
48
# File 'lib/quarry/spec/runner.rb', line 45

def initialize(specs, output=nil)
  @specs  = [specs].flatten
  @output = output || Spec::Reporter::DotProgress.new #(self)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



41
42
43
# File 'lib/quarry/spec/runner.rb', line 41

def context
  @context
end

#outputObject (readonly)

Returns the value of attribute output.



39
40
41
# File 'lib/quarry/spec/runner.rb', line 39

def output
  @output
end

#specsObject (readonly)

Quarry::Spec::Runner.configure do

  def setup(spec)
    ...
  end
  def teardown(spec)
    ...
  end
end

def self.configure(plugin=nil, &block)

if block_given?
  m = Module.new(&block)
  m.extend m
  @config << m
end
if plugin
  @config << plugin
end

end



38
39
40
# File 'lib/quarry/spec/runner.rb', line 38

def specs
  @specs
end

Instance Method Details

#checkObject

Each spec gets it’s own context.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/quarry/spec/runner.rb', line 51

def check
  output.report_intro
  # loop through each specification and run it
  specs.each do |spec|
    # create a run context for the spec
    @context = Context.new
    # run the specification
    check_spec(spec)
  end
  output.report_summary
end

#check_spec(spec) ⇒ Object

Run a specification.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/quarry/spec/runner.rb', line 65

def check_spec(spec)
  #report(spec.description)

  # pretty sure this is the thing to do
  Dir.chdir(File.dirname(spec.file)) do

    output.report_start(spec)

    # TODO <-- plugin in here start (how to set?)
    #context.instance_eval(&spec.given) if spec.given

    spec.steps.each do |step|
      case step
      when Header
        output.report_header(step)
      when Macro
        case step.type
        when :before
          @before = step.code
        when :after
          @after = step.code
        else
          context.instance_eval(step.code, spec.file, step.lineno)
        end
        output.report_macro(step)
      when Comment
        output.report_comment(step)
      else
        run_step(spec, step) if step.code
      end
    end

    # TODO <-- plugin in here end
    #context.instance_eval(&spec.complete) if spec.complete

    output.report_end(spec)
  end
end

#run_step(spec, step) ⇒ Object

Run a specification step.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/quarry/spec/runner.rb', line 106

def run_step(spec, step)
  output.report_step(step)
  # TODO: Would spec.before + spec.code be better?
  context.instance_eval(@before, spec.file) if @before
  begin
    context.instance_eval(step.code, spec.file, step.lineno)
    output.report_pass(step)
  rescue Assertion => error
    output.report_fail(step, error)
  rescue Exception => error
    output.report_error(step, error)
  ensure
    context.instance_eval(@after, spec.file) if @after
  end
end