-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #775 from fontno/generator-feature
Add feature generator and include in list of available generators
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ The same generator pattern is available for all specs: | |
* mailer | ||
* observer | ||
* integration | ||
* feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'generators/rspec' | ||
|
||
module Rspec | ||
module Generators | ||
class FeatureGenerator < Base | ||
class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs" | ||
|
||
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? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
feature "<%= class_name.pluralize %>" do | ||
pending "add some scenarios (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'spec_helper' | ||
|
||
# Generators are not automatically loaded by rails | ||
require 'generators/rspec/feature/feature_generator' | ||
|
||
describe Rspec::Generators::FeatureGenerator do | ||
# Tell the generator where to put its output (what it thinks of as Rails.root) | ||
destination File.expand_path("../../../../../temp", __FILE__) | ||
|
||
before { prepare_destination } | ||
|
||
describe 'feature specs' do | ||
describe 'are generated independently from the command line' do | ||
before do | ||
run_generator %w(posts) | ||
end | ||
describe 'the spec' do | ||
subject(:feature_spec) { file('spec/features/posts_spec.rb') } | ||
it "exists" do | ||
expect(feature_spec).to exist | ||
end | ||
it "contains 'spec_helper'" do | ||
expect(feature_spec).to contain(/require 'spec_helper'/) | ||
end | ||
it "contains the feature" do | ||
expect(feature_spec).to contain(/feature "Posts"/) | ||
end | ||
end | ||
end | ||
|
||
describe "are not generated" do | ||
before do | ||
run_generator %w(posts --no-feature-specs) | ||
end | ||
describe "the spec" do | ||
subject(:feature_spec) { file('spec/features/posts_spec.rb') } | ||
it "does not exist" do | ||
expect(feature_spec).to_not exist | ||
end | ||
end | ||
end | ||
end | ||
end |