File: case_spec.rb

package info (click to toggle)
ruby-cucumber-core 1.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: ruby: 5,763; makefile: 2
file content (238 lines) | stat: -rw-r--r-- 8,482 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
require 'cucumber/core'
require 'cucumber/core/gherkin/writer'
require 'cucumber/core/platform'
require 'cucumber/core/test/case'
require 'debian/unindent'

module Cucumber
  module Core
    module Test
      describe Case do
        include Core
        include Core::Gherkin::Writer

        let(:test_case) { Test::Case.new(test_steps, [feature, scenario]) }
        let(:feature) { double }
        let(:scenario) { double }
        let(:test_steps) { [double, double] }

        context 'describing itself' do
          it "describes itself to a visitor" do
            visitor = double
            args = double
            expect( visitor ).to receive(:test_case).with(test_case, args)
            test_case.describe_to(visitor, args)
          end

          it "asks each test_step to describe themselves to the visitor" do
            visitor = double
            args = double
            test_steps.each do |test_step|
              expect( test_step ).to receive(:describe_to).with(visitor, args)
            end
            allow( visitor ).to receive(:test_case).and_yield(visitor)
            test_case.describe_to(visitor, args)
          end

          it "describes around hooks in order" do
            visitor = double
            allow( visitor ).to receive(:test_case).and_yield(visitor)
            first_hook, second_hook = double, double
            expect( first_hook ).to receive(:describe_to).ordered.and_yield
            expect( second_hook ).to receive(:describe_to).ordered.and_yield
            around_hooks = [first_hook, second_hook]
            Test::Case.new([], [], around_hooks).describe_to(visitor, double)
          end

          it "describes its source to a visitor" do
            visitor = double
            args = double
            expect( feature ).to receive(:describe_to).with(visitor, args)
            expect( scenario ).to receive(:describe_to).with(visitor, args)
            test_case.describe_source_to(visitor, args)
          end

        end

        describe "#name" do
          context "created from a scenario" do
            it "takes its name from the name of a scenario" do
              gherkin = gherkin do
                feature do
                  scenario 'Scenario name' do
                    step 'passing'
                  end
                end
              end
              receiver = double.as_null_object

              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.name ).to eq 'Scenario name'
                expect( test_case.keyword ).to eq 'Scenario'
              end
              compile([gherkin], receiver)
            end
          end

          context "created from a scenario outline example" do
            it "takes its name from the name of the scenario outline and examples table" do
              gherkin = gherkin do
                feature do
                  scenario_outline 'outline name' do
                    step 'passing with arg'

                    examples 'examples name' do
                      row 'arg'
                      row 'a'
                      row 'b'
                    end

                    examples '' do
                      row 'arg'
                      row 'c'
                    end
                  end
                end
              end
              receiver = double.as_null_object
              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.name ).to eq 'outline name, examples name (#1)'
                expect( test_case.keyword ).to eq 'Scenario Outline'
              end.once.ordered
              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.name ).to eq 'outline name, examples name (#2)'
              end.once.ordered
              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.name ).to eq 'outline name, Examples (#1)'
              end.once.ordered
              compile [gherkin], receiver
            end
          end
        end

        describe "#location" do
          context "created from a scenario" do
            it "takes its location from the location of the scenario" do
              gherkin = gherkin('features/foo.feature') do
                feature do
                  scenario do
                    step
                  end
                end
              end
              receiver = double.as_null_object
              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.location.to_s ).to eq 'features/foo.feature:3'
              end
              compile([gherkin], receiver)
            end
          end

          context "created from a scenario outline example" do
            it "takes its location from the location of the scenario outline example row" do
              gherkin = gherkin('features/foo.feature') do
                feature do
                  scenario_outline do
                    step 'passing with arg'

                    examples do
                      row 'arg'
                      row '1'
                      row '2'
                    end
                  end
                end
              end
              receiver = double.as_null_object
              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.location.to_s ).to eq 'features/foo.feature:8'
              end.once.ordered
              expect( receiver ).to receive(:test_case) do |test_case|
                expect( test_case.location.to_s ).to eq 'features/foo.feature:9'
              end.once.ordered
              compile [gherkin], receiver
            end
          end
        end

        describe "#tags" do
          it "includes all tags from the parent feature" do
            gherkin = gherkin do
              feature tags: ['@a', '@b'] do
                scenario tags: ['@c'] do
                  step
                end
                scenario_outline tags: ['@d'] do
                  step 'passing with arg'
                  examples tags: ['@e'] do
                    row 'arg'
                    row 'x'
                  end
                end
              end
            end
            receiver = double.as_null_object
            expect( receiver ).to receive(:test_case) do |test_case|
              expect( test_case.tags.map(&:name) ).to eq ['@a', '@b', '@c']
            end.once.ordered
            expect( receiver ).to receive(:test_case) do |test_case|
              expect( test_case.tags.map(&:name) ).to eq ['@a', '@b', '@d', '@e']
            end.once.ordered
            compile [gherkin], receiver
          end
        end

        describe "matching tags" do
          it "matches boolean expressions of tags" do
            gherkin = gherkin do
              feature tags: ['@a', '@b'] do
                scenario tags: ['@c'] do
                  step
                end
              end
            end
            receiver = double.as_null_object
            expect( receiver ).to receive(:test_case) do |test_case|
              expect( test_case.match_tags?('@a') ).to be_truthy
            end
            compile [gherkin], receiver
          end
        end

        describe "matching names" do
          it "matches names against regexp" do
            gherkin = gherkin do
              feature 'first feature' do
                scenario 'scenario' do
                  step 'missing'
                end
              end
            end
            receiver = double.as_null_object
            expect( receiver ).to receive(:test_case) do |test_case|
              expect( test_case.match_name?(/feature/) ).to be_truthy
            end
            compile [gherkin], receiver
          end
        end

        describe "#language" do
          it 'takes its language from the feature' do
            gherkin = Gherkin::Document.new('features/treasure.feature', %{# language: en-pirate
              Ahoy matey!: Treasure map
                Heave to: Find the treasure
                  Gangway!: a map
            })
            receiver = double.as_null_object
            expect( receiver ).to receive(:test_case) do |test_case|
              expect( test_case.language.iso_code ).to eq 'en-pirate'
            end
            compile([gherkin], receiver)
          end
        end

      end
    end
  end
end