Skip to content

Commit

Permalink
Introduce Cucumber parameter type 'command'
Browse files Browse the repository at this point in the history
This allows more steps to use the Cucumber Expression syntax.
  • Loading branch information
mvz committed Nov 15, 2024
1 parent 3cf9aa8 commit e096c9f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/aruba/cucumber/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/aruba/cucumber/parameter_types.rb
Original file line number Diff line number Diff line change
@@ -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 })

0 comments on commit e096c9f

Please sign in to comment.