Class: RSpec::Core::Hooks::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/hooks.rb

Direct Known Subclasses

AfterHook, AroundHook, BeforeHook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ Hook

Returns a new instance of Hook.



9
10
11
12
13
# File 'lib/rspec/core/hooks.rb', line 9

def initialize(options, &block)
  @options = options
  raise "no block given for #{display_name}" unless block
  @block = block
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/rspec/core/hooks.rb', line 7

def options
  @options
end

Instance Method Details

#callObject



23
24
25
# File 'lib/rspec/core/hooks.rb', line 23

def call
  @block.call
end

#display_nameObject



27
28
29
# File 'lib/rspec/core/hooks.rb', line 27

def display_name
  self.class.name.split('::').last.gsub('Hook','').downcase << " hook"
end

#options_apply?(example_or_group) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rspec/core/hooks.rb', line 15

def options_apply?(example_or_group)
  example_or_group.all_apply?(options)
end

#to_procObject



19
20
21
# File 'lib/rspec/core/hooks.rb', line 19

def to_proc
  @block
end