Class: Easytest::Hook
- Inherits:
-
Object
- Object
- Easytest::Hook
- Defined in:
- lib/easytest/hook.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #after? ⇒ Boolean
- #before? ⇒ Boolean
-
#initialize(type:, block:) ⇒ Hook
constructor
A new instance of Hook.
- #run(test_case) ⇒ Object
Constructor Details
#initialize(type:, block:) ⇒ Hook
Returns a new instance of Hook.
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/easytest/hook.rb', line 5 def block @block end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/easytest/hook.rb', line 3 def file @file end |
#type ⇒ Object (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
23 24 25 |
# File 'lib/easytest/hook.rb', line 23 def after? type == :after end |
#before? ⇒ 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 |