Class: Spec::DSL::Example

Inherits:
Object show all
Defined in:
lib/spec/dsl/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, options = {}, &example_block) ⇒ Example

Returns a new instance of Example.



9
10
11
12
13
14
15
# File 'lib/spec/dsl/example.rb', line 9

def initialize(description, options={}, &example_block)
  @from = caller(0)[3]
  @options = options
  @example_block = example_block
  @description = description
  @description_generated_proc = lambda { |desc| @generated_description = desc }
end

Instance Attribute Details

#numberObject

The global sequence number of this example



7
8
9
# File 'lib/spec/dsl/example.rb', line 7

def number
  @number
end

Instance Method Details

#descriptionObject



40
41
42
# File 'lib/spec/dsl/example.rb', line 40

def description
  @description == :__generate_description ? generated_description : @description
end

#matches?(matcher, specified_examples) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/spec/dsl/example.rb', line 35

def matches?(matcher, specified_examples)
  matcher.example_desc = description
  matcher.matches?(specified_examples)
end

#run(reporter, before_each_block, after_each_block, dry_run, execution_context, timeout = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spec/dsl/example.rb', line 17

def run(reporter, before_each_block, after_each_block, dry_run, execution_context, timeout=nil)
  @dry_run = dry_run
  reporter.example_started(self)
  return reporter.example_finished(self) if dry_run

  errors = []
  location = nil
  Timeout.timeout(timeout) do
    before_each_ok = before_example(execution_context, errors, &before_each_block)
    example_ok = run_example(execution_context, errors) if before_each_ok
    after_each_ok = after_example(execution_context, errors, &after_each_block)
    location = failure_location(before_each_ok, example_ok, after_each_ok)
  end

  ExampleShouldRaiseHandler.new(@from, @options).handle(errors)
  reporter.example_finished(self, errors.first, location, @example_block.nil?) if reporter
end

#to_sObject



44
45
46
# File 'lib/spec/dsl/example.rb', line 44

def to_s
  description
end