From 3cf9aa8e04ed6cb25601a613a2c62eab4f8eeb08 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 15 Nov 2024 13:58:00 +0100 Subject: [PATCH 1/2] Make scenario for 'I run the following script' step not require python Using just a script that uses Ruby is enough to test this step. --- .../command/run_commands_which_require_a_shell.feature | 10 ---------- features/step_definitions/hooks.rb | 6 ------ 2 files changed, 16 deletions(-) diff --git a/features/03_testing_frameworks/cucumber/steps/command/run_commands_which_require_a_shell.feature b/features/03_testing_frameworks/cucumber/steps/command/run_commands_which_require_a_shell.feature index 1bf4dc1ec..8c3dea621 100644 --- a/features/03_testing_frameworks/cucumber/steps/command/run_commands_which_require_a_shell.feature +++ b/features/03_testing_frameworks/cucumber/steps/command/run_commands_which_require_a_shell.feature @@ -12,7 +12,6 @@ Feature: Running shell commands Given I use a fixture named "cli-app" @requires-ruby - @requires-python Scenario: Creating and running scripts Given a file named "features/shell.feature" with: """ @@ -25,15 +24,6 @@ Feature: Running shell commands puts "Hello" \"\"\" Then the output should contain exactly "Hello" - - Scenario: Running python script - When I run the following script: - \"\"\"bash - #!/usr/bin/env python - - print("Hello") - \"\"\" - Then the output should contain exactly "Hello" """ When I run `cucumber` Then the features should all pass diff --git a/features/step_definitions/hooks.rb b/features/step_definitions/hooks.rb index 317f8a354..181e6c28f 100644 --- a/features/step_definitions/hooks.rb +++ b/features/step_definitions/hooks.rb @@ -2,12 +2,6 @@ require 'cucumber/platform' -Before '@requires-python' do - next unless Aruba.platform.which('python').nil? - - skip_this_scenario -end - Before '@requires-zsh' do next unless Aruba.platform.which('zsh').nil? From e096c9f92f3ee08fc8db6f0262aa7159c058e055 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 15 Nov 2024 14:02:14 +0100 Subject: [PATCH 2/2] Introduce Cucumber parameter type 'command' This allows more steps to use the Cucumber Expression syntax. --- lib/aruba/cucumber/command.rb | 31 ++++++++++++++++++--------- lib/aruba/cucumber/parameter_types.rb | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 619ebad13..71459d5eb 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -2,35 +2,46 @@ require 'aruba/generators/script_file' -When(/^I run `([^`]*)`$/) do |cmd| +When 'I run {command}' do |cmd| cmd = sanitize_text(cmd) run_command_and_stop(cmd, fail_on_error: false) end -## I successfully run `echo -n "Hello"` -## I successfully run `sleep 29` for up to 30 seconds -When(/^I successfully run `(.*?)`(?: for up to ([\d.]+) seconds)?$/) do |cmd, secs| +When 'I successfully run {command}' do |cmd| cmd = sanitize_text(cmd) - run_command_and_stop(cmd, fail_on_error: true, exit_timeout: secs && secs.to_f) + run_command_and_stop(cmd, fail_on_error: true) end -When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) \ - do |shell, commands| +When 'I successfully run {command} for up to {float} seconds' do |cmd, secs| + cmd = sanitize_text(cmd) + run_command_and_stop(cmd, fail_on_error: true, exit_timeout: secs.to_f) +end + +When 'I run the following commands:/script:' do |commands| + full_path = expand_path('bin/myscript') + + Aruba.platform.mkdir(expand_path('bin')) + shell = Aruba.platform.default_shell + + Aruba::ScriptFile.new(interpreter: shell, content: commands, path: full_path).call + run_command_and_stop(Shellwords.escape(full_path), fail_on_error: false) +end + +When 'I run the following commands/script with/in {command}:' do |shell, commands| full_path = expand_path('bin/myscript') Aruba.platform.mkdir(expand_path('bin')) - shell ||= Aruba.platform.default_shell Aruba::ScriptFile.new(interpreter: shell, content: commands, path: full_path).call run_command_and_stop(Shellwords.escape(full_path), fail_on_error: false) end -When(/^I run `([^`]*)` interactively$/) do |cmd| +When 'I run {command} interactively' do |cmd| run_command(sanitize_text(cmd)) end # Merge interactive and background after refactoring with event queue -When(/^I run `([^`]*)` in background$/) do |cmd| +When 'I run {command} in background' do |cmd| run_command(sanitize_text(cmd)) end diff --git a/lib/aruba/cucumber/parameter_types.rb b/lib/aruba/cucumber/parameter_types.rb index 5680893b4..c3b4f852d 100644 --- a/lib/aruba/cucumber/parameter_types.rb +++ b/lib/aruba/cucumber/parameter_types.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true ParameterType(name: 'channel', regexp: 'output|stderr|stdout', transformer: ->(name) { name }) +ParameterType(name: 'command', regexp: '`([^`]*)`', transformer: ->(name) { name })