gurke 3.3.4 → 3.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gurke/version.rb CHANGED
@@ -4,9 +4,9 @@ module Gurke
4
4
  module VERSION
5
5
  MAJOR = 3
6
6
  MINOR = 3
7
- PATCH = 4
7
+ PATCH = 5
8
8
  STAGE = nil
9
- STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
9
+ STRING = [MAJOR, MINOR, PATCH, STAGE].compact.join('.').freeze
10
10
 
11
11
  def self.to_s
12
12
  STRING
data/lib/gurke.rb CHANGED
@@ -61,9 +61,9 @@ module Gurke
61
61
 
62
62
  # @api private
63
63
  def world
64
- @world ||= const_set('World', Module.new)
64
+ @world ||= const_set(:World, Module.new)
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
- ::Module.send :include, Gurke::DSL
69
+ Module.include Gurke::DSL
@@ -3,49 +3,46 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Gurke::FeatureList do
6
- let(:reporter) { Gurke::Reporters::NullReporter.new }
7
- let(:runner) { double 'runner' }
8
- let(:feature) { double 'feature' }
6
+ let(:reporter) { instance_double Gurke::Reporters::NullReporter }
7
+ let(:runner) { instance_double Gurke::Runner }
8
+ let(:feature) { instance_double Gurke::Feature }
9
+ let(:features) { described_class.new }
9
10
 
10
11
  before do
11
12
  features << feature
12
13
 
13
- allow(runner).to receive(:hook) {|_, _, &block| block.call }
14
- allow(feature).to receive(:failed?).and_return false
15
- allow(feature).to receive(:pending?).and_return false
14
+ allow(feature).to receive_messages(failed?: false, pending?: false)
16
15
  allow(feature).to receive(:run)
16
+ allow(reporter).to receive(:invoke)
17
+ allow(runner).to receive(:hook) {|_, _, &block| block.call }
17
18
  end
18
19
 
19
- let(:features) { Gurke::FeatureList.new }
20
-
21
20
  describe '#run' do
22
- subject { features.run runner, reporter }
21
+ before { features.run runner, reporter }
23
22
 
24
- it 'should run all features' do
25
- expect(feature).to receive(:run).with(runner, reporter)
26
-
27
- subject
23
+ it 'runs all features' do
24
+ expect(feature).to have_received(:run).with(runner, reporter)
28
25
  end
29
26
 
30
- it 'should run hooks' do
31
- expect(runner).to receive(:hook) do |scope, world|
27
+ it 'runs hooks' do
28
+ expect(runner).to have_received(:hook) do |scope, world|
32
29
  expect(scope).to eq :features
33
- expect(world).to eq nil
30
+ expect(world).to be_nil
34
31
  end
35
-
36
- subject
37
32
  end
38
33
 
39
- it 'should run reporter callbacks in correct order' do
40
- expect(reporter).to receive(:invoke).exactly(4).times do |*args|
41
- @scopes ||= []
42
- @scopes << args.first
34
+ it 'runs reporter callbacks in correct order' do
35
+ scopes = []
36
+ expect(reporter).to have_received(:invoke).exactly(4).times do |*args|
37
+ scopes << args.first
43
38
  end
44
39
 
45
- subject
46
-
47
- expect(@scopes).to eq %i[before_features start_features
48
- end_features after_features]
40
+ expect(scopes).to eq %i[
41
+ before_features
42
+ start_features
43
+ end_features
44
+ after_features
45
+ ]
49
46
  end
50
47
  end
51
48
  end
@@ -1,52 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable MissingCopEnableDirective
4
- # rubocop:disable Style/Semicolon
3
+ # rubocop:disable Lint/MissingCopEnableDirective
5
4
 
6
5
  require 'spec_helper'
7
6
 
8
7
  RSpec.describe Gurke::Reporters::CompactReporter do
