Skip to content

#1503 with changelog. #1508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
### 3.4.1 Development
### 3.5.0 Development
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.4.0...master)

Enhancements:

* Add a `---singularize` option for the feature spec generator (Felicity McCabe,
#1503)

Bug fixes:

* Make it possible to write nested specs within helper specs on classes that are
Expand Down
17 changes: 15 additions & 2 deletions lib/generators/rspec/feature/feature_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@ module Rspec
module Generators
# @private
class FeatureGenerator < Base
class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs"
class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs"
class_option :singularize, :type => :boolean, :default => false, :desc => "Singularize the generated feature"

def generate_feature_spec
return unless options[:feature_specs]

template 'feature_spec.rb', File.join('spec/features', class_path, "#{table_name}_spec.rb") # file_name?
template template_name, File.join('spec/features', class_path, filename)
end

def template_name
options[:singularize] ? 'feature_singular_spec.rb' : 'feature_spec.rb'
end

def filename
if options[:singularize]
"#{table_name.singularize}_spec.rb"
else
"#{table_name}_spec.rb"
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.feature "<%= class_name.singularize %>", <%= type_metatag(:feature) %> do
pending "add some scenarios (or delete) #{__FILE__}"
end
15 changes: 15 additions & 0 deletions spec/generators/rspec/feature/feature_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
end
end

describe 'are singularized appropriately with the --singularize flag' do
before do
run_generator %w(posts --singularize)
end
describe 'the spec' do
subject(:feature_spec) { file('spec/features/post_spec.rb') }
it "exists with the appropriate filename" do
expect(feature_spec).to exist
end
it "contains the singularized feature" do
expect(feature_spec).to contain(/^RSpec.feature \"Post\", #{type_metatag(:feature)}/)
end
end
end

describe "are not generated" do
before do
run_generator %w(posts --no-feature-specs)
Expand Down