Class: Easytest::Hook

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, block:) ⇒ Hook

Returns a new instance of Hook.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/easytest/hook.rb', line 7

def initialize(type:, block:)
  raise ArgumentError, "" unless [:before, :after].include?(type)

  @file = (caller_locations(3, 1)&.first&.absolute_path or raise)
  @type = type
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/easytest/hook.rb', line 5

def block
  @block
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/easytest/hook.rb', line 3

def file
  @file
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/easytest/hook.rb', line 4

def type
  @type
end

Instance Method Details

#after?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/easytest/hook.rb', line 23

def after?
  type == :after
end

#before?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/easytest/hook.rb', line 19

def before?
  type == :before
end

#run(test_case) ⇒ Object



15
16
17
# File 'lib/easytest/hook.rb', line 15

def run(test_case)
  block.call(test_case)
end