9
- let(:output) { StringIO.new }
10
- let(:reporter) { described_class.new(output) }
11
- subject { output.string }
8
+ subject(:out) do
9
+ reporter = described_class.new(StringIO.new)
10
+ reporter.send(*action)
11
+ reporter.io.string
12
+ end
12
13
 
13
- describe '#before_feature' do
14
- let(:feature) { double('feature') }
14
+ let(:feature) { instance_double(Gurke::Feature) }
15
+ let(:scenario) { instance_double(Gurke::Scenario) }
16
+ let(:step) { instance_double(Gurke::Step) }
15
17
 
16
- subject { reporter.before_feature(feature); super() }
18
+ describe '#before_feature' do
19
+ let(:action) { [:before_feature, feature] }
17
20
 
18
21
  it { is_expected.to eq '' }
19
22
  end
20
23
 
21
24
  describe '#start_background' do
22
- let(:feature) { double('feature') }
23
-
24
- subject { reporter.start_background(feature); super() }
25
+ let(:action) { [:start_background, feature] }
25
26
 
26
27
  it { is_expected.to eq '' }
27
28
  end
28
29
 
29
30
  describe '#before_scenario' do
30
- let(:scenario) { double('scenario') }
31
-
32
- subject { reporter.before_scenario(scenario); super() }
31
+ let(:action) { [:before_scenario, scenario] }
33
32
 
34
33
  it { is_expected.to eq '' }
35
34
  end
36
35
 
37
36
  describe '#before_step' do
38
- let(:step) { double('step') }
39
-
40
- subject { reporter.before_step(step); super() }
37
+ let(:action) { [:before_step, step] }
41
38
 
42
39
  it { is_expected.to eq '' }
43
40
  end
44
41
 
45
42
  describe '#after_step' do
46
- let(:feature) { double('feature') }
47
- let(:scenario) { double('scenario') }
48
- let(:step) { double('step') }
49
- let(:result) { double('result') }
43
+ let(:action) { [:after_step, result, scenario] }
44
+
45
+ let(:result) { instance_double(Gurke::Step::StepResult) }
50
46
  let(:backgrounds) { [] }
51
47
  let(:exception) { nil }
52
48
 
@@ -55,40 +51,43 @@ RSpec.describe Gurke::Reporters::CompactReporter do
55
51
  end
56
52
 
57
53
  before do
58
- allow(result).to receive(:step).and_return(step)
59
- allow(result).to receive(:scenario).and_return(scenario)
60
- allow(result).to receive(:state).and_return(state)
61
- allow(result).to receive(:exception).and_return(exception)
54
+ allow(result).to receive_messages(
55
+ step: step,
56
+ scenario: scenario,
57
+ state: state,
58
+ exception: exception,
59
+ )
62
60
  end
63
61
 
64
62
  before do
65
- allow(step).to receive(:name).and_return 'the scenario is passing'
66
- allow(step).to receive(:keyword).and_return 'Given'
63
+ allow(step).to receive_messages(
64
+ name: 'the scenario is passing',
65
+ keyword: 'Given',
66
+ )
67
67
  end
68
68
 
69
69
  before do
70
- allow(scenario).to receive(:feature).and_return(feature)
71
- allow(scenario).to receive(:steps).and_return(steps)
72
-
73
- allow(scenario).to receive(:name).and_return 'Running the scenario'
74
- allow(scenario).to receive(:file).and_return \
75
- File.join(Dir.getwd, 'features', 'file.feature')
76
- allow(scenario).to receive(:line).and_return 5
70
+ allow(scenario).to receive_messages(
71
+ feature: feature,
72
+ steps: steps,
73
+ name: 'Running the scenario',
74
+ file: File.join(Dir.getwd, 'features', 'file.feature'),
75
+ line: 5,
76
+ )
77
77
  end
78
78
 
79
79
  before do
