Skip to content

Commit

Permalink
translate most regexps to cucumber expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jul 24, 2017
1 parent 43e5b2c commit 92208f6
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 24 deletions.
8 changes: 4 additions & 4 deletions features/lib/step_definitions/aruba_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
assert_success result == 'pass'
end

Then(/^"([^"]*)" should not be required$/) do |file_name|
Then('{string} should not be required') do |file_name|
expect(all_output).not_to include("* #{file_name}")
end

Then(/^"([^"]*)" should be required$/) do |file_name|
Then('{string} should be required') do |file_name|
expect(all_output).to include("* #{file_name}")
end

Then(/^it fails before running features with:$/) do |expected|
Then('it fails before running features with:') do |expected|
assert_matching_output("\\A#{expected}", all_output)
assert_success(false)
end

Then(/^the output includes the message "(.*)"$/) do |message|
Then('the output includes the message {string}') do |message|
expect(all_output).to include(message)
end
2 changes: 1 addition & 1 deletion features/lib/step_definitions/cli_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
Then(/^I should see the CLI help$/) do
Then('I should see the CLI help') do
expect(all_output).to include('Usage:')
end
16 changes: 8 additions & 8 deletions features/lib/step_definitions/cucumber_steps.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# frozen_string_literal: true
Given(/^a directory without standard Cucumber project directory structure$/) do
Given('a directory without standard Cucumber project directory structure') do
in_current_dir do
FileUtils.rm_rf 'features' if File.directory?('features')
end
end

Given(/^a scenario with a step that looks like this:$/) do |string|
Given('a scenario with a step that looks like this:') do |string|
create_feature do
create_scenario { string }
end
end

Given(/^a scenario with a step that looks like this in japanese:$/) do |string|
Given('a scenario with a step that looks like this in japanese:') do |string|
create_feature_ja do
create_scenario_ja { string }
end
end

Given(/^the standard step definitions$/) do
Given('the standard step definitions') do
write_file 'features/step_definitions/steps.rb',

<<-STEPS
Expand All @@ -29,11 +29,11 @@
STEPS
end

Given(/^a step definition that looks like this:$/) do |string|
Given('a step definition that looks like this:') do |string|
create_step_definition { string }
end

Given(/^a scenario "([^\"]*)" that passes$/) do |name|
Given('a scenario {string} that passes') do |name|
write_file "features/#{name}.feature",
<<-FEATURE
Feature: #{name}
Expand All @@ -47,7 +47,7 @@
STEPS
end

Given(/^a scenario "([^\"]*)" that fails$/) do |name|
Given('a scenario {string} that fails') do |name|
write_file "features/#{name}.feature",
<<-FEATURE
Feature: #{name}
Expand All @@ -66,7 +66,7 @@
run_feature features.first, formatter
end

Then(/^the stderr should contain a warning message$/) do
Then('the stderr should contain a warning message') do
expect(all_stderr).to include('[warning]')
end

Expand Down
2 changes: 1 addition & 1 deletion features/lib/step_definitions/junit_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
Then(/^the junit output file "(.*?)" should contain:$/) do |actual_file, text|
Then('the junit output file {string} should contain:') do |actual_file, text|
actual = IO.read(current_dir + '/' + actual_file)
actual = replace_junit_time(actual)
expect(actual).to eq text
Expand Down
2 changes: 1 addition & 1 deletion features/lib/step_definitions/language_steps.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
# frozen_string_literal: true

Then(/^cucumber lists all the supported languages$/) do
Then('cucumber lists all the supported languages') do
sample_languages = %w(Arabic български Pirate English 日本語)
sample_languages.each do |language|
expect(all_output.force_encoding('utf-8')).to include(language)
Expand Down
12 changes: 6 additions & 6 deletions features/lib/step_definitions/profile_steps.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true
Given(/^the following profiles? (?:are|is) defined:$/) do |profiles|
Given('the following profile(s) are/is defined:') do |profiles|
write_file 'cucumber.yml', profiles
end

Then(/^the (.*) profile should be used$/) do |profile|
Then('the {word} profile should be used') do |profile|
step 'the stdout should contain:', profile
end

Then(/^exactly these files should be loaded:\s*(.*)$/) do |files|
expect(all_stdout.scan(/^ \* (.*\.rb)$/).flatten).to eq files.split(/,\s+/)
Then('exactly these files should be loaded: {list}') do |files|
expect(all_stdout.scan(/^ \* (.*\.rb)$/).flatten).to eq files
end

Then(/^exactly these features should be run:\s*(.*)$/) do |files|
expect(all_stdout.scan(/^ \* (.*\.feature)$/).flatten).to eq files.split(/,\s+/)
Then('exactly these features should be run: {list}') do |files|
expect(all_stdout.scan(/^ \* (.*\.feature)$/).flatten).to eq files
end
4 changes: 2 additions & 2 deletions features/lib/step_definitions/retry_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
Given(/^a scenario "([^\"]*)" that fails once, then passes$/) do |full_name|
Given('a scenario {string} that fails once, then passes') do |full_name|
name = snake_case(full_name)
write_file "features/#{name}.feature",
<<-FEATURE
Expand All @@ -22,7 +22,7 @@
INIT
end

Given(/^a scenario "([^\"]*)" that fails twice, then passes$/) do |full_name|
Given('a scenario {string} that fails twice, then passes') do |full_name|
name = snake_case(full_name)
write_file "features/#{name}.feature",
<<-FEATURE
Expand Down
2 changes: 1 addition & 1 deletion features/lib/step_definitions/ruby_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
When(/^I run the following Ruby code:$/) do |code|
When('I run the following Ruby code:') do |code|
run_simple %{ruby -e "#{code}"}
end
8 changes: 8 additions & 0 deletions features/lib/support/parameter_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ParameterType(
name: 'list',
regexp: /.*/,
type: Array,
transformer: ->(s) { s.split(/,\s+/)},
use_for_snippets: false,
prefer_for_regexp_match: false
)

0 comments on commit 92208f6

Please sign in to comment.