Skip to content

Instantly share code, notes, and snippets.

@arukoh
Created May 26, 2013 06:44
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/5651913 to your computer and use it in GitHub Desktop.
Save arukoh/5651913 to your computer and use it in GitHub Desktop.
Cucumber Tips。 ステップ定義をJSONファイルにダンプ。
# encoding: utf-8
#!/usr/bin/env ruby
require "./runtime"
unless ARGV.include?("--dotcucumber")
STDERR.puts "Must be specified option --dotcucumber OUTPUT_DIR"
exit 1
end
runtime = Runtime.new(ARGV.dup)
runtime.write_stepdefs_json
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
# use example: https://github.com/cucumber/cucumber/tree/master/examples/i18n/en/features
$ ruby dump_step_definitions.rb --dotcucumber /path/to/.cucumber/ examples/i18n/en/features
write to /path/to/.cucumber/stepdefs.json
$ cat /path/to/.cucumber/stepdefs.json
[
{
"source": "I have entered (\\d+) into the calculator",
"flags": "",
"file_colon_line": "examples/i18n/en/features/step_definitons/calculator_steps.rb:14",
"steps": [
{
"name": "I have entered 2 into the calculator",
"args": [
{
"offset": 15,
"val": "2"
}
]
},
{
"name": "I have entered 3 into the calculator",
"args": [
{
"offset": 15,
"val": "3"
}
]
}
]
},
{
"source": "I press (\\w+)",
"flags": "",
"file_colon_line": "examples/i18n/en/features/step_definitons/calculator_steps.rb:18",
"steps": [
{
"name": "I press divide",
"args": [
{
"offset": 8,
"val": "divide"
}
]
}
]
},
{
"source": "the result should be (.*) on the screen",
"flags": "",
"file_colon_line": "examples/i18n/en/features/step_definitons/calculator_steps.rb:22",
"steps": [
{
"name": "the result should be 1.5 on the screen",
"args": [
{
"offset": 21,
"val": "1.5"
}
]
},
{
"name": "the result should be <output> on the screen",
"args": [
{
"offset": 21,
"val": "<output>"
}
]
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment