Skip to content

Commit 955a99c

Browse files
Sam Phippenbenoittgt
authored andcommitted
Gets rubocop working on modern rubocops and rubies.
1 parent 36c6be5 commit 955a99c

17 files changed

+59
-20
lines changed

.rubocop.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,29 @@ PerlBackrefs:
4343
# We probably can refactor the backref out, but for now excluding it since
4444
# we can't use named matches in 1.8.7
4545
- lib/generators/rspec/scaffold/scaffold_generator.rb
46+
47+
Style/AccessModifierDeclarations:
48+
Enabled: false
49+
50+
51+
Naming/MemoizedInstanceVariableName:
52+
Enabled: false
53+
54+
Naming/UncommunicativeMethodParamName:
55+
Enabled: false
56+
57+
Metrics/PerceivedComplexity:
58+
Enabled: false
59+
60+
Metrics/BlockLength:
61+
Enabled: false
62+
63+
Lint/AssignmentInCondition:
64+
Enabled: false
65+
66+
Lint/EmptyExpression:
67+
Enabled: false
68+
69+
Layout/AlignHash:
70+
Enabled: false
71+

.rubocop_rspec_base.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CaseEquality:
2222
Enabled: false
2323

2424
# Warns when the class is excessively long.
25-
ClassLength:
25+
Metrics/ClassLength:
2626
Max: 100
2727

2828
CollectionMethods:
@@ -66,7 +66,7 @@ LineLength:
6666
Max: 100
6767

6868
# Over time we'd like to get this down, but this is what we're at now.
69-
MethodLength:
69+
Metrics/MethodLength:
7070
Max: 15
7171

7272
# Who cares what we call the argument for binary operator methods?
@@ -115,7 +115,10 @@ StringLiterals:
115115
Style/SpecialGlobalVars:
116116
Enabled: false
117117

118-
Style/TrailingCommaInLiteral:
118+
Style/TrailingCommaInArrayLiteral:
119+
Enabled: false
120+
121+
Style/TrailingCommaInHashLiteral:
119122
Enabled: false
120123

121124
Style/TrailingCommaInArguments:
@@ -162,7 +165,10 @@ Style/IfUnlessModifier:
162165
Style/IfUnlessModifierOfIfUnless:
163166
Enabled: false
164167

165-
Style/MethodMissing:
168+
Style/MethodMissingSuper:
169+
Enabled: false
170+
171+
Style/MissingRespondToMissing:
166172
Enabled: false
167173

168174
Style/MixinUsage:
@@ -243,11 +249,6 @@ Style/StderrPuts:
243249
Style/TernaryParentheses:
244250
Enabled: false
245251

246-
# This could likely be enabled, but it had a false positive on rspec-mocks
247-
# (suggested change was not behaviour preserving) so I don't trust it.
248-
Performance/HashEachMethods:
249-
Enabled: false
250-
251252
Naming/HeredocDelimiterNaming:
252253
Enabled: false
253254

@@ -307,3 +308,6 @@ Style/TrailingUnderscoreVariable:
307308

308309
Layout/EmptyLinesAroundAccessModifier:
309310
Enabled: false
311+
312+
Metrics/AbcSize:
313+
Enabled: false

Gemfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ else
7878
gem "rubyzip", '>= 1.2.2'
7979
end
8080

81-
if RUBY_VERSION >= '2.0.0' && RUBY_VERSION < '2.2.0'
82-
# our current rubocop version doesn't support the json version required by Ruby 2.4
83-
# our rails rubocop setup only supports 2.0 and 2.1
84-
gem 'rubocop', "~> 0.23.0"
85-
end
81+
gem 'rubocop'
8682

8783
custom_gemfile = File.expand_path("../Gemfile-custom", __FILE__)
8884
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)

lib/generators/rspec/mailer/mailer_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def generate_fixtures_files
2020

2121
def generate_preview_files
2222
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
23+
2324
template "preview.rb", File.join("spec/mailers/previews", class_path, "#{file_name}_preview.rb")
2425
end
2526
end

lib/generators/rspec/model/model_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def create_model_spec
2323

2424
def create_fixture_file
2525
return unless missing_fixture_replacement?
26+
2627
template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
2728
end
2829

lib/generators/rspec/request/request_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 RequestGenerator < IntegrationGenerator
7-
source_paths << File.expand_path("../../integration/templates", __FILE__)
7+
source_paths << File.expand_path('../integration/templates', __dir__)
88
end
99
end
1010
end

lib/generators/rspec/scaffold/scaffold_generator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Generators
66
# @private
77
class ScaffoldGenerator < Base
88
include ::Rails::Generators::ResourceHelpers
9-
source_paths << File.expand_path("../../helper/templates", __FILE__)
9+
source_paths << File.expand_path('../helper/templates', __dir__)
1010
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
1111

1212
class_option :orm, :desc => "ORM used to generate the controller"
@@ -74,12 +74,14 @@ def copy_view(view)
7474
# support for namespaced-resources
7575
def ns_file_name
7676
return file_name if ns_parts.empty?
77+
7778
"#{ns_prefix.map(&:underscore).join('/')}_#{ns_suffix.singularize.underscore}"
7879
end
7980

