Sha256: 2f81bfd0a1ceaeac3912af6a86f32dd4303e18b002ff5bd24b5824cbcd4d2ae1

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module RailsBestPractices
  module Reviews
    describe UseParenthesesInMethodDefReview do
      let(:runner) { Core::Runner.new(reviews: described_class.new) }

      it 'finds missing parentheses' do
        content = <<-EOF
        class PostsController < ApplicationController
          def edit foo, bar
          end
        end
        EOF
        runner.review('app/controllers/posts_controller.rb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq(
          'app/controllers/posts_controller.rb:2 - use parentheses around parameters in method definitions'
        )
      end
      it 'finds parentheses with no error' do
        content = <<-EOF
        class PostsController < ApplicationController
          def edit(foo, bar)
          end
        end
        EOF
        runner.review('app/controllers/posts_controller.rb', content)
        expect(runner.errors.size).to eq(0)
      end
      it 'does not throw an error without parameters' do
        content = <<-EOF
        class PostsController < ApplicationController
          def edit
          end
        end
        EOF
        runner.review('app/controllers/posts_controller.rb', content)
        expect(runner.errors.size).to eq(0)
      end

      it 'does not check ignored files' do
        runner = Core::Runner.new(reviews: described_class.new(ignored_files: /posts_controller/))
        content = <<-EOF
        class PostsController < ApplicationController
          def edit foo, bar
          end
        end
        EOF
        runner.review('app/controllers/posts_controller.rb', content)
        expect(runner.errors.size).to eq(0)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb
rails_best_practices-1.23.1 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb
rails_best_practices-1.23.0 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb
rails_best_practices-1.22.1 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb
rails_best_practices-1.22.0 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb
rails_best_practices-1.21.0 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb
rails_best_practices-1.20.1 spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb