cucumber_rails3_gen 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -16,4 +16,4 @@ Signal.trap("INT") { puts; exit }
16
16
  require 'rails/generators'
17
17
  require 'generators/cucumber/skeleton/skeleton_generator'
18
18
 
19
- Cucumber::SkeletonGenerator.start
19
+ Cucumber::Generators::SkeletonGenerator.start
@@ -1,178 +1,175 @@
1
1
  # This generator bootstraps a Rails project for use with Cucumber
2
2
  module Cucumber
3
- class SkeletonGenerator < Rails::Generators::Base
3
+ module Generators
4
+ class SkeletonGenerator < Rails::Generators::Base
4
5
 
5
- argument :language, :type => :string, :required => false, :default => 'en'
6
+ argument :language, :type => :string, :required => false, :default => 'en'
6
7
 
7
- class_option :shebang, :type => :boolean, :aliases => "--shebang", :group => :cucumber,
8
- :desc => "Adds shebang marker to script files"
8
+ class_option :shebang, :type => :boolean, :aliases => "--shebang", :group => :cucumber,
9
+ :desc => "Adds shebang marker to script files"
9
10
 
10
- class_option :webrat, :type => :boolean, :aliases => "--webrat", :group => :cucumber,
11
- :desc => "Use webrat"
11
+ class_option :webrat, :type => :boolean, :aliases => "--webrat", :group => :cucumber,
12
+ :desc => "Use webrat"
12
13
 
13
- class_option :capybara, :type => :boolean, :aliases => "--capybara", :group => :cucumber,
14
- :desc => "Use capybara"
14
+ class_option :capybara, :type => :boolean, :aliases => "--capybara", :group => :cucumber,
15
+ :desc => "Use capybara"
15
16
 
16
- class_option :rspec, :type => :boolean, :aliases => "--rspec", :group => :cucumber,
17
- :desc => "Use rspec"
17
+ class_option :rspec, :type => :boolean, :aliases => "--rspec", :group => :cucumber,
18
+ :desc => "Use rspec"
18
19
 
19
- class_option :testunit, :type => :boolean, :aliases => "--testunit", :group => :cucumber,
20
- :desc => "Use testunit"
20
+ class_option :testunit, :type => :boolean, :aliases => "--testunit", :group => :cucumber,
21
+ :desc => "Use testunit"
21
22
 
22
- class_option :spork, :type => :boolean, :aliases => "--spork", :group => :cucumber,
23
- :desc => "Use spork"
23
+ class_option :spork, :type => :boolean, :aliases => "--spork", :group => :cucumber,
24
+ :desc => "Use spork"
24
25
 
25
- DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
26
- Config::CONFIG['ruby_install_name'])
26
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
27
+ Config::CONFIG['ruby_install_name'])
27
28
 
28
29
 
29
- def self.source_root
30
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
31
- end
32
-
33
-
34
- def initialize(*args, &block)
35
- super
36
- # @language = args.empty? ? 'en' : args.first
37
- end
38
-
39
- def my_options
40
- @my_options ||= {}
41
- end
30
+ def self.source_root
31
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
32
+ end
33
+
34
+
35
+ def initialize(*args, &block)
36
+ super
37
+ # @language = args.empty? ? 'en' : args.first
38
+ end
39
+
40
+ def my_options
41
+ @my_options ||= {}
42
+ end
43
+
44
+ def spork?
45
+ options[:spork]
46
+ end
47
+
48
+ def framework
49
+ my_options[:framework] ||= detect_current_framework || detect_default_framework
50
+ end
51
+
52
+ def driver
53
+ my_options[:driver] ||= detect_current_driver || detect_default_driver
54
+ end
42
55
 
43
- def spork?
44
- options[:spork]
45
- end
56
+ # def embed_template(source, indent='')
57
+ # template = File.join(File.dirname(__FILE__), 'templates', source)
58
+ # ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
59
+ # end
60
+
61
+ def version
62
+ filename = File.dirname(__FILE__) + '/../../../../VERSION'
63
+ path = File.expand_path(filename)
64
+ IO.read(filename).chomp
65
+ end
46
66
 
47
- def framework
48
- my_options[:framework] ||= detect_current_framework || detect_default_framework
49
- end
67
+ def create_files
68
+ if File.exist?('features/step_definitions/webrat_steps.rb')
69
+ STDERR.puts "Please remove features/step_definitions/webrat_steps.rb\n" +
70
+ "See upgrading instructions for 0.2.0 in History.txt"
71
+ exit(1)
72
+ end
73
+ if File.exist?('features/support/version_check.rb')
74
+ STDERR.puts "Please remove features/support/version_check.rb\n" +
75
+ "See upgrading instructions for 0.2.0 in History.txt"
76
+ exit(1)
77
+ end
50
78
 
51
- def driver
52
- my_options[:driver] ||= detect_current_driver || detect_default_driver
53
- end
79
+ template 'config/cucumber.yml.erb', 'config/cucumber.yml'
80
+ template 'environments/cucumber.rb.erb', 'config/environments/cucumber.rb'
54
81
 
