Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 6559158

Browse files
committed
Fix diff-lcs scenarios
1 parent 24e5b7b commit 6559158

File tree

2 files changed

+268
-1
lines changed

2 files changed

+268
-1
lines changed

features/expectation_framework_integration/aggregating_failures.feature

Lines changed: 251 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Feature: Aggregating Failures
1919
end
2020
"""
2121

22+
@skip-when-diff-lcs-1.3
2223
Scenario: Use `aggregate_failures` block form
2324
Given a file named "spec/use_block_form_spec.rb" with:
2425
"""ruby
@@ -70,7 +71,82 @@ Feature: Aggregating Failures
7071
1.1.2) Failure/Error: expect(response.headers).to include("Content-Type" => "application/json")
7172
expected {"Content-Type" => "text/plain"} to include {"Content-Type" => "application/json"}
7273
Diff:
73-
@@ -1,2 +1,2 @@
74+
@@ -1 +1 @@
75+
-"Content-Type" => "application/json",
76+
+"Content-Type" => "text/plain",
77+
# ./spec/use_block_form_spec.rb:20
78+
79+
1.1.3) Failure/Error: expect(response.body).to eq('{"message":"Success"}')
80+
81+
expected: "{\"message\":\"Success\"}"
82+
got: "Not Found"
83+
84+
(compared using ==)
85+
# ./spec/use_block_form_spec.rb:21
86+
87+
1.2) Failure/Error: expect(false).to be(true), "after hook failure"
88+
after hook failure
89+
# ./spec/use_block_form_spec.rb:6
90+
# ./spec/use_block_form_spec.rb:10
91+
92+
1.3) Failure/Error: expect(false).to be(true), "around hook failure"
93+
around hook failure
94+
# ./spec/use_block_form_spec.rb:12
95+
"""
96+
97+
@skip-when-diff-lcs-1.4
98+
Scenario: Use `aggregate_failures` block form
99+
Given a file named "spec/use_block_form_spec.rb" with:
100+
"""ruby
101+
require 'client'
102+
103+
RSpec.describe Client do
104+
after do
105+
# this should be appended to failure list
106+
expect(false).to be(true), "after hook failure"
107+
end
108+
109+
around do |ex|
110+
ex.run
111+
# this should also be appended to failure list
112+
expect(false).to be(true), "around hook failure"
113+
end
114+
115+
it "returns a successful response" do
116+
response = Client.make_request
117+
118+
aggregate_failures "testing response" do
119+
expect(response.status).to eq(200)
120+
expect(response.headers).to include("Content-Type" => "application/json")
121+
expect(response.body).to eq('{"message":"Success"}')
122+
end
123+
end
124+
end
125+
"""
126+
When I run `rspec spec/use_block_form_spec.rb`
127+
Then it should fail and list all the failures:
128+
"""
129+
Failures:
130+
131+
1) Client returns a successful response
132+
Got 3 failures:
133+
134+
1.1) Got 3 failures from failure aggregation block "testing response".
135+
# ./spec/use_block_form_spec.rb:18
136+
# ./spec/use_block_form_spec.rb:10
137+
138+
1.1.1) Failure/Error: expect(response.status).to eq(200)
139+
140+
expected: 200
141+
got: 404
142+
143+
(compared using ==)
144+
# ./spec/use_block_form_spec.rb:19
145+
146+
1.1.2) Failure/Error: expect(response.headers).to include("Content-Type" => "application/json")
147+
expected {"Content-Type" => "text/plain"} to include {"Content-Type" => "application/json"}
148+
Diff:
149+
@@ -1 +1 @@
74150
-"Content-Type" => "application/json",
75151
+"Content-Type" => "text/plain",
76152
# ./spec/use_block_form_spec.rb:20
@@ -143,6 +219,62 @@ Feature: Aggregating Failures
143219
# ./spec/use_metadata_spec.rb:10
144220
"""
145221

222+
@skip-when-diff-lcs-1.3
223+
Scenario: Enable failure aggregation globally using `define_derived_metadata`
224+
Given a file named "spec/enable_globally_spec.rb" with:
225+
"""ruby
226+
require 'client'
227+
228+
RSpec.configure do |c|
229+
c.define_derived_metadata do |meta|
230+
meta[:aggregate_failures] = true
231+
end
232+
end
233+
234+
RSpec.describe Client do
235+
it "returns a successful response" do
236+
response = Client.make_request
237+
238+
expect(response.status).to eq(200)
239+
expect(response.headers).to include("Content-Type" => "application/json")
240+
expect(response.body).to eq('{"message":"Success"}')
241+
end
242+
end
243+
"""
244+
When I run `rspec spec/enable_globally_spec.rb`
245+
Then it should fail and list all the failures:
246+
"""
247+
Failures:
248+
249+
1) Client returns a successful response
250+
Got 3 failures:
251+
252+
1.1) Failure/Error: expect(response.status).to eq(200)
253+
254+
expected: 200
255+
got: 404
256+
257+
(compared using ==)
258+
# ./spec/enable_globally_spec.rb:13
259+
260+
1.2) Failure/Error: expect(response.headers).to include("Content-Type" => "application/json")
261+
expected {"Content-Type" => "text/plain"} to include {"Content-Type" => "application/json"}
262+
Diff:
263+
@@ -1 +1 @@
264+
-"Content-Type" => "application/json",
265+
+"Content-Type" => "text/plain",
266+
# ./spec/enable_globally_spec.rb:14
267+
268+
1.3) Failure/Error: expect(response.body).to eq('{"message":"Success"}')
269+
270+
expected: "{\"message\":\"Success\"}"
271+
got: "Not Found"
272+
273+
(compared using ==)
274+
# ./spec/enable_globally_spec.rb:15
275+
"""
276+
277+
@skip-when-diff-lcs-1.4
146278
Scenario: Enable failure aggregation globally using `define_derived_metadata`
147279
Given a file named "spec/enable_globally_spec.rb" with:
148280
"""ruby
@@ -197,6 +329,72 @@ Feature: Aggregating Failures
197329
# ./spec/enable_globally_spec.rb:15
198330
"""
199331

332+
@skip-when-diff-lcs-1.3
333+
Scenario: Nested failure aggregation works
334+
Given a file named "spec/nested_failure_aggregation_spec.rb" with:
335+
"""ruby
336+
require 'client'
337+
338+
RSpec.describe Client do
339+
it "returns a successful response", :aggregate_failures do
340+
response = Client.make_request
341+
342+
expect(response.status).to eq(200)
343+
344+
aggregate_failures "testing headers" do
345+
expect(response.headers).to include("Content-Type" => "application/json")
346+
expect(response.headers).to include("Content-Length" => "21")
347+
end
348+
349+
expect(response.body).to eq('{"message":"Success"}')
350+
end
351+
end
352+
"""
353+
When I run `rspec spec/nested_failure_aggregation_spec.rb`
354+
Then it should fail and list all the failures:
355+
"""
356+
Failures:
357+
358+
1) Client returns a successful response
359+
Got 3 failures:
360+
361+
1.1) Failure/Error: expect(response.status).to eq(200)
362+
363+
expected: 200
364+
got: 404
365+
366+
(compared using ==)
367+
# ./spec/nested_failure_aggregation_spec.rb:7
368+
369+
1.2) Got 2 failures from failure aggregation block "testing headers".
370+
# ./spec/nested_failure_aggregation_spec.rb:9
371+
372+
1.2.1) Failure/Error: expect(response.headers).to include("Content-Type" => "application/json")
373+
expected {"Content-Type" => "text/plain"} to include {"Content-Type" => "application/json"}
374+
Diff:
375+
@@ -1 +1 @@
376+
-"Content-Type" => "application/json",
377+
+"Content-Type" => "text/plain",
378+
# ./spec/nested_failure_aggregation_spec.rb:10
379+
380+
1.2.2) Failure/Error: expect(response.headers).to include("Content-Length" => "21")
381+
expected {"Content-Type" => "text/plain"} to include {"Content-Length" => "21"}
382+
Diff:
383+
@@ -1 +1 @@
384+
-"Content-Length" => "21",
385+
+"Content-Type" => "text/plain",
386+
# ./spec/nested_failure_aggregation_spec.rb:11
387+
388+
1.3) Failure/Error: expect(response.body).to eq('{"message":"Success"}')
389+
390+
expected: "{\"message\":\"Success\"}"
391+
got: "Not Found"
392+
393+
(compared using ==)
394+
# ./spec/nested_failure_aggregation_spec.rb:14
395+
"""
396+
397+
@skip-when-diff-lcs-1.4
200398
Scenario: Nested failure aggregation works
201399
Given a file named "spec/nested_failure_aggregation_spec.rb" with:
202400
"""ruby
@@ -301,6 +499,58 @@ Feature: Aggregating Failures
301499
302500
"""
303501

502+
@skip-when-diff-lcs-1.3
503+
Scenario: Pending integrates properly with aggregated failures
504+
Given a file named "spec/pending_spec.rb" with:
505+
"""ruby
506+
require 'client'
507+
508+
RSpec.describe Client do
509+
it "returns a successful response", :aggregate_failures do
510+
pending "Not yet ready"
511+
response = Client.make_request
512+
513+
expect(response.status).to eq(200)
514+
expect(response.headers).to include("Content-Type" => "application/json")
515+
expect(response.body).to eq('{"message":"Success"}')
516+
end
517+
end
518+
"""
519+
When I run `rspec spec/pending_spec.rb`
520+
Then it should pass and list all the pending examples:
521+
"""
522+
Pending: (Failures listed here are expected and do not affect your suite's status)
523+
524+
1) Client returns a successful response
525+
# Not yet ready
526+
Got 3 failures:
527+
528+
1.1) Failure/Error: expect(response.status).to eq(200)
529+
530+
expected: 200
531+
got: 404
532+
533+
(compared using ==)
534+
# ./spec/pending_spec.rb:8
535+
536+
1.2) Failure/Error: expect(response.headers).to include("Content-Type" => "application/json")
537+
expected {"Content-Type" => "text/plain"} to include {"Content-Type" => "application/json"}
538+
Diff:
539+
@@ -1 +1 @@
540+
-"Content-Type" => "application/json",
541+
+"Content-Type" => "text/plain",
542+
# ./spec/pending_spec.rb:9
543+
544+
1.3) Failure/Error: expect(response.body).to eq('{"message":"Success"}')
545+
546+
expected: "{\"message\":\"Success\"}"
547+
got: "Not Found"
548+
549+
(compared using ==)
550+
# ./spec/pending_spec.rb:10
551+
"""
552+
553+
@skip-when-diff-lcs-1.4
304554
Scenario: Pending integrates properly with aggregated failures
305555
Given a file named "spec/pending_spec.rb" with:
306556
"""ruby

features/support/diff_lcs_versions.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'diff-lcs'
2+
3+
Around "@skip-when-diff-lcs-1.4" do |scenario, block|
4+
if Diff::LCS::VERSION.to_f >= 1.4
5+
warn "Skipping scenario #{scenario.title} on `diff-lcs` v#{Diff::LCS::VERSION.to_f}"
6+
else
7+
block.call
8+
end
9+
end
10+
11+
Around "@skip-when-diff-lcs-1.3" do |scenario, block|
12+
if Diff::LCS::VERSION.to_f < 1.4
13+
warn "Skipping scenario #{scenario.title} on `diff-lcs` v#{Diff::LCS::VERSION.to_f}"
14+
else
15+
block.call
16+
end
17+
end

0 commit comments

Comments
 (0)