Skip to content

Instantly share code, notes, and snippets.

@SFEley
Forked from andrzejsliwa/gist:778535
Created June 29, 2011 18:43
Show Gist options
  • Save SFEley/1054553 to your computer and use it in GitHub Desktop.
Save SFEley/1054553 to your computer and use it in GitHub Desktop.
list all available cucumber steps - (rake cucumber:steps)
# From https://gist.github.com/778535
# In turn based on http://www.natontesting.com/2010/01/11/updated-script-to-list-all-cucumber-step-definitions/
desc "List all available steps"
task :steps do
require 'hirb'
extend Hirb::Console
features_dir = "features"
step_candidates = Dir.glob(File.join(features_dir,'**/*.rb'))
# Follow all the gem requires, and identify which files have steps in them
step_files = []
step_candidates.each do |candidate|
File.foreach(candidate) do |line|
if line =~ /require ['"](.*\/.*)['"]/
if libfile = `gem which #{$1} 2>/dev/null`.chomp
step_candidates << libfile unless step_candidates.include?(libfile)
end
elsif line =~ /^\s*(?:Given|When|Then)\s+/
step_files << candidate
end
end
end
step_files.uniq.each do |step_file|
puts "File: #{step_file}"
puts ""
results = []
File.new(step_file).read.each_line.each_with_index do |line, number|
next unless line =~ /^\s*(?:Given|When|Then)\s+|\//
res = /(?:Given|When|Then)[\s\(]*\/(.*)\/([imxo]*)[\s\)]*do\s*(?:$|\|(.*)\|)/.match(line)
next unless res
matches = res.captures
results << OpenStruct.new(
:steps => matches[0],
:args => matches[2]
)
end
table results, :resize => false, :fields=>[:steps, :args]
puts ""
end
end
File: features/step_definitions/instance_steps.rb
+---------------------------------+------------+
| steps | args |
+---------------------------------+------------+
| ^an? (\S+) instance named '.*'$ | type, name |
+---------------------------------+------------+
1 row in set
File: /Users/Steve/.rvm/gems/ruby-1.9.2-p180@warden/gems/aruba-0.4.3/lib/aruba/cucumber.rb
+----------------------------------------------------------+---------------------------+
| steps | args |
+----------------------------------------------------------+---------------------------+
| ^I'm using a clean gemset "([^"]*)"$ | gemset |
| ^a directory named "([^"]*)"$ | dir_name |
| ^a file named "([^"]*)" with:$ | file_name, file_content |
| ^an empty file named "([^"]*)"$ | file_name |
| ^I write to "([^"]*)" with:$ | file_name, file_content |
| ^I overwrite "([^"]*)" with:$ | file_name, file_content |
| ^I append to "([^"]*)" with:$ | file_name, file_content |
| ^I append to "([^"]*)" with "([^"]*)"$ | file_name, file_content |
| ^I remove the file "([^"]*)"$ | file_name |
| ^I cd to "([^"]*)"$ | dir |
| ^I run "(.*)"$ | cmd |
| ^I run `([^`]*)`$ | cmd |
| ^I successfully run "(.*)"$ | cmd |
| ^I successfully run `([^`]*)`$ | cmd |
| ^I run "([^"]*)" interactively$ | cmd |
| ^I run `([^`]*)` interactively$ | cmd |
| ^I type "([^"]*)"$ | input |
| ^the output should contain "([^"]*)"$ | expected |
| ^the output from "([^"]*)" should contain "([^"]*)"$ | cmd, expected |
| ^the output from "([^"]*)" should not contain "([^"]*)"$ | cmd, unexpected |
| ^the output should not contain "([^"]*)"$ | unexpected |
| ^the output should contain:$ | expected |
| ^the output should not contain:$ | unexpected |
| ^the output should contain exactly "([^"]*)"$ | expected |
| ^the output should contain exactly:$ | expected |
| ^the output should match \/([^\/]*)\/$ | expected |
| ^the output should match:$ | expected |
| ^the exit status should be (\d+)$ | exit_status |
| ^the exit status should not be (\d+)$ | exit_status |
| ^it should (pass|fail) with:$ | pass_fail, partial_output |
| ^it should (pass|fail) with exactly:$ | pass_fail, exact_output |
| ^it should (pass|fail) with regexp?:$ | pass_fail, expected |
| ^the stderr should contain "([^"]*)"$ | expected |
| ^the stderr should contain:$ | expected |
| ^the stderr should contain exactly:$ | expected |
| ^the stdout should contain "([^"]*)"$ | expected |
| ^the stdout should contain:$ | expected |
| ^the stdout should contain exactly:$ | expected |
| ^the stderr should not contain "([^"]*)"$ | unexpected |
| ^the stderr should not contain:$ | unexpected |
| ^the stdout should not contain "([^"]*)"$ | unexpected |
| ^the stdout should not contain:$ | unexpected |
| ^the stdout from "([^"]*)" should contain "([^"]*)"$ | cmd, expected |
| ^the stdout from "([^"]*)" should not contain "([^"]*)"$ | cmd, unexpected |
| ^the stderr from "([^"]*)" should contain "([^"]*)"$ | cmd, expected |
| ^the stderr from "([^"]*)" should not contain "([^"]*)"$ | cmd, unexpected |
| ^the file "([^"]*)" should not exist$ | file_name |
| ^the following files should exist:$ | files |
| ^the following files should not exist:$ | files |
| ^a file named "([^"]*)" should exist$ | file |
| ^a file named "([^"]*)" should not exist$ | file |
| ^the following directories should exist:$ | directories |
| ^the following directories should not exist:$ | directories |
| ^a directory named "([^"]*)" should exist$ | directory |
| ^a directory named "([^"]*)" should not exist$ | directory |
| ^the file "([^"]*)" should contain "([^"]*)"$ | file, partial_content |
| ^the file "([^"]*)" should not contain "([^"]*)"$ | file, partial_content |
| ^the file "([^"]*)" should contain exactly:$ | file, exact_content |
| ^the file "([^"]*)" should match \/([^\/]*)\/$ | file, partial_content |
| ^the file "([^"]*)" should not match \/([^\/]*)\/$ | file, partial_content |
+----------------------------------------------------------+---------------------------+
60 rows in set
@aquadrehz
Copy link

I'm new for Ruby. Can I know how to use this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment