/
feature.rb
75 lines (66 loc) · 1.86 KB
/
feature.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
74
75
module Spinach
class Runner
# A feature runner handles a particular Spinach::Feature run.
#
class Feature
# @param [String] filename
# path to the feature file. Scenario line could be passed to run just
# that scenario.
# @example feature/a_cool_feature.feature:12
#
# @param [Spinach::Reporter] reporter
# the reporter that will log this run
#
def initialize(filename, reporter)
@filename, @scenario_line = filename.split(':')
@reporter = reporter
end
attr_reader :reporter
attr_reader :filename
# @return [Spinach::Feature]
# the feature towards which this scenario will be run
#
def feature
@feature ||= Spinach.find_feature(feature_name).new
end
# @return [Hash]
# the parsed data for this feature
#
def data
@data ||= Spinach::Parser.new(filename).parse
end
# @return [String]
# this feature's name
#
def feature_name
@feature_name ||= data['name']
end
# @return [Hash]
# the parsed scenarios for this runner's feature
#
def scenarios
@scenarios ||= (data['elements'] || [])
end
# Runs this feature
#
def run
reporter.feature(feature_name)
failures = []
feature.run_hook :before, feature_name
scenarios.each do |scenario|
if !@scenario_line || scenario['line'].to_s == @scenario_line
failure = Scenario.new(feature_name, feature, scenario, reporter).run
failures << failure if failure
end
end
feature.run_hook :after, feature_name
unless failures.length.zero?
reporter.error_summary(failures)
return false
else
return true
end
end
end
end
end