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

Make cucumber CCK compliant #1738

Merged
merged 38 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1697d48
First interim working update
luke-hill Sep 11, 2023
dc4aaa9
Update of all runtime dependencies
luke-hill Sep 11, 2023
71da693
Remove pry from suite - use a local gemfile
luke-hill Sep 11, 2023
e879733
Update to use latest cck
luke-hill Sep 11, 2023
a9c3259
Remove another personalised gem
luke-hill Sep 11, 2023
e5f7beb
Add fix into message builder that now generates a new exception type …
luke-hill Sep 28, 2023
37d95ed
Enable the structure for making the parameter-type message pass the v…
luke-hill Sep 28, 2023
0e3f116
Add in a new param to last call for #attach which is the filename - L…
luke-hill Sep 29, 2023
ed45483
Add in filename to #attach called from world
luke-hill Sep 29, 2023
564499c
Pass in filename to each method chain
luke-hill Oct 2, 2023
7762e3c
CCK should run locally too
luke-hill Oct 2, 2023
2a39a2f
Permit filename to be passed into legacy JSONFormatter
luke-hill Oct 2, 2023
c6b8969
Add in filename to console formatter puts statement
luke-hill Oct 2, 2023
3ab379b
Add filename to pretty formatter
luke-hill Oct 2, 2023
adf5e4e
When pretty formatter encounters something WITH a filename, show it a…
luke-hill Oct 2, 2023
e5bb4ae
Also revert console formatter to old behaviour when no filename is en…
luke-hill Oct 2, 2023
f474f3b
Fix tests for user interface receiving nil arg
luke-hill Oct 2, 2023
036ffb3
Merge branch 'main' into dependency_bump
luke-hill Oct 3, 2023
7350776
Remove silly default for filename in final consumer before create mes…
luke-hill Oct 3, 2023
f4c6d1f
WIP: Better spike / structure
luke-hill Oct 3, 2023
9bec82d
Bump messages to 17.0 to enable transformer fetching
luke-hill Oct 6, 2023
6968e51
Fix envelope preparation for ParameterType message to be CCK conformant
luke-hill Oct 6, 2023
92584b8
Re-order required rubygems and required ruby versions
luke-hill Oct 6, 2023
0a0a281
Add filename param doc for ProtoWorld
luke-hill Oct 6, 2023
3e61b31
CCK 13 is released
luke-hill Oct 10, 2023
719fbb0
Fix spacing of example feature
luke-hill Oct 11, 2023
fc9f074
Bump CCK to v14
luke-hill Nov 2, 2023
f41dede
Mark pending spec from CCK as currently untested whilst it is investi…
luke-hill Nov 3, 2023
dee314a
Remove redundant rake task code
luke-hill Nov 3, 2023
0d50bda
Ensure cck tests aren't ran mixed in to regular tests
luke-hill Nov 3, 2023
187eb59
Fix failing tests for hook order that were using a previously defined…
luke-hill Nov 3, 2023
35d9f6b
Remove pending guard
luke-hill Nov 10, 2023
265a270
spec_helper fixes
luke-hill Nov 10, 2023
25f4f89
Update changelog
luke-hill Nov 10, 2023
82315a5
Remove final trace of legacy cucumber 1.7 pending flags
luke-hill Nov 10, 2023
b7b19e6
Update changelog with ref to removed guards
luke-hill Nov 10, 2023
bf85ed5
Update RSpec skipped messages to make more sense
luke-hill Nov 10, 2023
19b6649
update changelog
luke-hill Nov 13, 2023
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
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
--tag "~cck"

7 changes: 3 additions & 4 deletions cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ Gem::Specification.new do |s|

