Skip to content

Instantly share code, notes, and snippets.

@arukoh
Created May 26, 2013 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arukoh/5651920 to your computer and use it in GitHub Desktop.
Save arukoh/5651920 to your computer and use it in GitHub Desktop.
Cucumber Tips。 フィーチャのシナリオステップ名にマッピングされている「ステップ定義」を検索する。
# encoding: utf-8
#!/usr/bin/env ruby
require "./runtime"
if ARGV.empty?
STDERR.puts "Must be specified STEP_NAME"
exit 1
end
step_name = ARGV.shift
runtime = Runtime.new(ARGV.dup)
step_match = runtime.step_match(step_name)
step_definition = step_match.step_definition
puts "step definition"
puts "\tfile:\t#{step_definition.file}"
puts "\tline:\t#{step_definition.file_colon_line.delete("#{step_definition.file}:")}"
puts "\tstep:\t#{step_definition.to_hash}"
puts "\targuments:"
step_match.step_arguments.each do |arg|
puts "\t\t#{arg.to_hash}"
end
require "cucumber"
module Cucumber
class Runtime
def load
load_step_definitions
end
end
end
class Runtime
def initialize(args=[])
@configuration = Cucumber::Cli::Configuration.new(STDOUT, STDERR)
@configuration.parse!(args)
@runtime = Cucumber::Runtime.new(@configuration)
@runtime.load
end
def step_match(step_name)
@runtime.step_match(step_name)
end
def write_stepdefs_json
@runtime.write_stepdefs_json
puts "write to " + File.expand_path(Dir.glob("#{@configuration.dotcucumber}/*").first) if @configuration.dotcucumber
end
end
$ ruby find_step_definition.rb "the result should be 1.5 on the screen" examples/i18n/en/features/
step definition
file: examples/i18n/en/features/step_definitons/calculator_steps.rb
line: 22
step: {"source"=>"the result should be (.*) on the screen", "flags"=>""}
arguments:
{"offset"=>21, "val"=>"1.5"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment