Created
May 26, 2013 06:44
-
-
Save arukoh/5651913 to your computer and use it in GitHub Desktop.
Cucumber Tips。 ステップ定義をJSONファイルにダンプ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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