s.add_dependency 'builder', '~> 3.2', '>= 3.2.4'
s.add_dependency 'cucumber-ci-environment', '~> 9.2', '>= 9.2.0'
s.add_dependency 'cucumber-core', '~> 11.1', '>= 11.1.0'
s.add_dependency 'cucumber-core', '~> 12.0'
s.add_dependency 'cucumber-cucumber-expressions', '~> 16.1', '>= 16.1.2'
s.add_dependency 'cucumber-gherkin', '>= 24', '< 26.2.1'
s.add_dependency 'cucumber-gherkin', '>= 24', '< 27'
s.add_dependency 'cucumber-html-formatter', '~> 20.4', '>= 20.4.0'
s.add_dependency 'cucumber-messages', '>= 19', '< 23'
s.add_dependency 'diff-lcs', '~> 1.5', '>= 1.5.0'
s.add_dependency 'mini_mime', '~> 1.1', '>= 1.1.5'
s.add_dependency 'multi_test', '~> 1.1', '>= 1.1.0'
s.add_dependency 'sys-uname', '~> 1.2', '>= 1.2.3'

s.add_development_dependency 'cucumber-compatibility-kit', '~> 10.0'
s.add_development_dependency 'cucumber-compatibility-kit', '~> 12.0'
# Only needed whilst we are testing the formatters. Can be removed once we remove tests for those
s.add_development_dependency 'nokogiri', '~> 1.13', '>= 1.13.6'
s.add_development_dependency 'pry', '~> 0.14', '>= 0.14.1'
s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
s.add_development_dependency 'rspec', '~> 3.12', '>= 3.12.0'
s.add_development_dependency 'rubocop', '~> 1.56.4'
Expand Down
9 changes: 7 additions & 2 deletions lib/cucumber/formatter/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,17 @@ def do_print_passing_wip(passed_messages)
end
end

def attach(src, media_type)
def attach(src, media_type, filename)
return unless media_type == 'text/x.cucumber.log+plain'
return unless @io

@io.puts
@io.puts(format_string(src, :tag))
if filename
@io.puts("#{filename}: #{format_string(src, :tag)}")
else
@io.puts(format_string(src, :tag))
end

@io.flush
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def on_test_run_finished(_event)
@io.write(JSON.pretty_generate(@feature_hashes))
end

def attach(src, mime_type)
def attach(src, mime_type, _filename)
if mime_type == 'text/x.cucumber.log+plain'
test_step_output << src
return
Expand Down
19 changes: 14 additions & 5 deletions lib/cucumber/formatter/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def output_message
raise 'To be implemented'
end

def attach(src, media_type)
def attach(src, media_type, filename)
attachment_data = {
test_step_id: @current_test_step_id,
test_case_started_id: @current_test_case_started_id,
media_type: media_type
media_type: media_type,
file_name: filename
}

if media_type.start_with?('text/')
Expand Down Expand Up @@ -192,10 +193,13 @@ def on_test_step_finished(event)

result_message = result.to_message
if result.failed? || result.pending?
message_element = result.failed? ? result.exception : result
luke-hill marked this conversation as resolved.
Show resolved Hide resolved

result_message = Cucumber::Messages::TestStepResult.new(
status: result_message.status,
duration: result_message.duration,
message: create_error_message(result)
message: create_error_message(message_element),
exception: create_exception_object(result, message_element)
)
end

Expand All @@ -211,12 +215,17 @@ def on_test_step_finished(event)
output_envelope(message)
end

def create_error_message(result)
message_element = result.failed? ? result.exception : result
def create_error_message(message_element)
message = "#{message_element.message} (#{message_element.class})"
([message] + message_element.backtrace).join("\n")
end

def create_exception_object(result, message_element)
return unless result.failed?

Cucumber::Messages::Exception.from_h({ type: message_element.class, message: message_element.message })
end

