From a3e4743658f0d574f1b96cf94626a313cfb209d7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 19 Apr 2012 16:01:46 -0400 Subject: [PATCH] add a generator, 'cause i'm both lazy and not lazy --- README.md | 6 ++++++ lib/cucumber-step_writer.rb | 3 +++ lib/cucumber/step_writer/generators.rb | 13 +++++++++++++ lib/cucumber/step_writer/railtie.rb | 8 ++++++++ skel/step_writer.rb | 10 ++++++++++ 5 files changed, 40 insertions(+) create mode 100644 lib/cucumber/step_writer/generators.rb create mode 100644 lib/cucumber/step_writer/railtie.rb create mode 100644 skel/step_writer.rb diff --git a/README.md b/README.md index 58bbf58..93a355e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ Cucumber::StepWriter.after_write do |dir| end ``` +Set up your sane defaults by using the generator: + +``` bash +rails generator cucumber:step_writer +``` + TODO: * If you want it to generate for different languages, I take pull requests. diff --git a/lib/cucumber-step_writer.rb b/lib/cucumber-step_writer.rb index c345314..cbf13a9 100644 --- a/lib/cucumber-step_writer.rb +++ b/lib/cucumber-step_writer.rb @@ -1 +1,4 @@ require "cucumber/step_writer" + +require "cucumber/step_writer/railtie" if defined?(::Rails) + diff --git a/lib/cucumber/step_writer/generators.rb b/lib/cucumber/step_writer/generators.rb new file mode 100644 index 0000000..bb21ecb --- /dev/null +++ b/lib/cucumber/step_writer/generators.rb @@ -0,0 +1,13 @@ +module Cucumber + class StepWriterGenerator < Rails::Generators::Base + source_root File.expand_path('../../../../skel', __FILE__) + + desc "Create a step writer that opens your step definitiosn folder once steps are generated" + def generate_step_writer_after_hook + copy_file 'step_writer.rb', 'features/support/step_writer.rb' + insert_into_file 'config/cucumber.yml', + "# inserted by cucumber-step_writer\nstd_opts << ' -f Cucumber::StepWriter --out features/step_definitions'\n", + :after => %r{std_opts = "--format[^\n]*\n} + end + end +end diff --git a/lib/cucumber/step_writer/railtie.rb b/lib/cucumber/step_writer/railtie.rb new file mode 100644 index 0000000..8200087 --- /dev/null +++ b/lib/cucumber/step_writer/railtie.rb @@ -0,0 +1,8 @@ +module Cucumber + class StepWriterRailtie < Rails::Railtie + generators do + load File.expand_path('../generators.rb', __FILE__) + end + end +end + diff --git a/skel/step_writer.rb b/skel/step_writer.rb new file mode 100644 index 0000000..727374d --- /dev/null +++ b/skel/step_writer.rb @@ -0,0 +1,10 @@ +Cucumber::StepWriter.after_write do |dir| + %w{open xdg-open}.each do |cmd| + %x{which #{cmd}} + + if $?.exitstatus + system %{#{cmd} #{dir}} + break + end + end +end