Module: Vigia::Hooks

Included in:
Sail::RSpecObject
Defined in:
lib/vigia/hooks.rb

Instance Method Summary collapse

Instance Method Details

#execute_hook(filter_name, rspec_context) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/vigia/hooks.rb', line 4

def execute_hook(filter_name, rspec_context)
  hooks_for_object(filter_name).each do |hook|
    if self.is_a?(Vigia::Sail::Context)
      instance = self
      rspec_context.define_singleton_method(:vigia_context, -> { instance })
    end

    rspec_context.instance_exec(&hook)
  end
end

#hooks_for_object(filter_name) ⇒ Object



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

def hooks_for_object(filter_name)
  config_hooks(filter_name) + object_hooks(filter_name)
end

#with_hooks(rspec_context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vigia/hooks.rb', line 19

def with_hooks(rspec_context)
  instance = self

  rspec_context.before(:context) do
    instance.execute_hook(:before, self)
  end

  rspec_context.after(:context) do
    instance.execute_hook(:after, self)
  end

  instance.execute_hook(:extend, rspec_context)

  yield
end