55
- # def embed_template(source, indent='')
56
- # template = File.join(File.dirname(__FILE__), 'templates', source)
57
- # ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
58
- # end
59
-
60
- def version
61
- filename = File.dirname(__FILE__) + '/../../../../VERSION'
62
- path = File.expand_path(filename)
63
- IO.read(filename).chomp
64
- end
82
+ copy_file 'script/cucumber', 'script/cucumber'
83
+ chmod 'script/cucumber', 0755, :verbose => false, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
84
+
85
+ empty_directory 'features/step_definitions'
86
+ template "step_definitions/#{driver}_steps.rb.erb", 'features/step_definitions/web_steps.rb'
87
+ if language != 'en'
88
+ template "step_definitions/web_steps_#{language}.rb.erb", "features/step_definitions/web_steps_#{language}.rb"
89
+ end
90
+
91
+ empty_directory 'features/support'
92
+ if spork?
93
+ template 'support/rails_spork.rb.erb', 'features/support/env.rb'
94
+ else
95
+ template 'support/rails.rb.erb', 'features/support/env.rb'
96
+ end
97
+ copy_file 'support/paths.rb', 'features/support/paths.rb'
98
+
99
+ empty_directory 'lib/tasks'
100
+ template 'tasks/cucumber.rake.erb', 'lib/tasks/cucumber.rake'
101
+
102
+ gsub_file 'config/database.yml', /test:.*\n/, "test: &TEST\n"
103
+ unless File.read('config/database.yml').include? 'cucumber:'
104
+ gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
105
+ end
106
+
107
+ end
108
+
109
+ no_tasks do
110
+ def embed_file(source, indent='')
111
+ IO.read(File.join(File.dirname(__FILE__), 'templates', source)).gsub(/^/, indent)
112
+ end
65
113
 
66
- def create_files
67
- if File.exist?('features/step_definitions/webrat_steps.rb')
68
- STDERR.puts "Please remove features/step_definitions/webrat_steps.rb\n" +
69
- "See upgrading instructions for 0.2.0 in History.txt"
70
- exit(1)
114
+ def embed_template(source, indent='')
115
+ template = File.join(File.dirname(__FILE__), 'templates', source)
116
+ ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
117
+ end
71
118
  end
72
- if File.exist?('features/support/version_check.rb')
73
- STDERR.puts "Please remove features/support/version_check.rb\n" +
74
- "See upgrading instructions for 0.2.0 in History.txt"
75
- exit(1)
119
+
120
+ def banner
121
+ "Usage: #{$0} cucumber (language)"
76
122
  end
77
123
 
78
- template 'config/cucumber.yml.erb', 'config/cucumber.yml'
79
- template 'environments/cucumber.rb.erb', 'config/environments/cucumber.rb'
80
-
81
- copy_file 'script/cucumber', 'script/cucumber'
82
- chmod 'script/cucumber', 0755, :verbose => false, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
83
124
 
84
- empty_directory 'features/step_definitions'
85
- template "step_definitions/#{driver}_steps.rb.erb", 'features/step_definitions/web_steps.rb'
86
- if language != 'en'
87
- template "step_definitions/web_steps_#{language}.rb.erb", "features/step_definitions/web_steps_#{language}.rb"
125
+ private
126
+ def empty_directory_with_gitkeep(destination, config = {})
127
+ empty_directory(destination, config)
128
+ create_file("#{destination}/.gitkeep") unless options[:skip_git]
129
+ end
130
+
131
+ def first_loadable(libraries)
132
+ require 'rubygems'
133
+ libraries.each do |library|
134
+ begin
135
+ require library[0]
136
+ return library[1]
137
+ rescue LoadError => ignore
138
+ end
139
+ end
140
+ return nil
88
141
  end
89
142
 
90
- empty_directory 'features/support'
91
- if spork?
92
- template 'support/rails_spork.rb.erb', 'features/support/env.rb'
93
- else
94
- template 'support/rails.rb.erb', 'features/support/env.rb'
143
+ def detect_current_driver
144
+ detect_in_env([['capybara', :capybara], ['webrat', :webrat ]])
95
145
  end
96
- copy_file 'support/paths.rb', 'features/support/paths.rb'
97
-
98
- empty_directory 'lib/tasks'
99
- template 'tasks/cucumber.rake.erb', 'lib/tasks/cucumber.rake'
100
-
101
- gsub_file 'config/database.yml', /test:.*\n/, "test: &TEST\n"
102
- unless File.read('config/database.yml').include? 'cucumber:'
103
- gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
146
+
147
+ def detect_default_driver
148
+ @default_driver = first_loadable([['capybara', :capybara], ['webrat', :webrat ]])
149
+ raise "I don't know which driver you want. Use --capybara or --webrat, or gem install capybara or webrat." unless @default_driver
150
+ @default_driver
104
151
  end
105
-
106
- end
107
152
 
108
- def banner
109
- "Usage: #{$0} cucumber (language)"
110
- end
153
+ def detect_current_framework
154
+ detect_in_env([['spec', :rspec], ['test/unit', :testunit]])
155
+ end
111
156
 
