Class: Spec::Runner::Specification

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}, &spec_block) ⇒ Specification

Returns a new instance of Specification.



15
16
17
18
19
20
21
# File 'lib/spec/runner/specification.rb', line 15

def initialize(name, opts={}, &spec_block)
  @from = caller(0)[3]
  @description = name
  @options = opts
  @spec_block = spec_block
  @description_generated_callback = lambda { |desc| @generated_description = desc }
end

Class Attribute Details

.currentObject

Returns the value of attribute current.



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

def current
  @current
end

.generated_descriptionObject

Returns the value of attribute generated_description.



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

def generated_description
  @generated_description
end

Instance Attribute Details

#spec_blockObject (readonly)

Returns the value of attribute spec_block.



12
13
14
# File 'lib/spec/runner/specification.rb', line 12

def spec_block
  @spec_block
end

Instance Method Details

#matches?(matcher, description) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(matcher, description)
  matcher.spec_desc = name
  matcher.matches?(description)
end

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/spec/runner/specification.rb', line 23

def run(reporter, setup_block, teardown_block, dry_run, execution_context)
  reporter.spec_started(name) if reporter
  return reporter.spec_finished(name) if dry_run

  errors = []
  begin
    set_current
    setup_ok = setup_spec(execution_context, errors, &setup_block)
    spec_ok = execute_spec(execution_context, errors) if setup_ok
    teardown_ok = teardown_spec(execution_context, errors, &teardown_block)
  ensure
    clear_current
  end

  SpecShouldRaiseHandler.new(@from, @options).handle(errors)
  reporter.spec_finished(name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) if reporter
end