Class: Spec::Runner::Specification

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

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Specification

Returns a new instance of Specification.



5
6
7
8
9
# File 'lib/spec/runner/specification.rb', line 5

def initialize(name, &block)
  @name = name
  @block = block
  @mocks = []
end

Instance Method Details

#add_mock(mock) ⇒ Object



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

def add_mock(mock)
  @mocks << mock
end

#matches_matcher?(matcher) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/spec/runner/specification.rb', line 42

def matches_matcher?(matcher)
  matcher.matches? @name 
end

#run(reporter = nil, setup_block = nil, teardown_block = nil, dry_run = false, execution_context = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spec/runner/specification.rb', line 11

def run(reporter=nil, setup_block=nil, teardown_block=nil, dry_run=false, execution_context=nil)
  reporter.spec_started(@name)
  return reporter.spec_finished(@name) if dry_run
  execution_context = execution_context || ::Spec::Runner::ExecutionContext.new(self)
  errors = []
  begin
    execution_context.instance_exec(&setup_block) unless setup_block.nil?
    setup_ok = true
    execution_context.instance_exec(&@block)
    spec_ok = true
  rescue => e
    errors << e
  end

  begin
    execution_context.instance_exec(&teardown_block) unless teardown_block.nil?
    teardown_ok = true
    @mocks.each do |mock|
      mock.__verify
    end
  rescue => e
    errors << e
  end

  reporter.spec_finished(@name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) unless reporter.nil?
end