def on_test_case_finished(event)
message = Cucumber::Messages::Envelope.new(
test_case_finished: Cucumber::Messages::TestCaseFinished.new(
Expand Down
8 changes: 6 additions & 2 deletions lib/cucumber/formatter/pretty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,14 @@ def on_test_run_finished(_event)
print_summary
end

def attach(src, media_type)
def attach(src, media_type, filename)
return unless media_type == 'text/x.cucumber.log+plain'

@test_step_output.push src
if filename
@test_step_output.push("#{filename}: #{src}")
else
@test_step_output.push(src)
end
end

private
Expand Down
14 changes: 8 additions & 6 deletions lib/cucumber/glue/proto_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

module Cucumber
module Glue
# Defines the basic API methods availlable in all Cucumber step definitions.
# Defines the basic API methods available in all Cucumber step definitions.
#
# You can, and probably should, extend this API with your own methods that
# make sense in your domain. For more on that, see {Cucumber::Glue::Dsl#World}
Expand Down Expand Up @@ -86,14 +86,16 @@ def log(*messages)
# @param file [string|io] the file to attach.
# It can be a string containing the file content itself, the file path, or an IO ready to be read.
# @param media_type [string] the media type.
# If file is a valid path, media_type can be omitted, it will then be inferred from the file name.
def attach(file, media_type = nil)
# If file is a valid path, media_type can be omitted, it will then be inferred from the file name.
# @param filename [string] the name of the file you wish to specify.
# BEHAVIOUR HERE TBD
luke-hill marked this conversation as resolved.
Show resolved Hide resolved
def attach(file, media_type = nil, filename = nil)
return super unless File.file?(file)

content = File.read(file, mode: 'rb')
media_type = MiniMime.lookup_by_filename(file)&.content_type if media_type.nil?

super(content, media_type.to_s)
super(content, media_type.to_s, filename)
rescue StandardError
super
end
Expand Down Expand Up @@ -152,8 +154,8 @@ def add_modules!(world_modules, namespaced_world_modules)
runtime.ask(question, timeout_seconds)
end

define_method(:attach) do |file, media_type|
runtime.attach(file, media_type)
define_method(:attach) do |file, media_type, filename|
runtime.attach(file, media_type, filename)
end

# Prints the list of modules that are included in the World
Expand Down
18 changes: 17 additions & 1 deletion lib/cucumber/glue/registry_and_more.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,23 @@ def parameter_type_envelope(parameter_type)
name: parameter_type.name,
regular_expressions: parameter_type.regexps.map(&:to_s),
prefer_for_regular_expression_match: parameter_type.prefer_for_regexp_match?,
use_for_snippets: parameter_type.use_for_snippets?
use_for_snippets: parameter_type.use_for_snippets?,
source_reference: Cucumber::Messages::SourceReference.new(
uri: location.file,
location: Cucumber::Messages::Location.new(
line: location.lines.first
)
)
# source_reference: Cucumber::Messages::SourceReference.from_h(
# # TODO: This needs fixing before we release the next version - this is simply put in to trick the
# # CCK into passing the v12 specification - LH -> 26/9/23
# {
# uri: 'foo',
# location: {
# line: 5
# }
# }
# )
)
)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/runtime/user_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def ask(question, timeout_seconds)
# be a path to a file, or if it's an image it may also be a Base64 encoded image.
# The embedded data may or may not be ignored, depending on what kind of formatter(s) are active.
#
def attach(src, media_type)
@visitor.attach(src, media_type)
def attach(src, media_type, filename)
@visitor.attach(src, media_type, filename)
end

private
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/glue/step_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ def step_match(text)

context 'allows log' do
it 'calls "attach" with the correct media type' do
expect(user_interface).to receive(:attach).with('wasup', 'text/x.cucumber.log+plain')
expect(user_interface).to receive(:attach).with('wasup', 'text/x.cucumber.log+plain', nil)
dsl.Given(/Loud/) do
log 'wasup'
end
run_step 'Loud'
end

it 'calls `to_s` if the message is not a String' do
expect(user_interface).to receive(:attach).with('["Not", 1, "string"]', 'text/x.cucumber.log+plain')
expect(user_interface).to receive(:attach).with('["Not", 1, "string"]', 'text/x.cucumber.log+plain', nil)
dsl.Given(/Loud/) do
log ['Not', 1, 'string']
end
Expand Down
6 changes: 0 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
ENV['CUCUMBER_COLORS'] = nil
$LOAD_PATH.unshift(File.dirname(__FILE__))

# For Travis....
require 'cucumber/encoding'

require 'simplecov_setup'

require 'pry'

require 'cucumber'

RSpec.configure do |c|
Expand Down