Skip to content

Commit 5b10339

Browse files
committed
Update existing generator specs.
This updates the existing generator specs: - Remove old `require 'spec_helper'`; `.rspec` does this now - Do not use the monkey patch version of `describe` - Use the generator support macros for the shared common setup
1 parent 66bb6a7 commit 5b10339

File tree

10 files changed

+31
-64
lines changed

10 files changed

+31
-64
lines changed

spec/generators/rspec/controller/controller_generator_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/controller/controller_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::ControllerGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path("../../../../../tmp", __FILE__)
9-
10-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::ControllerGenerator, :type => :generator do
6+
setup_default_destination
117

128
describe 'controller specs' do
139
subject { file('spec/controllers/posts_controller_spec.rb') }

spec/generators/rspec/feature/feature_generator_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by rails
42
require 'generators/rspec/feature/feature_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::FeatureGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path('../../../../../tmp', __FILE__)
9-
10-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::FeatureGenerator, :type => :generator do
6+
setup_default_destination
117

128
describe 'feature specs' do
139
describe 'are generated independently from the command line' do

spec/generators/rspec/helper/helper_generator_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/helper/helper_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::HelperGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path("../../../../../tmp", __FILE__)
9-
10-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::HelperGenerator, :type => :generator do
6+
setup_default_destination
117

128
subject { file('spec/helpers/posts_helper_spec.rb') }
139
describe 'generated by default' do

spec/generators/rspec/install/install_generator_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
require 'spec_helper'
1+
# Generators are not automatically loaded by Rails
22
require 'generators/rspec/install/install_generator'
3+
require 'support/generators'
34

45
RSpec.describe Rspec::Generators::InstallGenerator, :type => :generator do
5-
destination File.expand_path("../../../../../tmp", __FILE__)
6-
76
def use_active_record_migration
87
match(/ActiveRecord::Migration\./m)
98
end
@@ -32,7 +31,7 @@ def use_transactional_fixtures
3231
match(/config\.use_transactional_fixtures/m)
3332
end
3433

35-
before { prepare_destination }
34+
setup_default_destination
3635

3736
let(:rails_helper) { content_for('spec/rails_helper.rb') }
3837
let(:spec_helper) { content_for('spec/spec_helper.rb') }

spec/generators/rspec/job/job_generator_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/job/job_generator'
3+
require 'support/generators'
54

65
RSpec.describe Rspec::Generators::JobGenerator, :type => :generator, :skip => !RSpec::Rails::FeatureCheck.has_active_job? do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path('../../../../../tmp', __FILE__)
9-
10-
before { prepare_destination }
6+
setup_default_destination
117

128
describe 'the generated files' do
139
before { run_generator %w(user) }

spec/generators/rspec/mailer/mailer_generator_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/mailer/mailer_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::MailerGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path("../../../../../tmp", __FILE__)
9-
10-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::MailerGenerator, :type => :generator do
6+
setup_default_destination
117

128
describe 'mailer spec' do
139
subject { file('spec/mailers/posts_spec.rb') }

spec/generators/rspec/model/model_generator_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/model/model_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::ModelGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path("../../../../../tmp", __FILE__)
9-
10-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::ModelGenerator, :type => :generator do
6+
setup_default_destination
117

128
it 'runs both the model and fixture tasks' do
139
gen = generator %w(posts)

spec/generators/rspec/observer/observer_generator_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/observer/observer_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::ObserverGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path("../../../../../tmp", __FILE__)
5+
RSpec.describe Rspec::Generators::ObserverGenerator, :type => :generator do
6+
setup_default_destination
97

108
subject { file('spec/models/posts_observer_spec.rb') }
9+
1110
before do
12-
prepare_destination
1311
run_generator %w(posts)
1412
end
1513

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
require 'spec_helper'
2-
1+
# Generators are not automatically loaded by Rails
32
require 'generators/rspec/scaffold/scaffold_generator'
3+
require 'support/generators'
44

5-
describe Rspec::Generators::ScaffoldGenerator, :type => :generator do
6-
destination File.expand_path("../../../../../tmp", __FILE__)
7-
8-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::ScaffoldGenerator, :type => :generator do
6+
setup_default_destination
97

108
describe 'standard controller spec' do
119
subject { file('spec/controllers/posts_controller_spec.rb') }

spec/generators/rspec/view/view_generator_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
require 'spec_helper'
2-
31
# Generators are not automatically loaded by Rails
42
require 'generators/rspec/view/view_generator'
3+
require 'support/generators'
54

6-
describe Rspec::Generators::ViewGenerator, :type => :generator do
7-
# Tell the generator where to put its output (what it thinks of as Rails.root)
8-
destination File.expand_path("../../../../../tmp", __FILE__)
9-
10-
before { prepare_destination }
5+
RSpec.describe Rspec::Generators::ViewGenerator, :type => :generator do
6+
setup_default_destination
117

128
describe 'with default template engine' do
139
it 'generates a spec for the supplied action' do

0 commit comments

Comments
 (0)