cukedep 0.1.11 → 0.2.00
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/.ruby-version +1 -1
- data/.travis.yml +10 -10
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +30 -30
- data/bin/cukedep +15 -15
- data/lib/cukedep/application.rb +105 -112
- data/lib/cukedep/cli/cmd-line.rb +11 -13
- data/lib/cukedep/config.rb +85 -89
- data/lib/cukedep/constants.rb +5 -5
- data/lib/cukedep/cuke-runner.rb +191 -198
- data/lib/cukedep/customization.rb +30 -30
- data/lib/cukedep/feature-model.rb +43 -46
- data/lib/cukedep/feature-rep.rb +9 -11
- data/lib/cukedep/file-action.rb +11 -18
- data/lib/cukedep/gherkin-facade.rb +11 -6
- data/lib/cukedep/gherkin-listener.rb +12 -42
- data/lib/cukedep/hook-dsl.rb +78 -78
- data/lib/cukedep/sandbox.rb +15 -16
- data/lib/cukedep.rb +1 -2
- data/sample/features/step_definitions/steps.rb +2 -2
- data/sample/model/model.rb +19 -20
- data/spec/cukedep/application_spec.rb +80 -80
- data/spec/cukedep/cli/cmd-line_spec.rb +88 -88
- data/spec/cukedep/cuke-runner_spec.rb +74 -74
- data/spec/cukedep/customization_spec.rb +31 -31
- data/spec/cukedep/debug-file-action.rb +29 -29
- data/spec/cukedep/feature-model_spec.rb +100 -100
- data/spec/cukedep/feature-rep_spec.rb +2 -1
- data/spec/cukedep/file-action_spec.rb +365 -366
- data/spec/cukedep/file-parsing.rb +39 -41
- data/spec/cukedep/gherkin-facade_spec.rb +48 -49
- data/spec/cukedep/gherkin-listener_spec.rb +55 -57
- data/spec/cukedep/hook-dsl_spec.rb +182 -182
- data/spec/cukedep/sample_features/cukedep_hooks.rb +30 -30
- data/spec/cukedep/sample_features/standalone.feature +1 -1
- data/templates/rake.erb +12 -21
- metadata +80 -58
- data/sample/result.html +0 -472
- data/spec/cukedep/sample_features/cukedep.rake +0 -215
- data/spec/cukedep/sample_features/dependencies.dot +0 -38
- data/spec/cukedep/sample_features/feature2id.csv +0 -7
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
# File: file-parsing.rb
|
|
2
|
-
|
|
3
|
-
require_relative '../../lib/cukedep/gherkin-facade'
|
|
4
|
-
|
|
5
|
-
module Cukedep # This module is used as a namespace
|
|
6
|
-
# Mixin module used in tests.
|
|
7
|
-
# Purpose: to parse a sample of feature files.
|
|
8
|
-
module FileParsing
|
|
9
|
-
# The list of sample feature file names.
|
|
10
|
-
SampleFileNames =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# Helper method. It parses sample feature files and
|
|
20
|
-
# notifies the provided listener of its progress.
|
|
21
|
-
def parse_for(aListener)
|
|
22
|
-
orig_dir = Dir.getwd
|
|
23
|
-
begin
|
|
24
|
-
# Determine the folder where the sample files reside
|
|
25
|
-
my_dir = File.dirname(__FILE__)
|
|
26
|
-
sample_dir = File.expand_path(my_dir + '/sample_features')
|
|
27
|
-
Dir.chdir(sample_dir)
|
|
28
|
-
|
|
29
|
-
# Parse the specified feature files in work directory
|
|
30
|
-
is_verbose = false
|
|
31
|
-
gherkin_facade = GherkinFacade.new(is_verbose, 'UTF-8')
|
|
32
|
-
gherkin_facade.parse_features(aListener, SampleFileNames)
|
|
33
|
-
ensure
|
|
34
|
-
Dir.chdir(orig_dir)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
end # module
|
|
41
|
-
# End of file
|
|
1
|
+
# File: file-parsing.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../../lib/cukedep/gherkin-facade'
|
|
4
|
+
|
|
5
|
+
module Cukedep # This module is used as a namespace
|
|
6
|
+
# Mixin module used in tests.
|
|
7
|
+
# Purpose: to parse a sample of feature files.
|
|
8
|
+
module FileParsing
|
|
9
|
+
# The list of sample feature file names.
|
|
10
|
+
SampleFileNames = [
|
|
11
|
+
'a_few_tests.feature',
|
|
12
|
+
'some_tests.feature',
|
|
13
|
+
'still_other_tests.feature',
|
|
14
|
+
'yet_other_tests.feature',
|
|
15
|
+
'more_tests.feature',
|
|
16
|
+
'standalone.feature'
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
# Helper method. It parses sample feature files and
|
|
20
|
+
# notifies the provided listener of its progress.
|
|
21
|
+
def parse_for(aListener)
|
|
22
|
+
orig_dir = Dir.getwd
|
|
23
|
+
begin
|
|
24
|
+
# Determine the folder where the sample files reside
|
|
25
|
+
my_dir = File.dirname(__FILE__)
|
|
26
|
+
sample_dir = File.expand_path(my_dir + '/sample_features')
|
|
27
|
+
Dir.chdir(sample_dir)
|
|
28
|
+
|
|
29
|
+
# Parse the specified feature files in work directory
|
|
30
|
+
is_verbose = false
|
|
31
|
+
gherkin_facade = GherkinFacade.new(is_verbose, 'UTF-8')
|
|
32
|
+
gherkin_facade.parse_features(aListener, SampleFileNames)
|
|
33
|
+
ensure
|
|
34
|
+
Dir.chdir(orig_dir)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end # module
|
|
38
|
+
end # module
|
|
39
|
+
# End of file
|
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
# File: file-actions_spec.rb
|
|
2
|
-
|
|
3
|
-
require_relative '../spec_helper'
|
|
4
|
-
|
|
5
|
-
# Load the class under testing
|
|
6
|
-
require_relative '../../lib/cukedep/gherkin-facade'
|
|
7
|
-
require_relative '../../lib/cukedep/gherkin-listener'
|
|
8
|
-
|
|
9
|
-
module Cukedep # Open module to get rid of long qualified names
|
|
10
|
-
describe GherkinFacade do
|
|
11
|
-
subject { GherkinFacade.new(false, 'UTF-8') }
|
|
12
|
-
|
|
13
|
-
context 'Creation & initialization:' do
|
|
14
|
-
it 'should be created with two arguments' do
|
|
15
|
-
expect { GherkinFacade.new(true, 'UTF-8') }.not_to raise_error
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'should whether it is verbose or not' do
|
|
19
|
-
# Case 1: instance is verbose
|
|
20
|
-
expect(subject.verbose).to be_falsey
|
|
21
|
-
|
|
22
|
-
# Case 2: instance is silent
|
|
23
|
-
instance =
|
|
24
|
-
expect(instance.verbose).to be_truthy
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'should know the feature file external encoding' do
|
|
28
|
-
expect(subject.external_encoding).to eq('UTF-8')
|
|
29
|
-
end
|
|
30
|
-
end # context
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end #
|
|
48
|
-
|
|
49
|
-
# End of file
|
|
1
|
+
# File: file-actions_spec.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
|
|
5
|
+
# Load the class under testing
|
|
6
|
+
require_relative '../../lib/cukedep/gherkin-facade'
|
|
7
|
+
require_relative '../../lib/cukedep/gherkin-listener'
|
|
8
|
+
|
|
9
|
+
module Cukedep # Open module to get rid of long qualified names
|
|
10
|
+
describe GherkinFacade do
|
|
11
|
+
subject { GherkinFacade.new(false, 'UTF-8') }
|
|
12
|
+
|
|
13
|
+
context 'Creation & initialization:' do
|
|
14
|
+
it 'should be created with two arguments' do
|
|
15
|
+
expect { GherkinFacade.new(true, 'UTF-8') }.not_to raise_error
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should whether it is verbose or not' do
|
|
19
|
+
# Case 1: instance is verbose
|
|
20
|
+
expect(subject.verbose).to be_falsey
|
|
21
|
+
|
|
22
|
+
# Case 2: instance is silent
|
|
23
|
+
instance = GherkinFacade.new(true, 'UTF-8')
|
|
24
|
+
expect(instance.verbose).to be_truthy
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should know the feature file external encoding' do
|
|
28
|
+
expect(subject.external_encoding).to eq('UTF-8')
|
|
29
|
+
end
|
|
30
|
+
end # context
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
context 'Provided services:' do
|
|
34
|
+
let(:listener) { GherkinListener.new }
|
|
35
|
+
it 'should parse ASCII feature files' do
|
|
36
|
+
instance = GherkinFacade.new(false, 'US-ASCII')
|
|
37
|
+
patterns = ['sample_features/a_few_tests.feature']
|
|
38
|
+
expect { instance.parse_features(listener, patterns) }.not_to raise_error
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# it 'should parse feature files with other external encoding' do
|
|
42
|
+
# patterns = [ 'sample_features/standalone.feature' ]
|
|
43
|
+
# expect { subject.parse_features(listener, patterns) }.not_to raise_error
|
|
44
|
+
# end
|
|
45
|
+
end # context
|
|
46
|
+
end # describe
|
|
47
|
+
end # module
|
|
48
|
+
# End of file
|
|
@@ -1,57 +1,55 @@
|
|
|
1
|
-
# File: gherkin-listener_spec.rb
|
|
2
|
-
|
|
3
|
-
require_relative '../spec_helper'
|
|
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
|
-
%w(
|
|
39
|
-
%w(
|
|
40
|
-
%w(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# End of file
|
|
1
|
+
# File: gherkin-listener_spec.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
|
+
require_relative 'file-parsing'
|
|
5
|
+
|
|
6
|
+
# Load the class under testing
|
|
7
|
+
require_relative '../../lib/cukedep/gherkin-listener'
|
|
8
|
+
|
|
9
|
+
module Cukedep # Open module to get rid of long qualified names
|
|
10
|
+
describe GherkinListener do
|
|
11
|
+
include FileParsing # Use mixin module to parse of sample feature files
|
|
12
|
+
|
|
13
|
+
subject { GherkinListener.new }
|
|
14
|
+
|
|
15
|
+
context 'Creation and initialization:' do
|
|
16
|
+
it 'should be created without argument' do
|
|
17
|
+
expect { GherkinListener.new }.not_to raise_error
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should have no feature file at start' do
|
|
21
|
+
expect(subject.feature_files.size).to eq(0)
|
|
22
|
+
end
|
|
23
|
+
end # context
|
|
24
|
+
|
|
25
|
+
context 'Provided services:' do
|
|
26
|
+
it 'should build a FeatureFileRep per parsed file' do
|
|
27
|
+
parse_for(subject)
|
|
28
|
+
expect(subject.feature_files.size)
|
|
29
|
+
.to eq(FileParsing::SampleFileNames.size)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should know the tags of each feature' do
|
|
33
|
+
parse_for(subject)
|
|
34
|
+
|
|
35
|
+
expectations = [
|
|
36
|
+
%w(a_few feature:qux),
|
|
37
|
+
%w(some feature:foo depends_on:bar depends_on:qux),
|
|
38
|
+
%w(still_other feature:baz),
|
|
39
|
+
%w(yet_other feature:bar depends_on:baz depends_on:qux depends_on:quux),
|
|
40
|
+
%w(feature:quux more),
|
|
41
|
+
[]
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
# Sort the expectations to ease further comparison
|
|
45
|
+
expectations.map!(&:sort)
|
|
46
|
+
|
|
47
|
+
subject.feature_files.each_with_index do |file, i|
|
|
48
|
+
expect(file.feature.tags.sort).to eq(expectations[i])
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end # context
|
|
52
|
+
end # describe
|
|
53
|
+
end # module
|
|
54
|
+
|
|
55
|
+
# End of file
|
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
# File: file-action_spec.rb
|
|
2
|
-
|
|
3
|
-
require 'stringio'
|
|
4
|
-
require_relative '../spec_helper'
|
|
5
|
-
|
|
6
|
-
# Load the class under testing
|
|
7
|
-
require_relative '../../lib/cukedep/hook-dsl'
|
|
8
|
-
|
|
9
|
-
module Cukedep # Open module to get rid of long qualified names
|
|
10
|
-
# Let's specify the behaviour of the mix-in module
|
|
11
|
-
describe HookDSL do
|
|
12
|
-
subject do
|
|
13
|
-
obj = Object.new
|
|
14
|
-
obj.extend(HookDSL)
|
|
15
|
-
obj
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'Hook definitions:' do
|
|
19
|
-
let(:code_block) do
|
|
20
|
-
-> {
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'should accept the before all hook' do
|
|
24
|
-
# Case 1: before all with block code
|
|
25
|
-
expect { subject.before_cuke(:all, &code_block) }.not_to raise_error
|
|
26
|
-
|
|
27
|
-
# Case 2: before all without block code
|
|
28
|
-
expect { subject.before_cuke(:all) }.not_to raise_error
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'should accept the before each hook' do
|
|
32
|
-
# Case 1: before each with block code
|
|
33
|
-
expect { subject.before_cuke(:each, &code_block) }.not_to raise_error
|
|
34
|
-
|
|
35
|
-
# Case 2: before each without block code
|
|
36
|
-
expect { subject.before_cuke(:each) }.not_to raise_error
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
it 'should accept the after all hook' do
|
|
41
|
-
# Case 1: after all with block code
|
|
42
|
-
expect { subject.after_cuke(:all, &code_block) }.not_to raise_error
|
|
43
|
-
|
|
44
|
-
# Case 2: before all without block code
|
|
45
|
-
expect { subject.after_cuke(:all) }.not_to raise_error
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'should accept the after each hook' do
|
|
49
|
-
# Case 1: after each with block code
|
|
50
|
-
expect { subject.after_cuke(:each, &code_block) }.not_to raise_error
|
|
51
|
-
|
|
52
|
-
# Case 2: after each without block code
|
|
53
|
-
expect { subject.after_cuke(:each) }.not_to raise_error
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'should reject invalid scope argument' do
|
|
57
|
-
# Case 1: before invalid with block code
|
|
58
|
-
msg = "Unknown scope 'invalid' for before_cuke hook."
|
|
59
|
-
error = StandardError
|
|
60
|
-
expect { subject.before_cuke(:invalid, &code_block) }
|
|
61
|
-
.to raise_error(error, msg)
|
|
62
|
-
|
|
63
|
-
# Case 2: after invalid with block code
|
|
64
|
-
msg = "Unknown scope 'invalid' for after_cuke hook."
|
|
65
|
-
expect { subject.after_cuke(:invalid, &code_block) }
|
|
66
|
-
.to raise_error(error, msg)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
it 'should register the block code with the event' do
|
|
71
|
-
# No block code registered yet.
|
|
72
|
-
expect(subject.instance_variables).not_to include(:@before_hooks)
|
|
73
|
-
|
|
74
|
-
# Case 1: No before all handler provided
|
|
75
|
-
subject.before_cuke(:all)
|
|
76
|
-
expect(subject.instance_variables).not_to include(:@before_hooks)
|
|
77
|
-
|
|
78
|
-
# Case 1: Add before all handler
|
|
79
|
-
subject.before_cuke(:all, &code_block)
|
|
80
|
-
|
|
81
|
-
# Check that handler code is stored in instance variable
|
|
82
|
-
expect(subject.instance_variables).to include(:@before_hooks)
|
|
83
|
-
expect(subject.before_hooks.keys).to eq([:all])
|
|
84
|
-
expect(subject.before_hooks[:all]).to eq(code_block)
|
|
85
|
-
|
|
86
|
-
# Case 2: No before each handler provided
|
|
87
|
-
subject.before_cuke(:each)
|
|
88
|
-
expect(subject.before_hooks.keys).to eq([:all])
|
|
89
|
-
|
|
90
|
-
# Case 3: Add before each handler
|
|
91
|
-
subject.before_cuke(:each, &code_block)
|
|
92
|
-
|
|
93
|
-
# Check that handler code is stored in instance variable
|
|
94
|
-
expect(subject.before_hooks.keys).to eq([
|
|
95
|
-
expect(subject.before_hooks[:each]).to eq(code_block)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# Case 4: No after all handler provided
|
|
99
|
-
subject.after_cuke(:all)
|
|
100
|
-
expect(subject.instance_variables).not_to include(:@after_hooks)
|
|
101
|
-
|
|
102
|
-
# Case 5: Add after all handler
|
|
103
|
-
subject.after_cuke(:all, &code_block)
|
|
104
|
-
|
|
105
|
-
# Check that handler code is stored in instance variable
|
|
106
|
-
expect(subject.instance_variables).to include(:@after_hooks)
|
|
107
|
-
expect(subject.after_hooks.keys).to eq([:all])
|
|
108
|
-
expect(subject.after_hooks[:all]).to eq(code_block)
|
|
109
|
-
|
|
110
|
-
# Case 6: No after each handler provided
|
|
111
|
-
subject.after_cuke(:each)
|
|
112
|
-
expect(subject.after_hooks.keys).to eq([:all])
|
|
113
|
-
|
|
114
|
-
# Case 7: Add after each handler
|
|
115
|
-
subject.after_cuke(:each, &code_block)
|
|
116
|
-
|
|
117
|
-
# Check that handler code is stored in instance variable
|
|
118
|
-
expect(subject.after_hooks.keys).to eq([
|
|
119
|
-
expect(subject.after_hooks[:each]).to eq(code_block)
|
|
120
|
-
end
|
|
121
|
-
end # context
|
|
122
|
-
=begin
|
|
123
|
-
context 'Executing handler code:' do
|
|
124
|
-
let(:ostream) { StringIO.new('', 'w') }
|
|
125
|
-
|
|
126
|
-
it 'should ignore missing handler' do
|
|
127
|
-
expect { subject.execute_hook(:before, :all) }.not_to raise_error
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it 'should execute the before all handler' do
|
|
131
|
-
text = 'before all'
|
|
132
|
-
# Let's create the hook
|
|
133
|
-
subject.before_cuke(:all) { ostream.print text }
|
|
134
|
-
|
|
135
|
-
# Let's execute it...
|
|
136
|
-
subject.execute_hook(:before, :all)
|
|
137
|
-
|
|
138
|
-
expect(ostream.string).to eq(text)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
it 'should execute the before all handler' do
|
|
143
|
-
text = 'before each'
|
|
144
|
-
# Let's create the hook
|
|
145
|
-
subject.before_cuke(:each) { ostream.print text }
|
|
146
|
-
|
|
147
|
-
# Let's execute it...
|
|
148
|
-
subject.execute_hook(:before, :each)
|
|
149
|
-
|
|
150
|
-
expect(ostream.string).to eq(text)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
it 'should execute the after all handler' do
|
|
155
|
-
text = 'after all'
|
|
156
|
-
# Let's create the hook
|
|
157
|
-
subject.after_cuke(:all) { ostream.print text }
|
|
158
|
-
|
|
159
|
-
# Let's execute it...
|
|
160
|
-
subject.execute_hook(:after, :all)
|
|
161
|
-
|
|
162
|
-
expect(ostream.string).to eq(text)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
it 'should execute the after each handler' do
|
|
167
|
-
text = 'after each'
|
|
168
|
-
# Let's create the hook
|
|
169
|
-
subject.after_cuke(:each) { ostream.print text }
|
|
170
|
-
|
|
171
|
-
# Let's execute it...
|
|
172
|
-
subject.execute_hook(:after, :each)
|
|
173
|
-
|
|
174
|
-
expect(ostream.string).to eq(text)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
end # context
|
|
178
|
-
=end
|
|
179
|
-
end # describe
|
|
180
|
-
end # module
|
|
181
|
-
|
|
182
|
-
# End of file
|
|
1
|
+
# File: file-action_spec.rb
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
require_relative '../spec_helper'
|
|
5
|
+
|
|
6
|
+
# Load the class under testing
|
|
7
|
+
require_relative '../../lib/cukedep/hook-dsl'
|
|
8
|
+
|
|
9
|
+
module Cukedep # Open module to get rid of long qualified names
|
|
10
|
+
# Let's specify the behaviour of the mix-in module
|
|
11
|
+
describe HookDSL do
|
|
12
|
+
subject do
|
|
13
|
+
obj = Object.new
|
|
14
|
+
obj.extend(HookDSL)
|
|
15
|
+
obj
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'Hook definitions:' do
|
|
19
|
+
let(:code_block) do
|
|
20
|
+
-> {}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should accept the before all hook' do
|
|
24
|
+
# Case 1: before all with block code
|
|
25
|
+
expect { subject.before_cuke(:all, &code_block) }.not_to raise_error
|
|
26
|
+
|
|
27
|
+
# Case 2: before all without block code
|
|
28
|
+
expect { subject.before_cuke(:all) }.not_to raise_error
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should accept the before each hook' do
|
|
32
|
+
# Case 1: before each with block code
|
|
33
|
+
expect { subject.before_cuke(:each, &code_block) }.not_to raise_error
|
|
34
|
+
|
|
35
|
+
# Case 2: before each without block code
|
|
36
|
+
expect { subject.before_cuke(:each) }.not_to raise_error
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
it 'should accept the after all hook' do
|
|
41
|
+
# Case 1: after all with block code
|
|
42
|
+
expect { subject.after_cuke(:all, &code_block) }.not_to raise_error
|
|
43
|
+
|
|
44
|
+
# Case 2: before all without block code
|
|
45
|
+
expect { subject.after_cuke(:all) }.not_to raise_error
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'should accept the after each hook' do
|
|
49
|
+
# Case 1: after each with block code
|
|
50
|
+
expect { subject.after_cuke(:each, &code_block) }.not_to raise_error
|
|
51
|
+
|
|
52
|
+
# Case 2: after each without block code
|
|
53
|
+
expect { subject.after_cuke(:each) }.not_to raise_error
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should reject invalid scope argument' do
|
|
57
|
+
# Case 1: before invalid with block code
|
|
58
|
+
msg = "Unknown scope 'invalid' for before_cuke hook."
|
|
59
|
+
error = StandardError
|
|
60
|
+
expect { subject.before_cuke(:invalid, &code_block) }
|
|
61
|
+
.to raise_error(error, msg)
|
|
62
|
+
|
|
63
|
+
# Case 2: after invalid with block code
|
|
64
|
+
msg = "Unknown scope 'invalid' for after_cuke hook."
|
|
65
|
+
expect { subject.after_cuke(:invalid, &code_block) }
|
|
66
|
+
.to raise_error(error, msg)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
it 'should register the block code with the event' do
|
|
71
|
+
# No block code registered yet.
|
|
72
|
+
expect(subject.instance_variables).not_to include(:@before_hooks)
|
|
73
|
+
|
|
74
|
+
# Case 1: No before all handler provided
|
|
75
|
+
subject.before_cuke(:all)
|
|
76
|
+
expect(subject.instance_variables).not_to include(:@before_hooks)
|
|
77
|
+
|
|
78
|
+
# Case 1: Add before all handler
|
|
79
|
+
subject.before_cuke(:all, &code_block)
|
|
80
|
+
|
|
81
|
+
# Check that handler code is stored in instance variable
|
|
82
|
+
expect(subject.instance_variables).to include(:@before_hooks)
|
|
83
|
+
expect(subject.before_hooks.keys).to eq([:all])
|
|
84
|
+
expect(subject.before_hooks[:all]).to eq(code_block)
|
|
85
|
+
|
|
86
|
+
# Case 2: No before each handler provided
|
|
87
|
+
subject.before_cuke(:each)
|
|
88
|
+
expect(subject.before_hooks.keys).to eq([:all])
|
|
89
|
+
|
|
90
|
+
# Case 3: Add before each handler
|
|
91
|
+
subject.before_cuke(:each, &code_block)
|
|
92
|
+
|
|
93
|
+
# Check that handler code is stored in instance variable
|
|
94
|
+
expect(subject.before_hooks.keys).to eq(%i[all each])
|
|
95
|
+
expect(subject.before_hooks[:each]).to eq(code_block)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# Case 4: No after all handler provided
|
|
99
|
+
subject.after_cuke(:all)
|
|
100
|
+
expect(subject.instance_variables).not_to include(:@after_hooks)
|
|
101
|
+
|
|
102
|
+
# Case 5: Add after all handler
|
|
103
|
+
subject.after_cuke(:all, &code_block)
|
|
104
|
+
|
|
105
|
+
# Check that handler code is stored in instance variable
|
|
106
|
+
expect(subject.instance_variables).to include(:@after_hooks)
|
|
107
|
+
expect(subject.after_hooks.keys).to eq([:all])
|
|
108
|
+
expect(subject.after_hooks[:all]).to eq(code_block)
|
|
109
|
+
|
|
110
|
+
# Case 6: No after each handler provided
|
|
111
|
+
subject.after_cuke(:each)
|
|
112
|
+
expect(subject.after_hooks.keys).to eq([:all])
|
|
113
|
+
|
|
114
|
+
# Case 7: Add after each handler
|
|
115
|
+
subject.after_cuke(:each, &code_block)
|
|
116
|
+
|
|
117
|
+
# Check that handler code is stored in instance variable
|
|
118
|
+
expect(subject.after_hooks.keys).to eq(%i[all each])
|
|
119
|
+
expect(subject.after_hooks[:each]).to eq(code_block)
|
|
120
|
+
end
|
|
121
|
+
end # context
|
|
122
|
+
=begin
|
|
123
|
+
context 'Executing handler code:' do
|
|
124
|
+
let(:ostream) { StringIO.new('', 'w') }
|
|
125
|
+
|
|
126
|
+
it 'should ignore missing handler' do
|
|
127
|
+
expect { subject.execute_hook(:before, :all) }.not_to raise_error
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'should execute the before all handler' do
|
|
131
|
+
text = 'before all'
|
|
132
|
+
# Let's create the hook
|
|
133
|
+
subject.before_cuke(:all) { ostream.print text }
|
|
134
|
+
|
|
135
|
+
# Let's execute it...
|
|
136
|
+
subject.execute_hook(:before, :all)
|
|
137
|
+
|
|
138
|
+
expect(ostream.string).to eq(text)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
it 'should execute the before all handler' do
|
|
143
|
+
text = 'before each'
|
|
144
|
+
# Let's create the hook
|
|
145
|
+
subject.before_cuke(:each) { ostream.print text }
|
|
146
|
+
|
|
147
|
+
# Let's execute it...
|
|
148
|
+
subject.execute_hook(:before, :each)
|
|
149
|
+
|
|
150
|
+
expect(ostream.string).to eq(text)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
it 'should execute the after all handler' do
|
|
155
|
+
text = 'after all'
|
|
156
|
+
# Let's create the hook
|
|
157
|
+
subject.after_cuke(:all) { ostream.print text }
|
|
158
|
+
|
|
159
|
+
# Let's execute it...
|
|
160
|
+
subject.execute_hook(:after, :all)
|
|
161
|
+
|
|
162
|
+
expect(ostream.string).to eq(text)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
it 'should execute the after each handler' do
|
|
167
|
+
text = 'after each'
|
|
168
|
+
# Let's create the hook
|
|
169
|
+
subject.after_cuke(:each) { ostream.print text }
|
|
170
|
+
|
|
171
|
+
# Let's execute it...
|
|
172
|
+
subject.execute_hook(:after, :each)
|
|
173
|
+
|
|
174
|
+
expect(ostream.string).to eq(text)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end # context
|
|
178
|
+
=end
|
|
179
|
+
end # describe
|
|
180
|
+
end # module
|
|
181
|
+
|
|
182
|
+
# End of file
|