80
- allow(feature).to receive(:backgrounds).and_return(backgrounds)
81
-
82
- allow(feature).to receive(:name).and_return 'Demo feature'
83
- allow(feature).to receive(:file).and_return \
84
- File.join(Dir.getwd, 'features', 'file.feature')
85
- allow(feature).to receive(:line).and_return 1
86
- allow(feature).to receive(:description).and_return \
87
- "As a developer\nI would like have this spec passed\nIn order to work on"
80
+ allow(feature).to receive_messages(
81
+ backgrounds: backgrounds,
82
+ name: 'Demo feature',
83
+ file: File.join(Dir.getwd, 'features', 'file.feature'),
84
+ line: 1,
85
+ description: "As a developer\n" \
86
+ "I would like have this spec passed\n" \
87
+ 'In order to work on',
88
+ )
88
89
  end
89
90
 
90
- subject { reporter.after_step(result, scenario); super() }
91
-
92
91
  context 'with step passing' do
93
92
  let(:state) { :passed }
94
93
 
@@ -101,7 +100,7 @@ RSpec.describe Gurke::Reporters::CompactReporter do
101
100
  it { is_expected.to eq '' }
102
101
  end
103
102
 
104
- context 'with step pending' do
103
+ context 'with step nil' do
105
104
  let(:state) { nil }
106
105
 
107
106
  it { is_expected.to eq '' }
@@ -111,30 +110,24 @@ RSpec.describe Gurke::Reporters::CompactReporter do
111
110
  let(:state) { :failed }
112
111
 
113
112
  before do
114
- e = double 'exception'
115
- c = double 'exception'
116
-
117
- allow(e).to receive(:class).and_return(RuntimeError)
118
- allow(e).to receive(:message).and_return('An error occurred')
119
- allow(e).to receive(:backtrace).and_return([
120
- '/path/to/file.rb:5:in `block (4 levels) in <top (required)>\'',
121
- '/path/to/file.rb:24:in in `fail_with\''
122
- ])
123
-
124
- allow(e).to receive(:cause).and_return(c)
125
-
126
- allow(c).to receive(:class).and_return(IOError)
127
- allow(c).to receive(:message).and_return('Socket closed')
128
- allow(c).to receive(:backtrace).and_return([
129
- 'script.rb:5:in `a\'',
130
- 'script.rb:10:in `b\''
131
- ])
132
-
133
- expect(result).to receive(:exception).and_return e
113
+ error = instance_double RuntimeError
114
+ cause = instance_double IOError
115
+
116
+ allow(error).to receive_messages(class: RuntimeError, message: 'An error occurred', backtrace: [
117
+ '/path/to/file.rb:5:in `block (4 levels) in <top (required)>\'',
118
+ '/path/to/file.rb:24:in in `fail_with\'',
119
+ ], cause: cause,)
120
+
121
+ allow(cause).to receive_messages(class: IOError, message: 'Socket closed', backtrace: [
122
+ 'script.rb:5:in `a\'',
123
+ 'script.rb:10:in `b\'',
124
+ ],)
125
+
126
+ allow(result).to receive(:exception).and_return error
134
127
  end
135
128
 
136
129
  it do
137
- is_expected.to eq unindent <<~TEXT
130
+ expect(out).to eq unindent <<~TEXT
138
131
  .E
139
132
  .Feature: Demo feature # features/file.feature:1
140
133
  . Scenario: Running the scenario # features/file.feature:5
@@ -153,22 +146,16 @@ RSpec.describe Gurke::Reporters::CompactReporter do
153
146
  end
154
147
 
155
148
  describe '#retry_scenario' do
156
- let(:scenario) { double('scenario') }
157
-
158
- subject { reporter.retry_scenario(scenario); super() }
149
+ let(:action) { [:retry_scenario, scenario] }
159
150
 
160
151
  it { is_expected.to eq '' }
161
152
  end
162
153
 
163
154
  describe '#after_scenario' do
