Skip to content

Commit ca988b0

Browse files
committed
Rails generate generator command create spec by default
1 parent 55515e1 commit ca988b0

File tree

3 files changed

+12
-37
lines changed

3 files changed

+12
-37
lines changed

features/generator_specs/generator_specs.feature

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@ Feature: Generator spec
22

33
RSpec spec(s) can be generated when generating application components. For instance, `rails generate model` will also generate an RSpec spec file for the model but you can also write your own generator. See [customizing your workflow](https://guides.rubyonrails.org/generators.html#customizing-your-workflow)
44

5-
Scenario: Use custom generator without '--generator-specs' arg
5+
Scenario: Use custom generator
66
When I run `bundle exec rails generate generator my_generator`
77
Then the features should pass
8-
Then the output should contain:
9-
"""
10-
create lib/generators/my_generator
11-
create lib/generators/my_generator/my_generator_generator.rb
12-
create lib/generators/my_generator/USAGE
13-
create lib/generators/my_generator/templates
14-
invoke rspec
15-
"""
16-
17-
Scenario: Use custom generator with '--generator-specs' arg
18-
When I run `bundle exec rails generate generator my_generator --generator-specs`
19-
Then the features should pass
208
Then the output should contain:
219
"""
2210
create lib/generators/my_generator

lib/generators/rspec/generator/generator_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Rspec
44
module Generators
55
# @private
66
class GeneratorGenerator < Base
7-
class_option :generator_specs, type: :boolean, default: false, desc: "Generate generator specs"
7+
class_option :generator_specs, type: :boolean, default: true, desc: "Generate generator specs"
88

99
def generate_generator_spec
1010
return unless options[:generator_specs]

spec/generators/rspec/generator/generator_generator_spec.rb

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,17 @@
66

77
describe "generator specs" do
88
subject(:generator_spec) { file("spec/generator/posts_generator_spec.rb") }
9-
describe "are generated independently/can be generated" do
10-
before do
11-
run_generator %w(posts --generator-specs)
12-
end
13-
it "creates the spec file" do
14-
expect(generator_spec).to exist
15-
end
16-
it "contains 'rails_helper in the spec file'" do
17-
expect(generator_spec).to contain(/require 'rails_helper'/)
18-
end
19-
it "includes the generator type in the metadata" do
20-
expect(generator_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:generator)}/)
21-
end
9+
before do
10+
run_generator %w(posts)
2211
end
23-
24-
describe "are not generated/are skipped by default" do
25-
before do
26-
run_generator %w(posts)
27-
end
28-
describe "the spec" do
29-
it "does not exist" do
30-
expect(generator_spec).to_not exist
31-
end
32-
end
12+
it "creates the spec file by default" do
13+
expect(generator_spec).to exist
14+
end
15+
it "contains 'rails_helper in the spec file'" do
16+
expect(generator_spec).to contain(/require 'rails_helper'/)
17+
end
18+
it "includes the generator type in the metadata" do
19+
expect(generator_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:generator)}/)
3320
end
3421
end
3522
end

0 commit comments

Comments
 (0)