Skip to content

Commit

Permalink
Remove rails version checks for controller generator
Browse files Browse the repository at this point in the history
  • Loading branch information
klyonrad committed Dec 15, 2019
1 parent 3f2cf7c commit 764de75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 58 deletions.
8 changes: 2 additions & 6 deletions lib/generators/rspec/controller/controller_generator.rb
Expand Up @@ -7,12 +7,8 @@ class ControllerGenerator < Base
argument :actions, type: :array, default: [], banner: "action action"

class_option :template_engine, desc: "Template engine to generate view files"
if Rails.version.to_f >= 5.0
class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
else
class_option :controller_specs, type: :boolean, default: true, desc: "Generate controller specs"
end
class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
class_option :routing_specs, type: :boolean, default: false, desc: "Generate routing specs"

Expand Down
79 changes: 27 additions & 52 deletions spec/generators/rspec/controller/controller_generator_spec.rb
Expand Up @@ -8,26 +8,22 @@
describe 'request specs' do
subject { file('spec/requests/posts_request_spec.rb') }

if Rails.version.to_f >= 5.0
describe 'generated by default' do
before do
run_generator %w[posts]
end
describe 'generated by default' do
before do
run_generator %w[posts]
end

describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) }
end
describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) }
end
end

describe 'skipped with a flag' do
before do
run_generator %w[posts --no-request_specs]
end
it { is_expected.not_to exist }
describe 'skipped with a flag' do
before do
run_generator %w[posts --no-request_specs]
end
else
it { is_expected.not_to exist }
end
end
Expand Down Expand Up @@ -137,48 +133,27 @@
describe 'controller specs' do
subject { file('spec/controllers/posts_controller_spec.rb') }

if Rails.version.to_f < 5.0
describe 'generated by default' do
before do
run_generator %w[posts]
end

describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) }
end
end
describe 'are not generated' do
it { is_expected.not_to exist }
end

describe 'skipped with a flag' do
before do
run_generator %w[posts --no-controller-specs]
end
it { is_expected.not_to exist }
end
else
describe 'are not generated' do
it { is_expected.not_to exist }
describe 'with --controller-specs flag' do
before do
run_generator %w[posts --controller-specs]
end

describe 'with --controller-specs flag' do
before do
run_generator %w[posts --controller-specs]
end

describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) }
end
describe 'the spec' do
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) }
end
end

describe 'with --no-controller_specs flag' do
before do
run_generator %w[posts --no-controller-specs]
end
it { is_expected.not_to exist }
describe 'with --no-controller_specs flag' do
before do
run_generator %w[posts --no-controller-specs]
end
it { is_expected.not_to exist }
end
end
end

0 comments on commit 764de75

Please sign in to comment.