Class: Cucumber::Glue::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/glue/hook.rb

Overview

TODO: Kill pointless wrapper for Before, After and AfterStep hooks with fire

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, registry, tag_expressions, proc, name: nil) ⇒ Hook

Returns a new instance of Hook.



11
12
13
14
15
16
17
18
19
# File 'lib/cucumber/glue/hook.rb', line 11

def initialize(id, registry, tag_expressions, proc, name: nil)
  @id = id
  @registry = registry
  @name = name
  @tag_expressions = sanitize_tag_expressions(tag_expressions)
  @proc = proc
  @location = Cucumber::Core::Test::Location.from_source_location(*@proc.source_location)
  fail_for_old_style_tag_expressions(@tag_expressions)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/cucumber/glue/hook.rb', line 9

def id
  @id
end

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/cucumber/glue/hook.rb', line 9

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/cucumber/glue/hook.rb', line 9

def name
  @name
end

#tag_expressionsObject (readonly)

Returns the value of attribute tag_expressions.



9
10
11
# File 'lib/cucumber/glue/hook.rb', line 9

def tag_expressions
  @tag_expressions
end

Instance Method Details

#invoke(pseudo_method, arguments, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/cucumber/glue/hook.rb', line 21

def invoke(pseudo_method, arguments, &block)
  check_arity = false
  InvokeInWorld.cucumber_instance_exec_in(
    @registry.current_world,
    check_arity,
    pseudo_method,
    *[arguments, block].flatten.compact,
    &@proc
  )
end

#to_envelopeObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber/glue/hook.rb', line 32

def to_envelope
  Cucumber::Messages::Envelope.new(
    hook: Cucumber::Messages::Hook.new(
      id: id,
      name: name,
      tag_expression: tag_expressions.empty? ? nil : tag_expressions.join(' '),
      source_reference: Cucumber::Messages::SourceReference.new(
        uri: location.file,
        location: Cucumber::Messages::Location.new(
          line: location.lines.first
        )
      )
    )
  )
end