-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
73 lines (63 loc) · 2.13 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# This is to implement the rspec's test flow structure that is used to define the tests
# This is implemented using Nested Layouts concept
# This is responsible for the logging of description, test steps and the numbering are happening here
# Before all, before each, after all, after each steps are also declared here
# This file can be taken as a backbone for the tests that are going to be scripted in this framework
require_relative "../libraries/logger.rb"
require_relative "../libraries/driver.rb"
require_relative "../libraries/config.rb"
require_relative "../libraries/assert.rb"
include Libraries
$VERBOSE = nil
$file = 0
$test = 0
$step = 0
# Before all block which can be declared for each test file
def before_all(&block)
yield if block_given?
end
# After all block which can be declared for each test file
def after_all(&block)
$after_all = lambda { yield }
end
# This will be executed before each `it` described in the tests
def before_each_test(&block)
$before_each_test = lambda { yield }
end
# This will be executed after each `it` described in the tests
def after_each_test(&block)
$after_each_test = lambda { yield }
end
# This will be executed before each `step` described in the tests
def before_each_step(&block)
$before_each_step = lambda { yield }
end
# This will be executed after each `step` described in the tests
def after_each_step(&block)
$after_each_step = lambda { yield }
end
# This is to log the description and reset the counter for the tests and steps
def describe(description)
$file = $file + 1
$test = 0
$step = 0
Log.file($file.to_s + ". " + description)
yield
$after_all.call if $after_all
end
# This is to log the steps declared in the tests
def step(description)
$step = $step + 1
$before_each_step.call if $before_each_step
Log.step($step.to_s + ". " + description)
yield
$after_each_step.call if $after_each_step
end
# This is to log the `it` declared in the tests
def it(description)
$test = $test + 1
$before_each_test.call if $before_each_test
Log.test($test.to_s + ". " + description)
yield
$after_each_test.call if $after_each_test
end