Skip to content

Commit b1dff7f

Browse files
author
Sam Phippen
committed
Merge pull request #1508 from rspec/1403_singular_generator
#1503 with changelog.
2 parents e566410 + bf9de9a commit b1dff7f

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

Changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
### 3.4.1 Development
1+
### 3.5.0 Development
22
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.4.0...master)
33

4+
Enhancements:
5+
6+
* Add a `---singularize` option for the feature spec generator (Felicity McCabe,
7+
#1503)
8+
49
Bug fixes:
510

611
* Make it possible to write nested specs within helper specs on classes that are

lib/generators/rspec/feature/feature_generator.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ module Rspec
44
module Generators
55
# @private
66
class FeatureGenerator < Base
7-
class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs"
7+
class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs"
8+
class_option :singularize, :type => :boolean, :default => false, :desc => "Singularize the generated feature"
89

910
def generate_feature_spec
1011
return unless options[:feature_specs]
1112

12-
template 'feature_spec.rb', File.join('spec/features', class_path, "#{table_name}_spec.rb") # file_name?
13+
template template_name, File.join('spec/features', class_path, filename)
14+
end
15+
16+
def template_name
17+
options[:singularize] ? 'feature_singular_spec.rb' : 'feature_spec.rb'
18+
end
19+
20+
def filename
21+
if options[:singularize]
22+
"#{table_name.singularize}_spec.rb"
23+
else
24+
"#{table_name}_spec.rb"
25+
end
1326
end
1427
end
1528
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'rails_helper'
2+
3+
RSpec.feature "<%= class_name.singularize %>", <%= type_metatag(:feature) %> do
4+
pending "add some scenarios (or delete) #{__FILE__}"
5+
end

spec/generators/rspec/feature/feature_generator_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
end
2525
end
2626

27+
describe 'are singularized appropriately with the --singularize flag' do
28+
before do
29+
run_generator %w(posts --singularize)
30+
end
31+
describe 'the spec' do
32+
subject(:feature_spec) { file('spec/features/post_spec.rb') }
33+
it "exists with the appropriate filename" do
34+
expect(feature_spec).to exist
35+
end
36+
it "contains the singularized feature" do
37+
expect(feature_spec).to contain(/^RSpec.feature \"Post\", #{type_metatag(:feature)}/)
38+
end
39+
end
40+
end
41+
2742
describe "are not generated" do
2843
before do
2944
run_generator %w(posts --no-feature-specs)

0 commit comments

Comments
 (0)