164
- let(:scenario) { double('scenario') }
165
-
166
- subject { reporter.after_scenario(scenario); super() }
155
+ let(:action) { [:after_scenario, scenario] }
167
156
 
168
157
  before do
169
- allow(scenario).to receive(:failed?).and_return(false)
170
- allow(scenario).to receive(:passed?).and_return(true)
171
- allow(scenario).to receive(:pending?).and_return(false)
158
+ allow(scenario).to receive_messages(failed?: false, passed?: true, pending?: false)
172
159
  end
173
160
 
174
161
  it { is_expected.to eq '.' }
@@ -191,20 +178,16 @@ RSpec.describe Gurke::Reporters::CompactReporter do
191
178
  end
192
179
 
193
180
  describe '#after_feature' do
194
- let(:feature) { double('feature') }
195
-
196
- subject { reporter.after_feature(feature); super() }
181
+ let(:action) { [:after_feature, feature] }
197
182
 
198
183
  it { is_expected.to eq '' }
199
184
  end
200
185
 
201
186
  describe '#after_features' do
202
- let(:features) { [] }
203
-
204
- subject { reporter.after_features(features); super() }
187
+ let(:action) { [:after_features, []] }
205
188
 
206
189
  it do
207
- is_expected.to eq unindent <<~TEXT
190
+ expect(out).to eq unindent <<~TEXT
208
191
  .
209
192
  .
210
193
  .0 scenarios: 0 passed, 0 failing, 0 pending
@@ -1,31 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable MissingCopEnableDirective
4
- # rubocop:disable Style/Semicolon
3
+ # rubocop:disable Lint/MissingCopEnableDirective
5
4
 
6
5
  require 'spec_helper'
7
6
 
8
7
  RSpec.describe Gurke::Reporters::DefaultReporter do
9
- let(:output) { StringIO.new }
10
- let(:reporter) { described_class.new(output) }
11
- subject { output.string }
8
+ subject(:out) do
9
+ reporter = described_class.new(StringIO.new)
10
+ reporter.send(*action)
11
+ reporter.io.string
12
+ end
13
+
14
+ let(:feature) { instance_double(Gurke::Feature) }
15
+ let(:scenario) { instance_double(Gurke::Scenario) }
16
+ let(:step) { instance_double(Gurke::Step) }
12
17
 
13
18
  describe '#before_feature' do
14
- let(:feature) { double('feature') }
19
+ let(:action) { [:before_feature, feature] }
15
20
 
16
21
  before do
17
- expect(feature).to receive(:name).and_return 'Demo feature'
18
- expect(feature).to receive(:file).and_return \
19
- File.join(Dir.getwd, 'features', 'file.feature')
20
- expect(feature).to receive(:line).and_return 1
21
- expect(feature).to receive(:description).and_return \
22
- "As a developer\nI would like have this spec passed\nIn order to work on"
22
+ allow(feature).to receive_messages(name: 'Demo feature', file: File.join(Dir.getwd, 'features', 'file.feature'),
23
+ line: 1, description: <<~DESC.strip,)
24
+ As a developer
25
+ I would like have this spec passed
26
+ In order to work on
27
+ DESC
23
28
  end
24
29
 
25
- subject { reporter.before_feature(feature); super() }
26
-
27
30
  it do
28
- is_expected.to eq unindent <<~TEXT
31
+ expect(out).to eq unindent <<~TEXT
29
32
  Feature: Demo feature # features/file.feature:1
30
33
  As a developer
31
34
  I would like have this spec passed
@@ -37,12 +40,10 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
37
40
  end
38
41
 
39
42
  describe '#start_background' do
40
- let(:feature) { double('feature') }
41
-
42
- subject { reporter.start_background(feature); super() }
43
+ let(:action) { [:start_background, feature] }
43
44
 
44
45
  it do
45
- is_expected.to eq unindent <<~TEXT
46
+ expect(out).to eq unindent <<~TEXT
46
47
  . Background:
47
48
  .
