Skip to content

Commit

Permalink
Update existing generator specs.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cupakromer committed May 25, 2015
1 parent 66bb6a7 commit 5b10339
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 64 deletions.
10 changes: 3 additions & 7 deletions spec/generators/rspec/controller/controller_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/controller/controller_generator'
require 'support/generators'

describe Rspec::Generators::ControllerGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::ControllerGenerator, :type => :generator do
setup_default_destination

describe 'controller specs' do
subject { file('spec/controllers/posts_controller_spec.rb') }
Expand Down
10 changes: 3 additions & 7 deletions spec/generators/rspec/feature/feature_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by rails
require 'generators/rspec/feature/feature_generator'
require 'support/generators'

describe Rspec::Generators::FeatureGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path('../../../../../tmp', __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::FeatureGenerator, :type => :generator do
setup_default_destination

describe 'feature specs' do
describe 'are generated independently from the command line' do
Expand Down
10 changes: 3 additions & 7 deletions spec/generators/rspec/helper/helper_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/helper/helper_generator'
require 'support/generators'

describe Rspec::Generators::HelperGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::HelperGenerator, :type => :generator do
setup_default_destination

subject { file('spec/helpers/posts_helper_spec.rb') }
describe 'generated by default' do
Expand Down
7 changes: 3 additions & 4 deletions spec/generators/rspec/install/install_generator_spec.rb
@@ -1,9 +1,8 @@
require 'spec_helper'
# Generators are not automatically loaded by Rails
require 'generators/rspec/install/install_generator'
require 'support/generators'

RSpec.describe Rspec::Generators::InstallGenerator, :type => :generator do
destination File.expand_path("../../../../../tmp", __FILE__)

def use_active_record_migration
match(/ActiveRecord::Migration\./m)
end
Expand Down Expand Up @@ -32,7 +31,7 @@ def use_transactional_fixtures
match(/config\.use_transactional_fixtures/m)
end

before { prepare_destination }
setup_default_destination

let(:rails_helper) { content_for('spec/rails_helper.rb') }
let(:spec_helper) { content_for('spec/spec_helper.rb') }
Expand Down
8 changes: 2 additions & 6 deletions spec/generators/rspec/job/job_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/job/job_generator'
require 'support/generators'

RSpec.describe Rspec::Generators::JobGenerator, :type => :generator, :skip => !RSpec::Rails::FeatureCheck.has_active_job? do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path('../../../../../tmp', __FILE__)

before { prepare_destination }
setup_default_destination

describe 'the generated files' do
before { run_generator %w(user) }
Expand Down
10 changes: 3 additions & 7 deletions spec/generators/rspec/mailer/mailer_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/mailer/mailer_generator'
require 'support/generators'

describe Rspec::Generators::MailerGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::MailerGenerator, :type => :generator do
setup_default_destination

describe 'mailer spec' do
subject { file('spec/mailers/posts_spec.rb') }
Expand Down
10 changes: 3 additions & 7 deletions spec/generators/rspec/model/model_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/model/model_generator'
require 'support/generators'

describe Rspec::Generators::ModelGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::ModelGenerator, :type => :generator do
setup_default_destination

it 'runs both the model and fixture tasks' do
gen = generator %w(posts)
Expand Down
10 changes: 4 additions & 6 deletions spec/generators/rspec/observer/observer_generator_spec.rb
@@ -1,15 +1,13 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/observer/observer_generator'
require 'support/generators'

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

subject { file('spec/models/posts_observer_spec.rb') }

before do
prepare_destination
run_generator %w(posts)
end

Expand Down
10 changes: 4 additions & 6 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
@@ -1,11 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/scaffold/scaffold_generator'
require 'support/generators'

describe Rspec::Generators::ScaffoldGenerator, :type => :generator do
destination File.expand_path("../../../../../tmp", __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::ScaffoldGenerator, :type => :generator do
setup_default_destination

describe 'standard controller spec' do
subject { file('spec/controllers/posts_controller_spec.rb') }
Expand Down
10 changes: 3 additions & 7 deletions spec/generators/rspec/view/view_generator_spec.rb
@@ -1,13 +1,9 @@
require 'spec_helper'

# Generators are not automatically loaded by Rails
require 'generators/rspec/view/view_generator'
require 'support/generators'

describe Rspec::Generators::ViewGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)

before { prepare_destination }
RSpec.describe Rspec::Generators::ViewGenerator, :type => :generator do
setup_default_destination

describe 'with default template engine' do
it 'generates a spec for the supplied action' do
Expand Down

0 comments on commit 5b10339

Please sign in to comment.