8081
# support for namespaced-resources
8182
def ns_table_name
8283
return table_name if ns_parts.empty?
84+
8385
"#{ns_prefix.map(&:underscore).join('/')}/#{ns_suffix.tableize}"
8486
end
8587

lib/rspec-rails.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Railtie < ::Rails::Railtie
3939

4040
def setup_preview_path(app)
4141
return unless supports_action_mailer_previews?(app.config)
42+
4243
options = app.config.action_mailer
4344
config_default_preview_path(options) if config_preview_path?(options)
4445
end
@@ -57,6 +58,7 @@ def config_preview_path?(options)
5758

5859
def config_default_preview_path(options)
5960
return unless options.preview_path.blank?
61+
6062
options.preview_path = "#{::Rails.root}/spec/mailers/previews"
6163
end
6264

lib/rspec/rails/adapters.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def assertion_instance
103103
assertion_modules.each do |mod|
104104
mod.public_instance_methods.each do |method|
105105
next if method == :method_missing || method == "method_missing"
106+
106107
define_method(method.to_sym) do |*args, &block|
107108
assertion_instance.send(method.to_sym, *args, &block)
108109
end

lib/rspec/rails/example/helper_example_group.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def determine_constant_from_test_name(_ignore)
1919
else
2020
def determine_default_helper_class(_ignore)
2121
return unless Module === described_class && !(Class === described_class)
22+
2223
described_class
2324
end
2425
end

lib/rspec/rails/example/system_example_group.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def app
4949
begin
5050
require 'capybara'
5151
require 'action_dispatch/system_test_case'
52-
# rubocop:disable Lint/HandleExceptions
5352
rescue LoadError => e
5453
# rubocop:enable Lint/HandleExceptions
5554
abort """

lib/rspec/rails/feature_check.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ module RSpec
22
module Rails
33
# @private
44
# Disable some cops until https://github.com/bbatsov/rubocop/issues/1310
5-
# rubocop:disable Style/IndentationConsistency
65
module FeatureCheck
7-
# rubocop:disable Style/IndentationWidth
86
module_function
97
# rubocop:enable Style/IndentationWidth
108

lib/rspec/rails/matchers/active_job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def have_been_enqueued
310310
# @private
311311
def check_active_job_adapter
312312
return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
313+
313314
raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`"
314315
end
315316
end

lib/rspec/rails/matchers/base_matcher.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def self.underscore(camel_cased_word)
114114

115115
def assert_ivars(*expected_ivars)
116116
return unless (expected_ivars - present_ivars).any?
117+
117118
ivar_list = RSpec::Matchers::EnglishPhrasing.list(expected_ivars)
118119
raise "#{self.class.name} needs to supply#{ivar_list}"
119120
end

lib/rspec/rails/matchers/have_enqueued_mail.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Rails
66
module Matchers
77
# Matcher class for `have_enqueued_mail`. Should not be instantiated directly.
88
#
9-
# rubocop: disable Style/ClassLength
109
# @private
1110
# @see RSpec::Rails::Matchers#have_enqueued_mail
1211
class HaveEnqueuedMail < ActiveJob::HaveEnqueuedJob
@@ -33,6 +32,7 @@ def with(*args, &block)
3332

3433
def matches?(block)
3534
raise ArgumentError, 'have_enqueued_mail and enqueue_mail only work with block arguments' unless block.respond_to?(:call)
35+
3636
check_active_job_adapter
3737
super
3838
end
@@ -89,6 +89,7 @@ def yield_mail_args(block)
8989

9090
def check_active_job_adapter
9191
return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter
92+
9293
raise StandardError, "To use HaveEnqueuedMail matcher set `ActiveJob::Base.queue_adapter = :test`"
9394
end
9495

lib/rspec/rails/matchers/have_http_status.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def as_test_response(obj)
5959
# `@invalid_response` is present, `nil` otherwise
6060
def invalid_response_type_message
6161
return unless @invalid_response
62+
6263
"expected a response object, but an instance of " \
6364
"#{@invalid_response.class} was received"
6465
end
@@ -174,6 +175,7 @@ def failure_message_when_negated
174175
# @return [Symbol] representing the actual http numeric code
175176
def actual_status
176177
return unless actual
178+
177179
@actual_status ||= compute_status_from(actual)
178180
end
179181

@@ -254,6 +256,7 @@ def initialize(type)
254256
unless self.class.valid_statuses.include?(type)
255257
raise ArgumentError, "Invalid generic HTTP status: #{type.inspect}"
256258
end
259+
257260
@expected = type
258261
@actual = nil
259262
@invalid_response = nil
@@ -374,6 +377,7 @@ def type_codes
374377
# @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb `Rack::Utils::SYMBOL_TO_STATUS_CODE`
375378
def have_http_status(target)
376379
raise ArgumentError, "Invalid HTTP status: nil" unless target
380+
377381
HaveHttpStatus.matcher_for_status(target)
378382
end
379383
end

lib/rspec/rails/matchers/have_rendered.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def matches?(*)
2929
def check_redirect
3030
response = @scope.response
3131
return unless response.respond_to?(:redirect?) && response.redirect?
32+
3233
@redirect_is = @scope.send(:normalize_argument_to_redirection, response.location)
3334
end
3435

0 commit comments

Comments
 (0)