48
49
  TEXT
@@ -50,19 +51,15 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
50
51
  end
51
52
 
52
53
  describe '#before_scenario' do
53
- let(:scenario) { double('scenario') }
54
+ let(:action) { [:before_scenario, scenario] }
54
55
 
55
56
  before do
56
- expect(scenario).to receive(:name).and_return 'Running the scenario'
57
- expect(scenario).to receive(:file).and_return \
58
- File.join(Dir.getwd, 'features', 'file.feature')
59
- expect(scenario).to receive(:line).and_return 5
57
+ allow(scenario).to receive_messages(name: 'Running the scenario',
58
+ file: File.join(Dir.getwd, 'features', 'file.feature'), line: 5,)
60
59
  end
61
60
 
62
- subject { reporter.before_scenario(scenario); super() }
63
-
64
61
  it do
65
- is_expected.to eq unindent <<~TEXT
62
+ expect(out).to eq unindent <<~TEXT
66
63
  . Scenario: Running the scenario # features/file.feature:5
67
64
  .
68
65
  TEXT
@@ -70,36 +67,32 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
70
67
  end
71
68
 
72
69
  describe '#before_step' do
73
- let(:step) { double('step') }
70
+ let(:action) { [:before_step, step] }
74
71
 
75
72
  before do
76
- expect(step).to receive(:name).and_return 'the scenario is passing'
77
- expect(step).to receive(:keyword).and_return 'Given'
73
+ allow(step).to receive_messages(name: 'the scenario is passing', keyword: 'Given')
78
74
  end
79
75
 
80
- subject { reporter.before_step(step); super() }
81
-
82
76
  it do
83
- is_expected.to eq unindent <<~TEXT
77
+ expect(out).to eq unindent <<~TEXT
84
78
  . Given the scenario is passing
85
79
  TEXT
86
80
  end
87
81
  end
88
82
 
89
83
  describe '#after_step' do
90
- let(:step) { double('step') }
84
+ let(:action) { [:after_step, result, scenario] }
85
+ let(:result) { instance_double(Gurke::Step::StepResult) }
91
86
 
92
87
  before do
93
- expect(step).to receive(:state).and_return state
88
+ allow(result).to receive(:state).and_return state
94
89
  end
95
90
 
96
- subject { reporter.after_step(step); super() }
97
-
98
91
  context 'with step passing' do
99
92
  let(:state) { :passed }
100
93
 
101
94
  it do
102
- is_expected.to eq unindent <<~TEXT
95
+ expect(out).to eq unindent <<~TEXT
103
96
  . (passed)
104
97
  .
105
98
  TEXT
@@ -110,18 +103,18 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
110
103
  let(:state) { :pending }
111
104
 
112
105
  it do
113
- is_expected.to eq unindent <<~TEXT
106
+ expect(out).to eq unindent <<~TEXT
114
107
  . (pending)
115
108
  .
116
109
  TEXT
117
110
  end
118
111
  end
119
112
 
120
- context 'with step pending' do
113
+ context 'with step nil' do
121
114
  let(:state) { nil }
122
115
 
123
116
  it do
124
- is_expected.to eq unindent <<~TEXT
117
+ expect(out).to eq unindent <<~TEXT
125
118
  . (skipped)
126
119
  .
127
120
  TEXT
@@ -132,30 +125,24 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
132
125
  let(:state) { :failed }
133
126
 
134
127
  before do
