lopata 0.1.13 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,136 +1,136 @@
1
- require 'rspec/expectations'
2
-
3
- # Scenario runtime class.
4
- #
5
- # All the scenarios are running in context of separate Lopata::Scenario object.
6
- #
7
- class Lopata::Scenario
8
- include RSpec::Matchers
9
-
10
- # @private
11
- attr_reader :execution
12
-
13
- # @private
14
- def initialize(execution)
15
- @execution = execution
16
- end
17
-
18
- # Marks current step as pending
19
- # @example
20
- # it 'pending step' do
21
- # pending
22
- # expect(1).to eq 2
23
- # end
24
- #
25
- # Pending steps wont be failed
26
- def pending(message = nil)
27
- execution.current_step.pending!(message)
28
- end
29
-
30
- # @return [Hash] metadata available for current step
31
- # @note The metadata keys also availalbe as methods (via method_missing)
32
- def metadata
33
- execution.metadata
34
- end
35
-
36
- private
37
-
38
- # @private
39
- def method_missing(method, *args, &block)
40
- if execution.let_methods.include?(method)
41
- instance_exec(*args, &execution.let_methods[method])
42
- elsif metadata.keys.include?(method)
43
- metadata[method]
44
- else
45
- super
46
- end
47
- end
48
-
49
- # @private
50
- def respond_to_missing?(method, *)
51
- execution.let_methods.include?(method) or metadata.keys.include?(method) or super
52
- end
53
-
54
- # @private
55
- # Scenario execution and live-cycle information
56
- class Execution
57
- attr_reader :scenario, :status, :steps, :title, :current_step
58
-
59
- def initialize(title, options_title, metadata = {})
60
- @title = [title, options_title].compact.reject(&:empty?).join(' ')
61
- @metadata = metadata
62
- @let_methods = {}
63
- @status = :not_runned
64
- @steps = []
65
- @scenario = Lopata::Scenario.new(self)
66
- end
67
-
68
- def run
69
- @status = :running
70
- sort_steps
71
- world.notify_observers(:scenario_started, self)
72
- steps.each(&method(:run_step))
73
- @status = steps.any?(&:failed?) ? :failed : :passed
74
- world.notify_observers(:scenario_finished, self)
75
- cleanup
76
- end
77
-
78
- def run_step(step)
79
- return if step.skipped?
80
- @current_step = step
81
- step.run(scenario)
82
- skip_rest if step.failed? && step.skip_rest_on_failure?
83
- @current_step = nil
84
- end
85
-
86
- def world
87
- Lopata.world
88
- end
89
-
90
- def failed?
91
- status == :failed
92
- end
93
-
94
- def sort_steps
95
- @steps = steps.reject(&:teardown_group?) + steps.select(&:teardown_group?)
96
- end
97
-
98
- def skip_rest
99
- steps.select { |s| s.status == :not_runned && !s.teardown? }.each(&:skip!)
100
- end
101
-
102
- def metadata
103
- if current_step
104
- @metadata.merge(current_step.metadata)
105
- else
106
- @metadata
107
- end
108
- end
109
-
110
- def let_methods
111
- if current_step
112
- @let_methods.merge(current_step.let_methods)
113
- else
114
- @let_methods
115
- end
116
- end
117
-
118
- def let(method_name, &block)
119
- # define_singleton_method method_name, &block
120
- base =
121
- if current_step && !current_step.groups.empty?
122
- current_step.groups.last.let_methods
123
- else
124
- @let_methods
125
- end
126
- base[method_name] = block
127
- end
128
-
129
- def cleanup
130
- @title = nil
131
- @metadata = nil
132
- @steps = nil
133
- @scenario = nil
134
- end
135
- end
136
- end
1
+ require 'rspec/expectations'
2
+
3
+ # Scenario runtime class.
4
+ #
5
+ # All the scenarios are running in context of separate Lopata::Scenario object.
6
+ #
7
+ class Lopata::Scenario
8
+ include RSpec::Matchers
9
+
10
+ # @private
11
+ attr_reader :execution
12
+
13
+ # @private
14
+ def initialize(execution)
15
+ @execution = execution
16
+ end
17
+
18
+ # Marks current step as pending
19
+ # @example
20
+ # it 'pending step' do
21
+ # pending
22
+ # expect(1).to eq 2
23
+ # end
24
+ #
25
+ # Pending steps wont be failed
26
+ def pending(message = nil)
27
+ execution.current_step.pending!(message)
28
+ end
29
+
30
+ # @return [Hash] metadata available for current step
31
+ # @note The metadata keys also availalbe as methods (via method_missing)
32
+ def metadata
33
+ execution.metadata
34
+ end
35
+
36
+ private
37
+
38
+ # @private
39
+ def method_missing(method, *args, &block)
40
+ if execution.let_methods.include?(method)
41
+ instance_exec(*args, &execution.let_methods[method])
42
+ elsif metadata.keys.include?(method)
43
+ metadata[method]
44
+ else
45
+ super
46
+ end
47
+ end
48
+
49
+ # @private
50
+ def respond_to_missing?(method, *)
51
+ execution.let_methods.include?(method) or metadata.keys.include?(method) or super
52
+ end
53
+
54
+ # @private
55
+ # Scenario execution and live-cycle information
56
+ class Execution
57
+ attr_reader :scenario, :status, :steps, :title, :current_step
58
+
59
+ def initialize(title, options_title, metadata = {})
60
+ @title = [title, options_title].compact.reject(&:empty?).join(' ')
61
+ @metadata = metadata
62
+ @let_methods = {}
63
+ @status = :not_runned
64
+ @steps = []
65
+ @scenario = Lopata::Scenario.new(self)
66
+ end
67
+
68
+ def run
69
+ @status = :running
70
+ sort_steps
71
+ world.notify_observers(:scenario_started, self)
72
+ steps.each(&method(:run_step))
73
+ @status = steps.any?(&:failed?) ? :failed : :passed
74
+ world.notify_observers(:scenario_finished, self)
75
+ cleanup
76
+ end
77
+
78
+ def run_step(step)
79
+ return if step.skipped?
80
+ @current_step = step
81
+ step.run(scenario)
82
+ skip_rest if step.failed? && step.skip_rest_on_failure?
83
+ @current_step = nil
84
+ end
85
+
86
+ def world
87
+ Lopata.world
88
+ end
89
+
90
+ def failed?
91
+ status == :failed
92
+ end
93
+
94
+ def sort_steps
95
+ @steps = steps.reject(&:teardown_group?) + steps.select(&:teardown_group?)
96
+ end
97
+
98
+ def skip_rest
99
+ steps.select { |s| s.status == :not_runned && !s.teardown? }.each(&:skip!)
100
+ end
101
+
102
+ def metadata
103
+ if current_step
104
+ @metadata.merge(current_step.metadata)
105
+ else
106
+ @metadata
107
+ end
108
+ end
109
+
110
+ def let_methods
111
+ if current_step
112
+ @let_methods.merge(current_step.let_methods)
113
+ else
114
+ @let_methods
115
+ end
116
+ end
117
+
118
+ def let(method_name, &block)
119
+ # define_singleton_method method_name, &block
120
+ base =
121
+ if current_step && !current_step.groups.empty?
122
+ current_step.groups.last.let_methods
123
+ else
124
+ @let_methods
125
+ end
126
+ base[method_name] = block
127
+ end
128
+
129
+ def cleanup
130
+ @title = nil
131
+ @metadata = nil
132
+ @steps = nil
133
+ @scenario = nil
134
+ end
135
+ end
136
+ end