File: scenarios_spec.rb

package info (click to toggle)
ruby-parallel-tests 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,280 kB
  • sloc: ruby: 5,381; javascript: 30; makefile: 4
file content (280 lines) | stat: -rw-r--r-- 9,018 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# frozen_string_literal: true
require 'tempfile'
require 'parallel_tests/cucumber/scenarios'

describe ParallelTests::Cucumber::Scenarios do
  let(:feature_file) do
    Tempfile.new('grouper.feature').tap do |feature|
      feature.write <<-EOS
        Feature: Grouping by scenario

          Scenario: First
            Given I do nothing

          Scenario: Second
            Given I don't do anything

          Scenario Outline: Third
            Given I don't do anything
          Examples:
            | param   |
            | value 1 |
            | value 2 |
      EOS
      feature.rewind
    end
  end

  context 'by default' do
    it 'returns all the scenarios' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path])
      expect(scenarios).to eq [
        "#{feature_file.path}:3",
        "#{feature_file.path}:6",
        "#{feature_file.path}:13",
        "#{feature_file.path}:14"
      ]
    end
  end

  context 'with line numbers' do
    it 'only returns scenarios that match the provided lines' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(["#{feature_file.path}:6:14"])
      expect(scenarios).to eq ["#{feature_file.path}:6", "#{feature_file.path}:14"]
    end
  end

  context 'with tags' do
    let(:feature_file) do
      Tempfile.new('grouper.feature').tap do |feature|
        feature.write <<-EOS
          @colours
          Feature: Grouping by scenario

            @black
            Scenario: Black
              Given I am black

            @white
            Scenario: White
              Given I am blue

            @black @white
            Scenario: Gray
              Given I am Gray

            @red
            Scenario Outline: Red
              Give I am <colour>
              @blue
              Examples:
                | colour  |
                | magenta |
                | fuchsia |

              @green
              Examples:
                | colour |
                | yellow |

              @blue @green
              Examples:
               | colour |
               | white  |
        EOS
        feature.rewind
      end
    end

    it 'Single Feature Tag: colours' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@colours"])
      expect(scenarios.length).to eq 7
    end

    it 'Single Scenario Tag: white' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@white"])
      expect(scenarios.length).to eq 2
    end

    it 'Multiple Scenario Tags 1: black && white' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@black and @white"])
      expect(scenarios.length).to eq 1
    end

    it 'Multiple Scenario Tags 2: black || white scenarios' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@black or @white"])
      expect(scenarios.length).to eq 3
    end

    it 'Scenario Outline Tag: red' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@red"])
      expect(scenarios.length).to eq 4
    end

    it 'Example Tag: blue' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@blue"])
      expect(scenarios.length).to eq 3
    end

    it 'Multiple Example Tags 1: blue && green' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@blue and @green"])
      expect(scenarios.length).to eq 1
    end

    it 'Multiple Example Tags 2: blue || green' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@blue or @green"])
      expect(scenarios.length).to eq 4
    end

    it 'Single Negative Feature Tag: !colours' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "not @colours"])
      expect(scenarios.length).to eq 0
    end

    it 'Single Negative Scenario Tag: !black' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "not @black"])
      expect(scenarios.length).to eq 5
    end

    it 'Multiple Negative Scenario Tags And: !(black && white)' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["-t", "not (@black and @white)"]
      )
      expect(scenarios.length).to eq 6
    end

    it 'Multiple Negative Scenario Tags Or: !(black || red)' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["-t", "not (@black or @red)"]
      )
      expect(scenarios.length).to eq 1
    end

    it 'Negative Scenario Outline Tag: !red' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "not @red"])
      expect(scenarios.length).to eq 3
    end

    it 'Negative Example Tag: !blue' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "not @blue"])
      expect(scenarios.length).to eq 4
    end

    it 'Multiple Negative Example Tags 1: !blue && !green' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["-t", "not @blue and not @green"]
      )
      expect(scenarios.length).to eq 3
    end

    it 'Multiple Negative Example Tags 2: !blue || !green) ' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["-t", "not @blue or not @green"]
      )
      expect(scenarios.length).to eq 6
    end

    it 'Scenario and Example Mixed Tags: black || green' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], test_options: ["-t", "@black or @green"])
      expect(scenarios.length).to eq 4
    end

    it 'Positive and Negative Mixed Tags: red && !blue' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["-t", "@red and not @blue"]
      )
      expect(scenarios.length).to eq 1
    end

    it 'Multiple Positive and Negative Mixed Tags: (white && black) || (red && !blue)' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["--tags", "(not @white and @black) or (@red and not @green)"]
      )
      expect(scenarios.length).to eq 3
    end

    it 'Ignore Tag Pattern Feature: colours' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], ignore_tag_pattern: "@colours")
      expect(scenarios.length).to eq 0
    end

    it 'Ignore Tag Pattern Scenario: black' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], ignore_tag_pattern: "@black")
      expect(scenarios.length).to eq 5
    end

    it 'Ignore Tag Pattern Scenario Outline: red' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], ignore_tag_pattern: "@red")
      expect(scenarios.length).to eq 3
    end

    it 'Ignore Tag Pattern Example: green' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], ignore_tag_pattern: "@green")
      expect(scenarios.length).to eq 5
    end

    it 'Ignore Tag Pattern Multiple Tags: black || red' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path], ignore_tag_pattern: "@black or @red")
      expect(scenarios.length).to eq 1
    end

    it 'Scenario Mixed tags: black && !blue with Ignore Tag Pattern Multiple Tags: red || white' do
      scenarios = ParallelTests::Cucumber::Scenarios.all(
        [feature_file.path],
        test_options: ["-t", "@black and not @blue"], ignore_tag_pattern: "@red or @white"
      )
      expect(scenarios.length).to eq 1
    end
  end

  context 'with Rules' do # cuke_modeler >=3.2
    let(:feature_file) do
      Tempfile.new('grouper.feature').tap do |feature|
        feature.write <<-EOS
        Feature: Grouping by scenario

          Scenario: First
            Given I do nothing

          Scenario Outline: Second
            Given I don't do anything
          Examples:
            | param   |
            | value 1 |
            | value 2 |

          Rule:
            Scenario: Third
             Given I don't do anything

          Rule:
            Scenario Outline: Fourth
              Given I don't do anything
            Examples:
              | param   |
              | value 1 |
              | value 2 |
        EOS
        feature.rewind
      end
    end

    it 'returns all the scenarios' do
      scenarios = ParallelTests::Cucumber::Scenarios.all([feature_file.path])
      expect(scenarios).to match_array [
        "#{feature_file.path}:3",
        "#{feature_file.path}:10",
        "#{feature_file.path}:11",
        "#{feature_file.path}:14",
        "#{feature_file.path}:22",
        "#{feature_file.path}:23"
      ]
    end
  end
end