Class: RSpec::Steps::Hook

Inherits:
Struct
  • Object
show all
Defined in:
lib/rspec-steps/hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



4
5
6
# File 'lib/rspec-steps/hook.rb', line 4

def action
  @action
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



4
5
6
# File 'lib/rspec-steps/hook.rb', line 4

def kind
  @kind
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/rspec-steps/hook.rb', line 4

def type
  @type
end

Instance Method Details

#define_on(example_group) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec-steps/hook.rb', line 23

def define_on(example_group)
  case type
  when :before
    example_group.before rspec_kind, &action
  when :after
    example_group.after rspec_kind, &action
  when :around
    example_group.around rspec_kind, &action
  end
end

#rspec_kindObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rspec-steps/hook.rb', line 5

def rspec_kind
  case kind
  when :each
    warn_about_promotion(type)
    :all
  when :step
    :each
  else
    kind
  end
end

#warn_about_promotion(scope_name) ⇒ Object



17
18
19
20
21
# File 'lib/rspec-steps/hook.rb', line 17

def warn_about_promotion(scope_name)
  RSpec::Steps.warnings[
    "#{scope_name} :each blocks declared for steps are always treated as " +
    ":all scope (it's possible you want #{scope_name} :step)"]
end