Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCK: Reconcile attachments #69

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions devkit/samples/attachments/attachments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,26 @@ Feature: Attachments

When the string "hello" is attached as "application/octet-stream"

Scenario: Log text
When the string "hello" is logged

Scenario: Log ANSI coloured text
When text with ANSI escapes is logged

Scenario: Log JSON
When the following string is attached as "application/json":
```
{"message": "The <b>big</b> question", "foo": "bar"}
```

Scenario: Log text
When the string "hello" is logged

Scenario: Log ANSI coloured text
When text with ANSI escapes is logged

Scenario: Byte arrays are base64-encoded regardless of media type
When an array with 10 bytes is attached as "text/plain"

Scenario: Streams are always base64-encoded
luke-hill marked this conversation as resolved.
Show resolved Hide resolved
Scenario: Attaching JPEG images
When a JPEG image is attached

Scenario: Attaching images in examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have we removed this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've just simplified the code. Examples tables are covered in a diff feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are but I don't think that one includes attachments?

When the <image> png is attached

Examples:
| image |
| cucumber.png |
Scenario: Attaching PNG images
When a PNG image is attached

Scenario: Attaching a document with a different filename
Scenario: Attaching PDFs with a different filename
When a PDF document is attached and renamed
21 changes: 2 additions & 19 deletions devkit/samples/attachments/attachments.feature.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Before, When } from '@cucumber/fake-cucumber'
import { ReadableStreamBuffer } from 'stream-buffers'
import fs from 'fs'

// Cucumber-JVM needs to use a Before hook in order to create attachments
luke-hill marked this conversation as resolved.
Show resolved Hide resolved
Before(() => undefined)

When('the string {string} is attached as {string}', function (text: string, mediaType: string) {
this.attach(text, mediaType)
})
Expand Down Expand Up @@ -32,25 +28,12 @@ When(
}
)

When(
'a stream with {int} bytes are attached as {string}',
async function (size: number, mediaType: string) {
const data = [...Array(size).keys()]
const buffer = Buffer.from(data)
const stream = new ReadableStreamBuffer({ chunkSize: 1, frequency: 1 })
stream.put(buffer)
stream.stop()

await this.attach(stream, mediaType)
}
)

When('a JPEG image is attached', async function () {
await this.attach(fs.createReadStream(__dirname + '/cucumber.jpeg'), 'image/jpeg')
})

When('the {word} png is attached', async function (filename) {
await this.attach(fs.createReadStream(__dirname + `/${filename}`), 'image/png')
When('a PNG image is attached', async function () {
await this.attach(fs.createReadStream(__dirname + '/cucumber.png'), 'image/png')
})

When('a PDF document is attached and renamed', async function () {
Expand Down
16 changes: 2 additions & 14 deletions ruby/features/attachments/attachments.feature.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# frozen_string_literal: true

require 'stringio'

# Cucumber-JVM needs to use a Before hook in order to create attachments
Before { nil }

When('the string {string} is attached as {string}') do |text, media_type|
attach(text, media_type)
end
Expand All @@ -26,19 +21,12 @@
attach(data, media_type)
end

When('a stream with {int} bytes are attached as {string}') do |size, media_type|
stream = StringIO.new
stream.puts (0..size).map(&:to_s).join('')
stream.seek(0)
attach(stream, media_type)
end

When('a JPEG image is attached') do
attach(File.open("#{__dir__}/cucumber.jpeg"), 'image/jpeg')
end

When('the {word} png is attached') do |filename|
attach(File.open("#{__dir__}/#{filename}"), 'image/png')
When('a PNG image is attached') do
attach(File.open("#{__dir__}/cucumber.png"), 'image/png')
end

When('a PDF document is attached and renamed') do
Expand Down