112
- private
113
- def empty_directory_with_gitkeep(destination, config = {})
114
- empty_directory(destination, config)
115
- create_file("#{destination}/.gitkeep") unless options[:skip_git]
116
- end
117
-
118
- def first_loadable(libraries)
119
- require 'rubygems'
120
- libraries.each do |library|
121
- begin
122
- require library[0]
123
- return library[1]
124
- rescue LoadError => ignore
125
- end
157
+ def detect_default_framework
158
+ @default_framework = first_loadable([['spec', :rspec], ['test/unit', :testunit]])
159
+ raise "I don't know what test framework you want. Use --rspec or --testunit, or gem install rspec or test-unit." unless @default_framework
160
+ @default_framework
126
161
  end
127
- return nil
128
- end
129
-
130
- def detect_current_driver
131
- detect_in_env([['capybara', :capybara], ['webrat', :webrat ]])
132
- end
133
-
134
- def detect_default_driver
135
- @default_driver = first_loadable([['capybara', :capybara], ['webrat', :webrat ]])
136
- raise "I don't know which driver you want. Use --capybara or --webrat, or gem install capybara or webrat." unless @default_driver
137
- @default_driver
138
- end
139
-
140
- def detect_current_framework
141
- detect_in_env([['spec', :rspec], ['test/unit', :testunit]])
142
- end
143
-
144
- def detect_default_framework
145
- @default_framework = first_loadable([['spec', :rspec], ['test/unit', :testunit]])
146
- raise "I don't know what test framework you want. Use --rspec or --testunit, or gem install rspec or test-unit." unless @default_framework
147
- @default_framework
148
- end
149
-
150
- def detect_in_env(choices)
151
- env = File.file?("features/support/env.rb") ? IO.read("features/support/env.rb") : ''
152
- choices.each do |choice|
153
- detected = choice[1] if env =~ /#{choice[0]}/n
154
- return detected if detected
162
+
163
+ def detect_in_env(choices)
164
+ env = File.file?("features/support/env.rb") ? IO.read("features/support/env.rb") : ''
165
+ choices.each do |choice|
166
+ detected = choice[1] if env =~ /#{choice[0]}/n
167
+ return detected if detected
168
+ end
169
+ return nil
155
170
  end
156
- return nil
157
171
  end
158
172
  end
159
173
  end
160
174
 
161
- module Cucumber
162
- module Helper
163
- class << self
164
- attr_accessor :framework
165
- end
166
-
167
- def self.embed_file(source, indent='')
168
- IO.read(File.join(File.dirname(__FILE__), 'templates', source)).gsub(/^/, indent)
169
- end
170
-
171
- def self.embed_template(source, indent='')
172
- template = File.join(File.dirname(__FILE__), 'templates', source)
173
- ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
174
- end
175
- end
176
- end
177
-
178
175
 
@@ -1,4 +1,4 @@
1
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
1
+ <%= embed_file('support/edit_warning.txt') %>
2
2
 
3
3
  require 'uri'
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
+ <%= embed_file('support/edit_warning.txt') %>
3
3
 
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
5
 
@@ -1,4 +1,4 @@
1
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
1
+ <%= embed_file('support/edit_warning.txt') %>
2
2
 
3
3
  require 'uri'
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
@@ -1,5 +1,4 @@
1
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
2
- <% Cucumber::Helper.framework = framework %>
3
- <%= Cucumber::Helper.embed_template('support/_rails_prefork.rb.erb') %>
4
- <%= Cucumber::Helper.embed_file("support/#{driver}.rb") %>
5
- <%= Cucumber::Helper.embed_file('support/_rails_each_run.rb') %>
1
+ <%= embed_file('support/edit_warning.txt') %>
2
+ <%= embed_template('support/_rails_prefork.rb.erb') %>
3
+ <%= embed_file("support/#{driver}.rb") %>
4
+ <%= embed_file('support/_rails_each_run.rb') %>
@@ -1,13 +1,13 @@
1
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
1
+ <%= embed_file('support/edit_warning.txt') %>
2
2
  require 'rubygems'
3
3
  require 'spork'
4
4
 
5
5
  Spork.prefork do
6
- <%= Cucumber::Helper.embed_template('support/_rails_prefork.rb.erb', ' ') %>
6
+ <%= embed_template('support/_rails_prefork.rb.erb', ' ') %>
7
7
 
8
- <%= Cucumber::Helper.embed_file("support/#{driver}.rb", ' ') %>
8
+ <%= embed_file("support/#{driver}.rb", ' ') %>
9
9
  end
10
10
 
11
11
  Spork.each_run do
12
- <%= Cucumber::Helper.embed_file('support/_rails_each_run.rb', ' ') %>
12
+ <%= embed_file('support/_rails_each_run.rb', ' ') %>
13
13
  end
@@ -1,4 +1,4 @@
1
- <%= Cucumber::Helper.embed_file('support/edit_warning.txt') %>
1
+ <%= embed_file('support/edit_warning.txt') %>
2
2
 
3
3
  unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber_rails3_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Mandrup