add a generator, 'cause i'm both lazy and not lazy

This commit is contained in:
John Bintz 2012-04-19 16:01:46 -04:00
parent c1379a1a9d
commit a3e4743658
5 changed files with 40 additions and 0 deletions

View File

@ -24,6 +24,12 @@ Cucumber::StepWriter.after_write do |dir|
end end
``` ```
Set up your sane defaults by using the generator:
``` bash
rails generator cucumber:step_writer
```
TODO: TODO:
* If you want it to generate for different languages, I take pull requests. * If you want it to generate for different languages, I take pull requests.

View File

@ -1 +1,4 @@
require "cucumber/step_writer" require "cucumber/step_writer"
require "cucumber/step_writer/railtie" if defined?(::Rails)

View File

@ -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

View File

@ -0,0 +1,8 @@
module Cucumber
class StepWriterRailtie < Rails::Railtie
generators do
load File.expand_path('../generators.rb', __FILE__)
end
end
end

10
skel/step_writer.rb Normal file
View File

@ -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