source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/heredoc_delimiter_naming_spec.rb | Ruby | mit | 12,856 | master | 4,752 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::HeredocDelimiterNaming, :config do
let(:cop_config) { { 'ForbiddenDelimiters' => %w[END] } }
context 'with an interpolated heredoc' do
it 'registers an offense with a non-meaningful delimiter' do
expect_offense(<<~RUBY)
<<-END
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/binary_operator_parameter_name_spec.rb | Ruby | mit | 12,856 | master | 3,666 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::BinaryOperatorParameterName, :config do
it 'registers an offense and corrects for `#+` when argument is not named other' do
expect_offense(<<~RUBY)
def +(foo); end
^^^ When defining the `+` operator, name its argument `other`.
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/file_name_spec.rb | Ruby | mit | 12,856 | master | 12,880 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::FileName, :config do
let(:config) do
RuboCop::Config.new(
{ 'AllCops' => { 'Include' => includes },
described_class.badge.to_s => cop_config },
'/some/.rubocop.yml'
)
end
let(:cop_config) do # matches default.yml
{... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/memoized_instance_variable_name_spec.rb | Ruby | mit | 12,856 | master | 33,341 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::MemoizedInstanceVariableName, :config do
it 'does not register an offense when or-assignment-based memoization is used outside a method definition' do
expect_no_offenses(<<~RUBY)
@x ||= y
RUBY
end
context 'with default EnforcedStyl... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/heredoc_delimiter_case_spec.rb | Ruby | mit | 12,856 | master | 8,353 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::HeredocDelimiterCase, :config do
context 'when enforced style is uppercase' do
let(:cop_config) do
{
'SupportedStyles' => %w[uppercase lowercase],
'EnforcedStyle' => 'uppercase'
}
end
context 'with an interpol... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/ascii_identifiers_spec.rb | Ruby | mit | 12,856 | master | 1,507 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::AsciiIdentifiers, :config do
shared_examples 'checks identifiers' do
it 'registers an offense for a variable name with non-ascii chars' do
expect_offense(<<~RUBY)
älg = 1
^ Use only ascii symbols in identifiers.
RUBY
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/accessor_method_name_spec.rb | Ruby | mit | 12,856 | master | 4,338 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::AccessorMethodName, :config do
it 'registers an offense for method get_something with no args' do
expect_offense(<<~RUBY)
def get_something
^^^^^^^^^^^^^ Do not prefix reader method names with `get_`.
# ...
end
R... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/block_forwarding_spec.rb | Ruby | mit | 12,856 | master | 14,730 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::BlockForwarding, :config do
context 'when `EnforcedStyle: anonymous' do
let(:cop_config) { { 'EnforcedStyle' => 'anonymous' } }
context 'Ruby >= 3.1', :ruby31 do
it 'registers and corrects an offense when using explicit block forwardin... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/predicate_prefix_spec.rb | Ruby | mit | 12,856 | master | 6,122 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::PredicatePrefix, :config do
context 'with restricted prefixes' do
let(:cop_config) { { 'NamePrefix' => %w[has_ is_], 'ForbiddenPrefixes' => %w[has_ is_] } }
it 'registers an offense when method name starts with "is"' do
expect_offense(... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/rescued_exceptions_variable_name_spec.rb | Ruby | mit | 12,856 | master | 15,595 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::RescuedExceptionsVariableName, :config do
context 'with default config' do
context 'with explicit rescue' do
context 'with `Exception` variable' do
it 'registers an offense when using `exc`' do
expect_offense(<<~RUBY)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/constant_name_spec.rb | Ruby | mit | 12,856 | master | 4,319 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::ConstantName, :config do
it 'registers an offense for camel case in const name' do
expect_offense(<<~RUBY)
TopCase = 5
^^^^^^^ Use SCREAMING_SNAKE_CASE for constants.
RUBY
end
it 'registers an offense for camel case in const ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/naming/class_and_module_camel_case_spec.rb | Ruby | mit | 12,856 | master | 1,311 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Naming::ClassAndModuleCamelCase, :config do
it 'registers an offense for underscore in class and module name' do
expect_offense(<<~RUBY)
class My_Class
^^^^^^^^ Use CamelCase for classes and modules.
end
module My_Module
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/variable_force/reference_spec.rb | Ruby | mit | 12,856 | master | 453 | # frozen_string_literal: true
require 'rubocop/ast/sexp'
RSpec.describe RuboCop::Cop::VariableForce::Reference do
include RuboCop::AST::Sexp
describe '.new' do
context 'when non variable reference node is passed' do
it 'raises error' do
node = s(:def)
scope = RuboCop::Cop::VariableForce... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/variable_force/variable_spec.rb | Ruby | mit | 12,856 | master | 1,440 | # frozen_string_literal: true
require 'rubocop/ast/sexp'
RSpec.describe RuboCop::Cop::VariableForce::Variable do
include RuboCop::AST::Sexp
describe '.new' do
context 'when non variable declaration node is passed' do
it 'raises error' do
name = :foo
declaration_node = s(:def)
sc... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/variable_force/variable_table_spec.rb | Ruby | mit | 12,856 | master | 8,109 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::VariableForce::VariableTable do
include RuboCop::AST::Sexp
subject(:variable_table) { described_class.new }
describe '#push_scope' do
it 'returns pushed scope object' do
node = s(:def)
scope = variable_table.push_scope(node)
expec... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/variable_force/assignment_spec.rb | Ruby | mit | 12,856 | master | 7,394 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::VariableForce::Assignment do
include RuboCop::AST::Sexp
let(:ast) { RuboCop::ProcessedSource.new(source, ruby_version, parser_engine: parser_engine).ast }
let(:source) do
<<~RUBY
class SomeClass
def some_method(flag)
puts 'H... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/variable_force/scope_spec.rb | Ruby | mit | 12,856 | master | 8,043 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::VariableForce::Scope do
include RuboCop::AST::Sexp
subject(:scope) { described_class.new(scope_node) }
let(:ast) { RuboCop::ProcessedSource.new(source, ruby_version, parser_engine: parser_engine).ast }
let(:scope_node) { ast.each_node(scope_node_typ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/gem_comment_spec.rb | Ruby | mit | 12,856 | master | 8,175 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::GemComment, :config do
let(:cop_config) do
{
'Include' => ['**/Gemfile'],
'IgnoredGems' => ['rake'],
'OnlyFor' => []
}
end
context 'when investigating Ruby files' do
it 'does not register any offenses' do
exp... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/gem_version_spec.rb | Ruby | mit | 12,856 | master | 2,691 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::GemVersion, :config do
context 'when EnforcedStyle is set to required (default)' do
let(:cop_config) do
{
'EnforcedStyle' => 'required',
'AllowedGems' => ['rspec']
}
end
it 'flags gems that do not specify a v... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/gem_filename_spec.rb | Ruby | mit | 12,856 | master | 4,216 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::GemFilename, :config do
shared_examples 'invalid gem file' do |message|
it 'registers an offense' do
offenses = _investigate(cop, processed_source)
expect(offenses.size).to eq(1)
expect(offenses.first.message).to eq(message)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/duplicated_group_spec.rb | Ruby | mit | 12,856 | master | 9,209 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::DuplicatedGroup, :config do
let(:cop_config) { { 'Include' => ['**/Gemfile'] } }
context 'when investigating Ruby files' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY, 'foo.rb')
# cop will not read these c... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/ordered_gems_spec.rb | Ruby | mit | 12,856 | master | 7,313 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::OrderedGems, :config do
let(:cop_config) { { 'TreatCommentsAsGroupSeparators' => treat_comments_as_group_separators } }
let(:treat_comments_as_group_separators) { false }
context 'When gems are alphabetically sorted' do
it 'does not registe... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/duplicated_gem_spec.rb | Ruby | mit | 12,856 | master | 3,706 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::DuplicatedGem, :config do
let(:cop_config) { { 'Include' => ['**/Gemfile'] } }
context 'when investigating Ruby files' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY, 'foo.rb')
# cop will not read these con... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/bundler/insecure_protocol_source_spec.rb | Ruby | mit | 12,856 | master | 1,833 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Bundler::InsecureProtocolSource, :config do
it 'registers an offense when using `source :gemcutter`' do
expect_offense(<<~RUBY)
source :gemcutter
^^^^^^^^^^ The source `:gemcutter` is deprecated [...]
RUBY
expect_correction(<<... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/open_spec.rb | Ruby | mit | 12,856 | master | 2,699 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::Open, :config do
it 'registers an offense for open' do
expect_offense(<<~RUBY)
open(something)
^^^^ The use of `Kernel#open` is a serious security risk.
RUBY
end
it 'registers an offense for open with mode argument' do
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/io_methods_spec.rb | Ruby | mit | 12,856 | master | 3,859 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::IoMethods, :config do
shared_examples 'offense' do |current, preferred, method_name|
it "registers and corrects an offense when using `#{method_name}`" do
expect_offense(<<~RUBY, current: current)
#{current}
^{current} `Fi... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/marshal_load_spec.rb | Ruby | mit | 12,856 | master | 1,320 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::MarshalLoad, :config do
it 'registers an offense for using Marshal.load' do
expect_offense(<<~RUBY)
Marshal.load('{}')
^^^^ Avoid using `Marshal.load`.
::Marshal.load('{}')
^^^^ Avoid using `Marshal.loa... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/compound_hash_spec.rb | Ruby | mit | 12,856 | master | 6,493 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::CompoundHash, :config do
it 'registers an offense when using XOR operator in the implementation of the hash method' do
expect_offense(<<~RUBY)
def hash
1.hash ^ 2.hash ^ 3.hash
^^^^^^^^^^^^^^^^^^^^^^^^ Use `[...].hash` ins... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/yaml_load_spec.rb | Ruby | mit | 12,856 | master | 1,667 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::YAMLLoad, :config do
it 'does not register an offense for YAML.dump' do
expect_no_offenses(<<~RUBY)
YAML.dump("foo")
::YAML.dump("foo")
Module::YAML.dump("foo")
RUBY
end
it 'does not register an offense for YAML.load ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/json_load_spec.rb | Ruby | mit | 12,856 | master | 2,317 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::JSONLoad, :config do
it 'registers an offense and corrects JSON.load' do
expect_offense(<<~RUBY)
JSON.load(arg)
^^^^ Prefer `JSON.parse` over `JSON.load`.
::JSON.load(arg)
^^^^ Prefer `JSON.parse` over `JSON.... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/security/eval_spec.rb | Ruby | mit | 12,856 | master | 2,383 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Security::Eval, :config do
it 'registers an offense for eval as function' do
expect_offense(<<~RUBY)
eval(something)
^^^^ The use of `eval` is a serious security risk.
RUBY
end
it 'registers an offense for eval as command' do
exp... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/while_until_modifier_spec.rb | Ruby | mit | 12,856 | master | 2,882 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::WhileUntilModifier, :config do
it_behaves_like 'condition modifier cop', :while
it_behaves_like 'condition modifier cop', :until
context 'when the body is a modifier if' do
it 'does not register an offense for while' do
expect_no_offens... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/min_max_spec.rb | Ruby | mit | 12,856 | master | 2,771 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MinMax, :config do
context 'with an array literal containing calls to `#min` and `#max`' do
context 'when the expression stands alone' do
it 'registers an offense if the receivers match' do
expect_offense(<<~RUBY)
[foo.min,... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/case_equality_spec.rb | Ruby | mit | 12,856 | master | 3,017 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CaseEquality, :config do
shared_examples 'offenses' do
it 'does not fail when the receiver is implicit' do
expect_no_offenses(<<~RUBY)
puts "No offense"
RUBY
end
it 'does not register an offense for === when the receiv... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/empty_block_parameter_spec.rb | Ruby | mit | 12,856 | master | 1,897 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EmptyBlockParameter, :config do
it 'registers an offense for an empty block parameter with do-end style' do
expect_offense(<<~RUBY)
a do ||
^^ Omit pipes for the empty block parameters.
end
RUBY
expect_correction(<<... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trailing_comma_in_block_args_spec.rb | Ruby | mit | 12,856 | master | 4,207 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrailingCommaInBlockArgs, :config do
context 'curly brace block format' do
it 'registers an offense when a trailing comma is not needed' do
expect_offense(<<~RUBY)
test { |a, b,| a + b }
^ Useless trailing comma p... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/sole_nested_conditional_spec.rb | Ruby | mit | 12,856 | master | 29,745 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SoleNestedConditional, :config do
let(:cop_config) { { 'AllowModifier' => false } }
it 'registers an offense and corrects when using nested `if` within `if`' do
expect_offense(<<~RUBY)
if foo
if bar
^^ Consider merging nes... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb | Ruby | mit | 12,856 | master | 37,730 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MethodCallWithArgsParentheses, :config do
shared_examples 'endless methods' do |omit: false|
context 'endless methods', :ruby30 do
context 'with arguments' do
it 'requires method calls to have parens' do
expect_no_offenses(... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/case_like_if_spec.rb | Ruby | mit | 12,856 | master | 10,419 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CaseLikeIf, :config do
let(:cop_config) { { 'MinBranchesCount' => 2 } }
it 'registers an offense and corrects when using `===`' do
expect_offense(<<~RUBY)
if Integer === x
^^^^^^^^^^^^^^^^ Convert `if-elsif` to `case-when`.
el... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_fetch_block_spec.rb | Ruby | mit | 12,856 | master | 4,690 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantFetchBlock, :config do
context 'with SafeForConstants: true' do
let(:config) do
RuboCop::Config.new('Style/RedundantFetchBlock' => { 'SafeForConstants' => true })
end
it 'registers an offense and corrects when using `#fetch... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_array_flatten_spec.rb | Ruby | mit | 12,856 | master | 1,911 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantArrayFlatten, :config do
it 'registers an offense for `x.flatten.join`' do
expect_offense(<<~RUBY)
x.flatten.join
^^^^^^^^ Remove the redundant `flatten`.
RUBY
expect_correction(<<~RUBY)
x.join
RUBY
end
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/numbered_parameters_spec.rb | Ruby | mit | 12,856 | master | 1,344 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NumberedParameters, :config do
context '>= Ruby 2.7', :ruby27 do
context 'EnforcedStyle: allow_single_line' do
let(:cop_config) { { 'EnforcedStyle' => 'allow_single_line' } }
it 'registers an offense when using numbered parameters wit... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/method_def_parentheses_spec.rb | Ruby | mit | 12,856 | master | 8,518 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MethodDefParentheses, :config do
shared_examples 'no parentheses' do
# common to require_no_parentheses and
# require_no_parentheses_except_multiline
it 'reports an offense for def with parameters with parens' do
expect_offense(<<~RU... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/infinite_loop_spec.rb | Ruby | mit | 12,856 | master | 7,408 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::InfiniteLoop, :config do
let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) }
%w(1 2.0 [1] {}).each do |lit|
it "registers an offense for a while loop with #{lit} as condition" do
expect_offense(<<~RUBY)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/optional_boolean_parameter_spec.rb | Ruby | mit | 12,856 | master | 2,454 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::OptionalBooleanParameter, :config do
let(:cop_config) { { 'AllowedMethods' => [] } }
it 'registers an offense when defining method with optional boolean arg' do
expect_offense(<<~RUBY)
def some_method(bar = false)
^^... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/numbered_parameters_limit_spec.rb | Ruby | mit | 12,856 | master | 3,130 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NumberedParametersLimit, :config do
include_context 'with exclude limit tracking'
let(:cop_config) { { 'Max' => max } }
let(:max) { 2 }
context 'with Ruby >= 2.7', :ruby27 do
it 'does not register an offense for a normal block with too man... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/float_division_spec.rb | Ruby | mit | 12,856 | master | 6,512 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FloatDivision, :config do
context 'EnforcedStyle is left_coerce' do
let(:cop_config) { { 'EnforcedStyle' => 'left_coerce' } }
it 'registers an offense and corrects for right coerce' do
expect_offense(<<~RUBY)
a / b.to_f
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/multiline_method_signature_spec.rb | Ruby | mit | 12,856 | master | 6,904 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MultilineMethodSignature, :config do
context 'when arguments span a single line' do
context 'when defining an instance method' do
it 'registers an offense and corrects when closing paren is on the following line' do
expect_offense(<<... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_transform_keys_spec.rb | Ruby | mit | 12,856 | master | 11,530 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashTransformKeys, :config do
context 'when using Ruby 2.5 or newer', :ruby25 do
context 'with inline block' do
it 'flags each_with_object when transform_keys could be used' do
expect_offense(<<~RUBY)
{a: 1, b: 2}.each_with... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/expand_path_arguments_spec.rb | Ruby | mit | 12,856 | master | 4,773 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ExpandPathArguments, :config do
it "registers an offense when using `File.expand_path('..', __FILE__)`" do
expect_offense(<<~RUBY)
File.expand_path('..', __FILE__)
^^^^^^^^^^^ Use `expand_path(__dir__)` instead of `expand_path('..... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb | Ruby | mit | 12,856 | master | 2,106 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MethodCalledOnDoEndBlock, :config do
context 'with a multi-line do..end block' do
it 'registers an offense for a chained call' do
expect_offense(<<~RUBY)
a do
b
end.c
^^^^^ Avoid chaining a method call on a ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/swap_values_spec.rb | Ruby | mit | 12,856 | master | 1,930 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SwapValues, :config do
shared_examples 'verbosely swapping' do |type, x, y, correction|
it "registers an offense and corrects when verbosely swapping #{type} variables" do
expect_offense(<<~RUBY, x: x)
tmp = %{x}
^^^^^^^{x} R... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/file_write_spec.rb | Ruby | mit | 12,856 | master | 3,066 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FileWrite, :config do
it 'does not register an offense for the `File.open` with multiline write block when not writing to the block variable' do
expect_no_offenses(<<~RUBY)
File.open(filename, 'w') do |f|
something.write(content)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_regexp_character_class_spec.rb | Ruby | mit | 12,856 | master | 14,971 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantRegexpCharacterClass, :config do
context 'with a character class containing a single character' do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY)
foo = /[a]/
^^^ Redundant single-element cha... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_min_max_by_spec.rb | Ruby | mit | 12,856 | master | 4,204 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantMinMaxBy, :config do
shared_examples 'redundant method' do |method, replacement|
it "autocorrects array.#{method} { |x| x }" do
expect_offense(<<~RUBY, method: method, replacement: replacement)
array.#{method} { |x| x }
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/if_inside_else_spec.rb | Ruby | mit | 12,856 | master | 8,207 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::IfInsideElse, :config do
let(:cop_config) { { 'AllowIfModifier' => false } }
it 'catches an if node nested inside an else' do
expect_offense(<<~RUBY)
if a
blah
else
if b
^^ Convert `if` nested inside `else` t... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/endless_method_spec.rb | Ruby | mit | 12,856 | master | 20,232 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EndlessMethod, :config do
context 'Ruby >= 3.0', :ruby30 do
let(:other_cops) do
{
'Layout/LineLength' => {
'Enabled' => line_length_enabled,
'Max' => 80
}
}
end
let(:line_length_enabled) { tr... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/select_by_range_spec.rb | Ruby | mit | 12,856 | master | 17,980 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SelectByRange, :config do
shared_examples 'range check' do |method, correction|
message = "Prefer `#{correction}` to `#{method}` with a range check."
actual_correction = if correction.include?('(...)')
correction.sub(... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/slicing_with_range_spec.rb | Ruby | mit | 12,856 | master | 6,342 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SlicingWithRange, :config do
context '<= Ruby 2.5', :ruby25, unsupported_on: :prism do
it 'reports no offense for array slicing end with `-1`' do
expect_no_offenses(<<~RUBY)
ary[1..-1]
RUBY
end
end
context '>= Ruby 2.6... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/array_intersect_with_single_element_spec.rb | Ruby | mit | 12,856 | master | 1,182 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ArrayIntersectWithSingleElement, :config do
context 'with `include?(element)`' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
array.include?(element)
RUBY
end
end
context 'with `intersect?([element... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/file_touch_spec.rb | Ruby | mit | 12,856 | master | 943 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FileTouch, :config do
it 'registers an offense when using `File.open` in append mode with empty block' do
expect_offense(<<~RUBY)
File.open(filename, 'a') {}
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `FileUtils.touch(filename)` instead of `File.... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/class_methods_definitions_spec.rb | Ruby | mit | 12,856 | master | 6,683 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ClassMethodsDefinitions, :config do
context 'when EnforcedStyle is def_self' do
let(:cop_config) { { 'EnforcedStyle' => 'def_self' } }
it 'registers an offense and corrects when defining class methods with `class << self`' do
expect_off... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/concat_array_literals_spec.rb | Ruby | mit | 12,856 | master | 4,130 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ConcatArrayLiterals, :config do
it 'registers an offense when using `concat` with single element array literal argument' do
expect_offense(<<~RUBY)
arr.concat([item])
^^^^^^^^^^^^^^ Use `push(item)` instead of `concat([item])`.
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/colon_method_definition_spec.rb | Ruby | mit | 12,856 | master | 1,167 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ColonMethodDefinition, :config do
it 'accepts a class method defined using .' do
expect_no_offenses(<<~RUBY)
class Foo
def self.bar
something
end
end
RUBY
end
context 'using self' do
it 'registers... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trailing_body_on_method_definition_spec.rb | Ruby | mit | 12,856 | master | 5,130 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrailingBodyOnMethodDefinition, :config do
let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) }
it 'registers an offense when body trails after method definition' do
expect_offense(<<~RUBY)
def some_method; ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/global_std_stream_spec.rb | Ruby | mit | 12,856 | master | 1,713 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::GlobalStdStream, :config do
it 'registers an offense and corrects when using std stream as const' do
expect_offense(<<~RUBY)
STDOUT.puts('hello')
^^^^^^ Use `$stdout` instead of `STDOUT`.
hash = { out: STDOUT, key: value }
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/object_then_spec.rb | Ruby | mit | 12,856 | master | 5,733 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ObjectThen, :config do
context 'EnforcedStyle: then' do
let(:cop_config) { { 'EnforcedStyle' => 'then' } }
it 'does not register an offense for method names other than `then`' do
expect_no_offenses(<<~RUBY)
obj.map { |x| x.foo }... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/map_join_spec.rb | Ruby | mit | 12,856 | master | 4,745 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MapJoin, :config do
%i[map collect].each do |method|
context "with `#{method}(&:to_s).join`" do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY, method: method)
array.#{method}(&:to_s).join(', ')
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/min_max_comparison_spec.rb | Ruby | mit | 12,856 | master | 3,961 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MinMaxComparison, :config do
it 'registers and corrects an offense when using `a > b ? a : b`' do
expect_offense(<<~RUBY)
a > b ? a : b
^^^^^^^^^^^^^ Use `[a, b].max` instead.
RUBY
expect_correction(<<~RUBY)
[a, b].max
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/if_with_boolean_literal_branches_spec.rb | Ruby | mit | 12,856 | master | 16,559 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::IfWithBooleanLiteralBranches, :config do
context 'when condition is a comparison method' do
RuboCop::AST::Node::COMPARISON_OPERATORS.each do |comparison_operator|
it 'registers and corrects an offense when using `if foo == bar` with boolean ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/eval_with_location_spec.rb | Ruby | mit | 12,856 | master | 9,611 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EvalWithLocation, :config do
it 'registers an offense when using `#eval` without any arguments' do
expect_offense(<<~RUBY)
eval <<-CODE
^^^^^^^^^^^^ Pass a binding, `__FILE__`, and `__LINE__` to `eval`.
do_something
CODE
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/format_string_token_spec.rb | Ruby | mit | 12,856 | master | 19,891 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FormatStringToken, :config do
let(:enforced_style) { :annotated }
let(:allowed_methods) { [] }
let(:allowed_patterns) { [] }
let(:mode) { :aggressive }
let(:cop_config) do
{
'EnforcedStyle' => enforced_style,
'SupportedStyles'... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb | Ruby | mit | 12,856 | master | 3,596 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
context 'configured with single quotes preferred' do
let(:cop_config) { { 'EnforcedStyle' => 'single_quotes' } }
it 'registers an offense for double quotes within embedded expression in a string' do
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/symbol_array_spec.rb | Ruby | mit | 12,856 | master | 9,605 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SymbolArray, :config do
before do
# Reset data which is shared by all instances of SymbolArray
described_class.largest_brackets = -Float::INFINITY
end
let(:other_cops) do
{
'Style/PercentLiteralDelimiters' => {
'Preferre... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/single_line_block_params_spec.rb | Ruby | mit | 12,856 | master | 4,041 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SingleLineBlockParams, :config do
let(:cop_config) { { 'Methods' => [{ 'reduce' => %w[a e] }, { 'test' => %w[x y] }] } }
it 'finds wrong argument names in calls with different syntax' do
expect_offense(<<~RUBY)
def m
[0, 1].reduce... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/inverse_methods_spec.rb | Ruby | mit | 12,856 | master | 12,745 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::InverseMethods, :config do
let(:config) do
RuboCop::Config.new(
'Style/InverseMethods' => {
'InverseMethods' => {
any?: :none?,
even?: :odd?,
present?: :blank?,
include?: :exclude?,
:... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/module_member_existence_check_spec.rb | Ruby | mit | 12,856 | master | 5,769 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ModuleMemberExistenceCheck, :config do
shared_examples 'module member inclusion' do |array_returning_method, predicate_method, has_inherit_param = true|
it "registers an offense when using `.#{array_returning_method}.include?(method)`" do
ex... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_each_methods_spec.rb | Ruby | mit | 12,856 | master | 17,432 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashEachMethods, :config do
context 'when node matches a keys#each or values#each' do
context 'when receiver is a send' do
it 'registers an offense autocorrects foo#keys.each to foo#each_key' do
expect_offense(<<~RUBY)
foo.... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/string_concatenation_spec.rb | Ruby | mit | 12,856 | master | 10,866 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::StringConcatenation, :config do
it 'registers an offense and corrects for string concatenation' do
expect_offense(<<~RUBY)
email_with_name = user.name + ' <' + user.email + '>'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Pref... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/single_argument_dig_spec.rb | Ruby | mit | 12,856 | master | 4,536 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SingleArgumentDig, :config do
describe 'dig over literal' do
context 'with single argument' do
it 'registers an offense and corrects unsuitable use of dig' do
expect_offense(<<~RUBY)
{ key: 'value' }.dig(:key)
^^^... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/array_coercion_spec.rb | Ruby | mit | 12,856 | master | 1,320 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ArrayCoercion, :config do
it 'registers an offense and corrects when splatting variable into array' do
expect_offense(<<~RUBY)
[*paths].each { |path| do_something(path) }
^^^^^^^^ Use `Array(paths)` instead of `[*paths]`.
RUBY
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_conversion_spec.rb | Ruby | mit | 12,856 | master | 6,022 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashConversion, :config do
it 'reports an offense for single-argument Hash[]' do
expect_offense(<<~RUBY)
Hash[ary]
^^^^^^^^^ Prefer `ary.to_h` to `Hash[ary]`.
RUBY
expect_correction(<<~RUBY)
ary.to_h
RUBY
end
it... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/file_read_spec.rb | Ruby | mit | 12,856 | master | 3,606 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FileRead, :config do
it 'does not register an offense when not reading from the block variable' do
expect_no_offenses(<<~RUBY)
File.open(filename) do |f|
something_else.read
end
RUBY
end
it 'registers an offense for an... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/nested_parenthesized_calls_spec.rb | Ruby | mit | 12,856 | master | 3,033 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NestedParenthesizedCalls, :config do
let(:config) do
RuboCop::Config.new('Style/NestedParenthesizedCalls' => { 'AllowedMethods' => ['be'] })
end
context 'on a non-parenthesized method call' do
it "doesn't register an offense" do
exp... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_self_assignment_branch_spec.rb | Ruby | mit | 12,856 | master | 6,444 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantSelfAssignmentBranch, :config do
it 'registers and corrects an offense when self-assigning redundant else ternary branch' do
expect_offense(<<~RUBY)
foo = condition ? bar : foo
^^^ Remove the self-assig... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/unpack_first_spec.rb | Ruby | mit | 12,856 | master | 3,153 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::UnpackFirst, :config do
context 'ruby version >= 2.4', :ruby24 do
context 'registers an offense' do
it 'when using `#unpack` with `#first`' do
expect_offense(<<~RUBY)
x.unpack('h*').first
^^^^^^^^^^^^^^^^^^ Use ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/self_assignment_spec.rb | Ruby | mit | 12,856 | master | 1,087 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SelfAssignment, :config do
%i[+ - * ** / % ^ << >> | & || &&].product(['x', '@x', '@@x']).each do |op, var|
it "registers an offense for non-shorthand assignment #{op} and #{var}" do
expect_offense(<<~RUBY, op: op, var: var)
%{var} =... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_syntax_spec.rb | Ruby | mit | 12,856 | master | 58,124 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashSyntax, :config do
context 'configured to enforce ruby19 style' do
context 'with SpaceAroundOperators enabled' do
let(:config) do
RuboCop::Config.new('AllCops' => {
'TargetRubyVersion' => ruby_versio... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_return_spec.rb | Ruby | mit | 12,856 | master | 14,277 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantReturn, :config do
let(:cop_config) { { 'AllowMultipleReturnValues' => false } }
it 'reports an offense for def with only a return' do
expect_offense(<<~RUBY)
def func
return something
^^^^^^ Redundant `return` de... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/proc_spec.rb | Ruby | mit | 12,856 | master | 1,396 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::Proc, :config do
it 'registers an offense for a Proc.new call' do
expect_offense(<<~RUBY)
f = Proc.new { |x| puts x }
^^^^^^^^ Use `proc` instead of `Proc.new`.
RUBY
expect_correction(<<~RUBY)
f = proc { |x| puts x }... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/mixin_grouping_spec.rb | Ruby | mit | 12,856 | master | 7,830 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MixinGrouping, :config do
context 'when configured with separated style' do
let(:cop_config) { { 'EnforcedStyle' => 'separated' } }
context 'when using `include`' do
it 'registers an offense for several mixins in one call' do
ex... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_string_escape_spec.rb | Ruby | mit | 12,856 | master | 12,301 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantStringEscape, :config do
def wrap(contents)
[l, contents, r].join
end
RSpec.shared_examples 'common no offenses' do |l, r|
let(:l) { l }
let(:r) { r }
it 'does not register an offense without escapes' do
expect_no_... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_slice_spec.rb | Ruby | mit | 12,856 | master | 31,539 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashSlice, :config do
shared_examples 'include?' do
context 'using `include?`' do
it 'does not register an offense when using `select` and calling `!include?` method with symbol array' do
expect_no_offenses(<<~RUBY)
{foo: 1... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_array_constructor_spec.rb | Ruby | mit | 12,856 | master | 3,070 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantArrayConstructor, :config do
it 'registers an offense when using an empty array literal argument for `Array.new`' do
expect_offense(<<~RUBY)
Array.new([])
^^^^^^^^^ Remove the redundant `Array` constructor.
RUBY
expec... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_format_spec.rb | Ruby | mit | 12,856 | master | 18,919 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantFormat, :config do
%i[format sprintf].each do |method|
context "with #{method}" do
it 'does not register an offense when called with no arguments' do
expect_no_offenses(<<~RUBY)
#{method}
#{method}()
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/class_methods_spec.rb | Ruby | mit | 12,856 | master | 1,513 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ClassMethods, :config do
it 'registers an offense for methods using a class name' do
expect_offense(<<~RUBY)
class Test
def Test.some_method
^^^^ Use `self.some_method` instead of `Test.some_method`.
do_somethin... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/signal_exception_spec.rb | Ruby | mit | 12,856 | master | 10,252 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SignalException, :config do
context 'when enforced style is `semantic`' do
let(:cop_config) { { 'EnforcedStyle' => 'semantic' } }
it 'registers an offense for raise in begin section' do
expect_offense(<<~RUBY)
begin
ra... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/collection_compact_spec.rb | Ruby | mit | 12,856 | master | 12,043 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CollectionCompact, :config, :ruby24 do
it 'registers an offense and corrects when using `reject` on array to reject nils' do
expect_offense(<<~RUBY)
array.reject { |e| e.nil? }
^^^^^^^^^^^^^^^^^^^^^ Use `compact` instead of `reje... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/reverse_find_spec.rb | Ruby | mit | 12,856 | master | 3,790 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ReverseFind, :config do
context 'when Ruby >= 4.0', :ruby40 do
it 'registers an offense when using `reverse.find` with block' do
expect_offense(<<~RUBY)
array.reverse.find { |item| item.even? }
^^^^^^^^^^^^ Use `rfind` ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/optional_arguments_spec.rb | Ruby | mit | 12,856 | master | 2,610 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::OptionalArguments, :config do
it 'registers an offense when an optional argument is followed by a required argument' do
expect_offense(<<~RUBY)
def foo(a = 1, b)
^^^^^ Optional arguments should appear at the end of the argument... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.