135
- e = double 'exception'
136
- c = double 'exception'
137
-
138
- allow(e).to receive(:class).and_return(RuntimeError)
139
- allow(e).to receive(:message).and_return('An error occurred')
140
- allow(e).to receive(:backtrace).and_return([
141
- '/path/to/file.rb:5:in `block (4 levels) in <top (required)>\'',
142
- '/path/to/file.rb:24:in in `fail_with\''
143
- ])
144
-
145
- allow(e).to receive(:cause).and_return(c)
146
-
147
- allow(c).to receive(:class).and_return(IOError)
148
- allow(c).to receive(:message).and_return('Socket closed')
149
- allow(c).to receive(:backtrace).and_return([
150
- 'script.rb:5:in `a\'',
151
- 'script.rb:10:in `b\''
152
- ])
153
-
154
- expect(step).to receive(:exception).and_return e
128
+ error = instance_double RuntimeError
129
+ cause = instance_double IOError
130
+
131
+ allow(error).to receive_messages(class: RuntimeError, message: 'An error occurred', backtrace: [
132
+ '/path/to/file.rb:5:in `block (4 levels) in <top (required)>\'',
133
+ '/path/to/file.rb:24:in in `fail_with\'',
134
+ ], cause: cause,)
135
+
136
+ allow(cause).to receive_messages(class: IOError, message: 'Socket closed', backtrace: [
137
+ 'script.rb:5:in `a\'',
138
+ 'script.rb:10:in `b\'',
139
+ ],)
140
+
141
+ allow(result).to receive(:exception).and_return error
155
142
  end
156
143
 
157
144
  it do
158
- is_expected.to eq unindent <<~TEXT
145
+ expect(out).to eq unindent <<~TEXT
159
146
  . (failure)
160
147
  . RuntimeError: An error occurred
161
148
  . /path/to/file.rb:5:in `block (4 levels) in <top (required)>'
@@ -171,9 +158,7 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
171
158
  end
172
159
 
173
160
  describe '#retry_scenario' do
174
- let(:scenario) { double('scenario') }
175
-
176
- subject { reporter.retry_scenario(scenario); super() }
161
+ let(:action) { [:retry_scenario, scenario] }
177
162
 
178
163
  context 'with normal scenario' do
179
164
  before do
@@ -181,7 +166,7 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
181
166
  end
182
167
 
183
168
  it do
184
- is_expected.to eq unindent <<~TEXT
169
+ expect(out).to eq unindent <<~TEXT
185
170
  .
186
171
  . Retry scenario due to previous failure:
187
172
  .
@@ -196,7 +181,7 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
196
181
  end
197
182
 
198
183
  it do
199
- is_expected.to eq unindent <<~TEXT
184
+ expect(out).to eq unindent <<~TEXT
200
185
  .
201
186
  . Retry flaky scenario due to previous failure:
202
187
  .
@@ -207,12 +192,10 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
207
192
  end
208
193
 
209
194
  describe '#after_scenario' do
210
- let(:scenario) { double('scenario') }
211
-
212
- subject { reporter.after_scenario(scenario); super() }
195
+ let(:action) { [:after_scenario, scenario] }
213
196
 
214
197
  it do
215
- is_expected.to eq unindent <<~TEXT
198
+ expect(out).to eq unindent <<~TEXT
216
199
  .
217
200
  .
218
201
  TEXT
@@ -220,12 +203,10 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
220
203
  end
221
204
 
222
205
  describe '#after_feature' do
223
- let(:feature) { double('feature') }
224
-
225
- subject { reporter.after_feature(feature); super() }
206
+ let(:action) { [:after_feature, feature] }
226
207
 
227
208
  it do
228
- is_expected.to eq unindent <<~TEXT
209
+ expect(out).to eq unindent <<~TEXT
229
210
  .
230
211
  .
231
212
  TEXT
@@ -233,12 +214,10 @@ RSpec.describe Gurke::Reporters::DefaultReporter do
233
214
  end
234
215
 
235
216
  describe '#after_features' do
236
- let(:features) { [] }
237
-
238
- subject { reporter.after_features(features); super() }
217
+ let(:action) { [:after_features, []] }
239
218
 
240
219
  it do
241
- is_expected.to eq unindent <<~TEXT
220
+ expect(out).to eq unindent <<~TEXT
242
221
  .0 scenarios: 0 failing, 0 pending
243
222
  .
244
223
  .