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/style/string_hash_keys_spec.rb | Ruby | mit | 12,856 | master | 2,203 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::StringHashKeys, :config do
it 'registers an offense when using strings as keys' do
expect_offense(<<~RUBY)
{ 'one' => 1 }
^^^^^ Prefer symbols instead of strings as hash keys.
RUBY
expect_correction(<<~RUBY)
{ :one => ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/send_with_literal_method_name_spec.rb | Ruby | mit | 12,856 | master | 10,789 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SendWithLiteralMethodName, :config do
context 'when calling `public_send` with a symbol literal argument' do
it 'registers an offense' do
expect_offense(<<~RUBY)
obj.public_send(:foo)
^^^^^^^^^^^^^^^^^ Use `foo` method ca... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/predicate_with_kind_spec.rb | Ruby | mit | 12,856 | master | 6,399 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::PredicateWithKind, :config do
shared_examples 'kind check' do |method|
message = "Prefer `#{method}(Integer)` to `#{method} { ... }` with a kind check."
context "with #{method}" do
it 'registers an offense and corrects for `is_a?`' do
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/require_order_spec.rb | Ruby | mit | 12,856 | master | 7,284 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RequireOrder, :config do
context 'when `require` is sorted' do
it 'registers no offense' do
expect_no_offenses(<<~RUBY)
require 'a'
require 'b'
RUBY
end
it 'registers no offense when single-quoted string and do... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/struct_inheritance_spec.rb | Ruby | mit | 12,856 | master | 4,166 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::StructInheritance, :config do
it 'registers an offense when extending instance of Struct' do
expect_offense(<<~RUBY)
class Person < Struct.new(:first_name, :last_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't extend an ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/guard_clause_spec.rb | Ruby | mit | 12,856 | master | 30,787 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::GuardClause, :config do
let(:other_cops) do
{
'Layout/LineLength' => {
'Enabled' => line_length_enabled,
'Max' => 80
}
}
end
let(:line_length_enabled) { true }
shared_examples 'reports offense' do |body|
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/nested_file_dirname_spec.rb | Ruby | mit | 12,856 | master | 1,416 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NestedFileDirname, :config do
context 'Ruby >= 3.1', :ruby31 do
it 'registers and corrects an offense when using `File.dirname(path)` nested two times' do
expect_offense(<<~RUBY)
File.dirname(File.dirname(path))
^^^^^^^^... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/symbol_proc_spec.rb | Ruby | mit | 12,856 | master | 18,338 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SymbolProc, :config do
it 'registers an offense for a block with parameterless method call on param' do
expect_offense(<<~RUBY)
coll.map { |e| e.upcase }
^^^^^^^^^^^^^^^^ Pass `&:upcase` as an argument to `map` instead of a bl... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_except_spec.rb | Ruby | mit | 12,856 | master | 31,188 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashExcept, :config do
shared_examples 'include?' do
context 'using `include?`' do
it 'does not register an offense when using `reject` and calling `!include?` method with symbol array' do
expect_no_offenses(<<~RUBY)
{foo: ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/numeric_predicate_spec.rb | Ruby | mit | 12,856 | master | 11,996 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NumericPredicate, :config do
context 'when configured to enforce numeric predicate methods' do
let(:cop_config) { { 'EnforcedStyle' => 'predicate', 'AutoCorrect' => true } }
context 'when checking if a number is zero' do
it 'registers a... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/multiline_block_chain_spec.rb | Ruby | mit | 12,856 | master | 2,725 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MultilineBlockChain, :config do
context 'with multi-line block chaining' do
it 'registers an offense for a simple case' do
expect_offense(<<~RUBY)
a do
b
end.c do
^^^^^ Avoid multi-line chains of blocks.
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/random_with_offset_spec.rb | Ruby | mit | 12,856 | master | 7,703 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RandomWithOffset, :config do
it 'registers an offense when using rand(int) + offset' do
expect_offense(<<~RUBY)
rand(6) + 1
^^^^^^^^^^^ Prefer ranges when generating random numbers instead of integers with offsets.
RUBY
expect... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/array_intersect_spec.rb | Ruby | mit | 12,856 | master | 16,248 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ArrayIntersect, :config do
context 'when TargetRubyVersion <= 3.0', :ruby30, unsupported_on: :prism do
it 'does not register an offense when using `(array1 & array2).any?`' do
expect_no_offenses(<<~RUBY)
(array1 & array2).any?
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/copyright_spec.rb | Ruby | mit | 12,856 | master | 8,205 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::Copyright, :config do
let(:cop_config) { { 'Notice' => 'Copyright (\(c\) )?2015 Acme Inc' } }
it 'does not register an offense when the notice is present' do
expect_no_offenses(<<~RUBY)
# Copyright 2015 Acme Inc.
# test2
names... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/even_odd_spec.rb | Ruby | mit | 12,856 | master | 3,739 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EvenOdd, :config do
it 'converts x % 2 == 0 to #even?' do
expect_offense(<<~RUBY)
x % 2 == 0
^^^^^^^^^^ Replace with `Integer#even?`.
RUBY
expect_correction(<<~RUBY)
x.even?
RUBY
end
it 'converts x % 2 != 0 to #... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_regexp_escape_spec.rb | Ruby | mit | 12,856 | master | 18,477 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantRegexpEscape, :config do
context 'with a single-line `//` regexp' do
context 'without escapes' do
it 'does not register an offense' do
expect_no_offenses('foo = /a/')
end
end
context 'with escaped slashes' do
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/commented_keyword_spec.rb | Ruby | mit | 12,856 | master | 17,529 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CommentedKeyword, :config do
it 'registers an offense and corrects when commenting on the same line as `end`' do
expect_offense(<<~RUBY)
if x
y
end # comment
^^^^^^^^^ Do not place comments on the same line as the `en... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/combinable_defined_spec.rb | Ruby | mit | 12,856 | master | 7,400 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CombinableDefined, :config do
it 'does not register an offense for a single `defined?`' do
expect_no_offenses(<<~RUBY)
defined?(Foo)
RUBY
end
%i[&& and].each do |operator|
context "joined by `#{operator}`" do
it 'does not ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_assignment_spec.rb | Ruby | mit | 12,856 | master | 5,165 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantAssignment, :config do
it 'reports an offense for def ending with assignment and returning' do
expect_offense(<<~RUBY)
def func
some_preceding_statements
x = something
^^^^^^^^^^^^^ Redundant assignment befor... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/missing_else_spec.rb | Ruby | mit | 12,856 | master | 23,377 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MissingElse, :config do
shared_examples 'pattern matching' do
context '>= Ruby 2.7', :ruby27 do
it 'does not register an offense' do
# Pattern matching is allowed to have no `else` branch because unlike `if` and `case`,
# it ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trailing_underscore_variable_spec.rb | Ruby | mit | 12,856 | master | 9,436 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrailingUnderscoreVariable, :config do
shared_examples 'common functionality' do
it 'registers an offense when the last variable of parallel assignment is an underscore' do
expect_offense(<<~RUBY)
a, b, _ = foo()
^^ Do ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/file_empty_spec.rb | Ruby | mit | 12,856 | master | 6,435 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FileEmpty, :config do
context 'target ruby version >= 2.4', :ruby24 do
it 'registers an offense for `File.zero?`' do
expect_offense(<<~RUBY)
File.zero?('path/to/file')
^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `File.empty?('path/to/file... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/single_line_methods_spec.rb | Ruby | mit | 12,856 | master | 13,420 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SingleLineMethods, :config do
let(:config) do
RuboCop::Config.new('AllCops' => all_cops_config,
'Style/SingleLineMethods' => cop_config,
'Layout/IndentationWidth' => { 'Width' => 2 },
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/hash_lookup_method_spec.rb | Ruby | mit | 12,856 | master | 3,378 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::HashLookupMethod, :config do
context 'with EnforcedStyle: brackets (default)' do
let(:cop_config) { { 'EnforcedStyle' => 'brackets' } }
it 'registers an offense for fetch with one argument' do
expect_offense(<<~RUBY)
hash.fetch(... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_current_directory_in_path_spec.rb | Ruby | mit | 12,856 | master | 2,984 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantCurrentDirectoryInPath, :config do
it "registers an offense when using a current directory path in `require_relative '...'`" do
expect_offense(<<~RUBY)
require_relative './path/to/feature'
^^ Remove the redun... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_capital_w_spec.rb | Ruby | mit | 12,856 | master | 2,204 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantCapitalW, :config do
it 'registers no offense for normal arrays of strings' do
expect_no_offenses('["one", "two", "three"]')
end
it 'registers no offense for normal arrays of strings with interpolation' do
expect_no_offenses('["o... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/parallel_assignment_spec.rb | Ruby | mit | 12,856 | master | 19,206 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ParallelAssignment, :config do
let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) }
it 'registers an offense when the right side has multiple arrays' do
expect_offense(<<~RUBY)
a, b, c = [1, 2], [3, 4], [5, ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/def_with_parentheses_spec.rb | Ruby | mit | 12,856 | master | 2,211 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DefWithParentheses, :config do
it 'reports an offense for def with empty parens' do
expect_offense(<<~RUBY)
def func()
^^ Omit the parentheses in defs when the method doesn't accept any arguments.
end
RUBY
expect... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/strip_spec.rb | Ruby | mit | 12,856 | master | 1,576 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::Strip, :config do
it 'registers an offense for `str.lstrip.rstrip`' do
expect_offense(<<~RUBY)
str.lstrip.rstrip
^^^^^^^^^^^^^ Use `strip` instead of `lstrip.rstrip`.
RUBY
expect_correction(<<~RUBY)
str.strip
RUB... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/zero_length_predicate_spec.rb | Ruby | mit | 12,856 | master | 14,488 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ZeroLengthPredicate, :config do
context 'with arrays' do
it 'registers an offense for `array.length == 0`' do
expect_offense(<<~RUBY)
[1, 2, 3].length == 0
^^^^^^^^^^^^^^^^^^^^^ Use `empty?` instead of `length == 0`.
RU... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/super_arguments_spec.rb | Ruby | mit | 12,856 | master | 12,689 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SuperArguments, :config do
shared_examples 'offense' do |description, args, forwarded_args = args|
it "registers and corrects an offense when using def`#{description} (#{args}) => (#{forwarded_args})`" do
expect_offense(<<~RUBY, forwarded_ar... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trailing_comma_in_hash_literal_spec.rb | Ruby | mit | 12,856 | master | 9,899 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrailingCommaInHashLiteral, :config do
shared_examples 'single line lists' do |extra_info|
it 'registers an offense for trailing comma in a literal' do
expect_offense(<<~RUBY)
MAP = { a: 1001, b: 2020, c: 3333, }
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/document_dynamic_eval_definition_spec.rb | Ruby | mit | 12,856 | master | 8,372 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DocumentDynamicEvalDefinition, :config do
it 'registers an offense when using eval-type method with string interpolation without comment docs' do
expect_offense(<<~RUBY)
class_eval <<-EOT, __FILE__, __LINE__ + 1
^^^^^^^^^^ Add a commen... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/array_first_last_spec.rb | Ruby | mit | 12,856 | master | 2,812 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ArrayFirstLast, :config do
it 'registers an offense when using `[0]`' do
expect_offense(<<~RUBY)
arr[0]
^^^ Use `first`.
RUBY
expect_correction(<<~RUBY)
arr.first
RUBY
end
it 'registers an offense when using ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/map_to_set_spec.rb | Ruby | mit | 12,856 | master | 6,388 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MapToSet, :config do
%i[map collect].each do |method|
context "for `#{method}.to_set` with block arity 1" do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY, method: method)
foo.#{method} { |x| [x, x * 2] }... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trailing_body_on_class_spec.rb | Ruby | mit | 12,856 | master | 3,089 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrailingBodyOnClass, :config do
let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) }
it 'registers an offense when body trails after class definition' do
expect_offense(<<~RUBY)
class Foo; body
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/unless_else_spec.rb | Ruby | mit | 12,856 | master | 2,608 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::UnlessElse, :config do
context 'unless with else' do
it 'registers an offense' do
expect_offense(<<~RUBY)
unless x # negative 1
^^^^^^^^^^^^^^^^^^^^^ Do not use `unless` with `else`. Rewrite these with the positive case first... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/identical_conditional_branches_spec.rb | Ruby | mit | 12,856 | master | 22,052 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::IdenticalConditionalBranches, :config do
context 'on if..else with identical bodies' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
if something
do_x
^^^^ Move `do_x` out of the conditional.
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/percent_q_literals_spec.rb | Ruby | mit | 12,856 | master | 2,702 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::PercentQLiterals, :config do
shared_examples 'accepts quote characters' do
it 'accepts single quotes' do
expect_no_offenses("'hi'")
end
it 'accepts double quotes' do
expect_no_offenses('"hi"')
end
end
shared_examples ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/multiline_ternary_operator_spec.rb | Ruby | mit | 12,856 | master | 7,177 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MultilineTernaryOperator, :config do
it 'registers an offense and corrects when the if branch and the else branch are ' \
'on a separate line from the condition' do
expect_offense(<<~RUBY)
a = cond ?
^^^^^^ Avoid multi-line te... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/empty_string_inside_interpolation_spec.rb | Ruby | mit | 12,856 | master | 4,028 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EmptyStringInsideInterpolation, :config do
context 'when EnforcedStyle is trailing_conditional' do
let(:cop_config) { { 'EnforcedStyle' => 'trailing_conditional' } }
it 'does not register an offense when if branch is not a literal' do
e... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/multiline_if_modifier_spec.rb | Ruby | mit | 12,856 | master | 2,970 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MultilineIfModifier, :config do
context 'if guard clause' do
it 'registers an offense' do
expect_offense(<<~RUBY)
{
^ Favor a normal if-statement over a modifier clause in a multiline statement.
result: run
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/yoda_condition_spec.rb | Ruby | mit | 12,856 | master | 13,039 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::YodaCondition, :config do
context 'enforce not yoda' do
let(:cop_config) { { 'EnforcedStyle' => 'forbid_for_all_comparison_operators' } }
it 'accepts method call on receiver on left' do
expect_no_offenses('b.value == 2')
end
it... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/return_nil_spec.rb | Ruby | mit | 12,856 | master | 1,451 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ReturnNil, :config do
context 'when enforced style is `return`' do
let(:config) do
RuboCop::Config.new(
'Style/ReturnNil' => {
'EnforcedStyle' => 'return',
'SupportedStyles' => %w[return return_nil]
}
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trivial_accessors_spec.rb | Ruby | mit | 12,856 | master | 9,923 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrivialAccessors, :config do
let(:cop_config) { {} }
it 'registers an offense on instance reader' do
expect_offense(<<~RUBY)
class Foo
def foo
^^^ Use `attr_reader` to define trivial reader methods.
@foo
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/non_nil_check_spec.rb | Ruby | mit | 12,856 | master | 4,831 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NonNilCheck, :config do
context 'when not allowing semantic changes' do
let(:cop_config) { { 'IncludeSemanticChanges' => false } }
it 'registers an offense for != nil' do
expect_offense(<<~RUBY)
x != nil
^^^^^^^^ Prefer ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/word_array_spec.rb | Ruby | mit | 12,856 | master | 18,586 | # frozen_string_literal: true
require 'timeout'
RSpec.describe RuboCop::Cop::Style::WordArray, :config do
include EncodingHelper
before do
# Reset data which is shared by all instances of WordArray
described_class.largest_brackets = -Float::INFINITY
end
let(:other_cops) do
{
'Style/Percent... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/one_line_conditional_spec.rb | Ruby | mit | 12,856 | master | 19,606 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::OneLineConditional, :config do
let(:config) { RuboCop::Config.new(config_data) }
let(:config_data) { cop_config_data }
let(:cop_config_data) do
{
'Style/OneLineConditional' => {
'AlwaysCorrectToMultiline' => always_correct_to_mul... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_self_spec.rb | Ruby | mit | 12,856 | master | 13,590 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantSelf, :config do
it 'reports an offense a self receiver on an rvalue' do
expect_offense(<<~RUBY)
a = self.b
^^^^ Redundant `self` detected.
RUBY
expect_correction(<<~RUBY)
a = b
RUBY
end
it 'does no... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/while_until_do_spec.rb | Ruby | mit | 12,856 | master | 1,063 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::WhileUntilDo, :config do
it 'registers an offense for do in multiline while' do
expect_offense(<<~RUBY)
while cond do
^^ Do not use `do` with multi-line `while`.
end
RUBY
expect_correction(<<~RUBY)
while... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/if_with_semicolon_spec.rb | Ruby | mit | 12,856 | master | 13,243 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::IfWithSemicolon, :config do
it 'registers an offense and corrects for one line if/;/end' do
expect_offense(<<~RUBY)
if cond; run else dont end
^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `if cond;` - use a ternary operator instead.
RUBY
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/ascii_comments_spec.rb | Ruby | mit | 12,856 | master | 988 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::AsciiComments, :config do
it 'registers an offense for a comment with non-ascii chars' do
expect_offense(<<~RUBY)
# 这是什么?
^^^^^ Use only ascii symbols in comments.
RUBY
end
it 'registers an offense for comments with mixed ch... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/comment_annotation_spec.rb | Ruby | mit | 12,856 | master | 10,718 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CommentAnnotation, :config do
context 'with default RequireColon configuration (colon + space)' do
let(:cop_config) { { 'Keywords' => %w[TODO FIXME OPTIMIZE HACK REVIEW] } }
context 'missing colon' do
it 'registers an offense and adds c... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/block_delimiters_spec.rb | Ruby | mit | 12,856 | master | 34,531 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::BlockDelimiters, :config do
shared_examples 'always accepted' do
context 'with blocks that need braces to be valid ruby' do
it 'accepts a multi-line block' do
expect_no_offenses(<<~RUBY)
puts [1, 2, 3].map { |n|
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/multiline_when_then_spec.rb | Ruby | mit | 12,856 | master | 3,531 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MultilineWhenThen, :config do
it 'registers an offense for empty when statement with then' do
expect_offense(<<~RUBY)
case foo
when bar then
^^^^ Do not use `then` for multiline `when` statement.
end
RUBY
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/not_spec.rb | Ruby | mit | 12,856 | master | 1,860 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::Not, :config do
it 'registers an offense for not' do
expect_offense(<<~RUBY)
not test
^^^ Use `!` instead of `not`.
RUBY
expect_correction(<<~RUBY)
!test
RUBY
end
it 'does not register an offense for !' do
e... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/documentation_method_spec.rb | Ruby | mit | 12,856 | master | 26,107 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DocumentationMethod, :config do
let(:require_for_non_public_methods) { false }
let(:config) do
RuboCop::Config.new(
'Style/CommentAnnotation' => {
'Keywords' => %w[TODO FIXME OPTIMIZE HACK REVIEW]
},
'Style/Documentati... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_percent_q_spec.rb | Ruby | mit | 12,856 | master | 5,782 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantPercentQ, :config do
context 'with %q strings' do
it 'registers an offense for only single quotes' do
expect_offense(<<~RUBY)
%q('hi')
^^^^^^^^ Use `%q` only for strings that contain both single quotes and double quo... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_file_extension_in_require_spec.rb | Ruby | mit | 12,856 | master | 1,076 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantFileExtensionInRequire, :config do
it 'registers an offense and corrects when requiring filename ending with `.rb`' do
expect_offense(<<~RUBY)
require 'foo.rb'
^^^ Redundant `.rb` file extension detected.
req... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/string_chars_spec.rb | Ruby | mit | 12,856 | master | 1,839 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::StringChars, :config do
it 'registers and corrects an offense when using `split(//)`' do
expect_offense(<<~RUBY)
string.split(//)
^^^^^^^^^ Use `chars` instead of `split(//)`.
RUBY
expect_correction(<<~RUBY)
strin... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/tally_method_spec.rb | Ruby | mit | 12,856 | master | 9,019 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TallyMethod, :config do
context 'when targeting Ruby 2.7+', :ruby27 do
context 'with `each_with_object(Hash.new(0))` pattern' do
it 'registers an offense and corrects' do
expect_offense(<<~RUBY)
array.each_with_object(Hash.... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_regexp_argument_spec.rb | Ruby | mit | 12,856 | master | 8,716 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantRegexpArgument, :config do
described_class::RESTRICT_ON_SEND.each do |method|
it "registers an offense and corrects when the method is `#{method}`" do
expect_offense(<<~RUBY, method: method)
'foo'.#{method}(/f/)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/line_end_concatenation_spec.rb | Ruby | mit | 12,856 | master | 6,093 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::LineEndConcatenation, :config do
it 'registers an offense for string concat at line end' do
expect_offense(<<~RUBY)
top = "test" +
^ Use `\\` instead of `+` to concatenate multiline strings.
"top"
RUBY
expec... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/empty_literal_spec.rb | Ruby | mit | 12,856 | master | 11,705 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EmptyLiteral, :config do
describe 'Empty Array' do
shared_examples 'registers_and_corrects' do |initializer:|
it "registers an offense for #{initializer}" do
expect_offense(<<~RUBY)
test = #{initializer}
#{... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/date_time_spec.rb | Ruby | mit | 12,856 | master | 2,587 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DateTime, :config do
let(:cop_config) { { 'AllowCoercion' => false } }
it 'registers an offense when using DateTime for current time' do
expect_offense(<<~RUBY)
DateTime.now
^^^^^^^^^^^^ Prefer `Time` over `DateTime`.
RUBY
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/double_cop_disable_directive_spec.rb | Ruby | mit | 12,856 | master | 1,601 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DoubleCopDisableDirective, :config do
it 'registers an offense for duplicate disable directives' do
expect_offense(<<~RUBY)
def choose_move(who_to_move) # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/AbcSize # ruboc... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/explicit_block_argument_spec.rb | Ruby | mit | 12,856 | master | 8,626 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ExplicitBlockArgument, :config do
it 'registers an offense and corrects when block just yields its arguments' do
expect_offense(<<~RUBY)
def m
items.something(first_arg) { |i| yield i }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/exponential_notation_spec.rb | Ruby | mit | 12,856 | master | 4,094 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ExponentialNotation, :config do
context 'EnforcedStyle is scientific' do
let(:cop_config) { { 'EnforcedStyle' => 'scientific' } }
it 'registers an offense for mantissa equal to 10' do
expect_offense(<<~RUBY)
10e6
^^^^ Us... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/global_vars_spec.rb | Ruby | mit | 12,856 | master | 730 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::GlobalVars, :config do
cop_config = { 'AllowedVariables' => ['$allowed'] }
let(:cop_config) { cop_config }
it 'registers an offense for $custom' do
expect_offense(<<~RUBY)
puts $custom
^^^^^^^ Do not introduce global variabl... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/yoda_expression_spec.rb | Ruby | mit | 12,856 | master | 2,191 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::YodaExpression, :config do
let(:cop_config) { { 'SupportedOperators' => ['*', '+'] } }
it 'registers an offense when numeric literal on left' do
expect_offense(<<~RUBY)
1 + x
^^^^^ Non-literal operand (`x`) should be first.
RUBY... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/disable_cops_within_source_code_directive_spec.rb | Ruby | mit | 12,856 | master | 2,899 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DisableCopsWithinSourceCodeDirective, :config do
it 'registers an offense for disabled cop within source code' do
expect_offense(<<~RUBY)
def foo # rubocop:disable Metrics/CyclomaticComplexity
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/nested_ternary_operator_spec.rb | Ruby | mit | 12,856 | master | 3,057 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NestedTernaryOperator, :config do
it 'registers an offense and corrects for a nested ternary operator expression' do
expect_offense(<<~RUBY)
a ? (b ? b1 : b2) : a2
^^^^^^^^^^^ Ternary operators must not be nested. Prefer `if` or `... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_argument_spec.rb | Ruby | mit | 12,856 | master | 5,672 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantArgument, :config do
let(:cop_config) do
{
'Methods' => {
'join' => '', 'sum' => 0, 'exit' => true, 'exit!' => false,
'to_i' => 10, 'split' => ' ', 'chomp' => "\n", 'chomp!' => "\n"
}
}
end
it 'registe... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/dir_empty_spec.rb | Ruby | mit | 12,856 | master | 3,842 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::DirEmpty, :config do
context 'target ruby version >= 2.4', :ruby24 do
it 'registers an offense for `Dir.entries.size == 2`' do
expect_offense(<<~RUBY)
Dir.entries('path/to/dir').size == 2
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/command_literal_spec.rb | Ruby | mit | 12,856 | master | 11,188 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CommandLiteral, :config do
let(:config) do
supported_styles = { 'SupportedStyles' => %w[backticks percent_x mixed] }
RuboCop::Config.new('Style/PercentLiteralDelimiters' =>
percent_literal_delimiters_config,
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/yaml_file_read_spec.rb | Ruby | mit | 12,856 | master | 3,568 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::YAMLFileRead, :config do
context 'when Ruby >= 3.0', :ruby30 do
it 'registers an offense when using `YAML.load` with `File.read` argument' do
expect_offense(<<~RUBY)
YAML.load(File.read(path))
^^^^^^^^^^^^^^^^^^^^^ Use `... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/nil_comparison_spec.rb | Ruby | mit | 12,856 | master | 2,162 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::NilComparison, :config do
context 'configured with predicate preferred' do
let(:cop_config) { { 'EnforcedStyle' => 'predicate' } }
it 'registers an offense for == nil' do
expect_offense(<<~RUBY)
x == nil
^^ Prefer the ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_struct_keyword_init_spec.rb | Ruby | mit | 12,856 | master | 4,839 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantStructKeywordInit, :config do
context 'Ruby >= 3.2', :ruby32 do
it 'registers an offense when using `keyword_init: nil` in `Struct.new`' do
expect_offense(<<~RUBY)
Struct.new(:foo, keyword_init: nil)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/string_methods_spec.rb | Ruby | mit | 12,856 | master | 661 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::StringMethods, :config do
let(:cop_config) { { 'intern' => 'to_sym' } }
it 'registers an offense' do
expect_offense(<<~RUBY)
'something'.intern
^^^^^^ Prefer `to_sym` over `intern`.
RUBY
expect_correction(<<~RUB... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/class_check_spec.rb | Ruby | mit | 12,856 | master | 1,451 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ClassCheck, :config do
context 'when enforced style is `is_a?`' do
let(:cop_config) { { 'EnforcedStyle' => 'is_a?' } }
it 'registers an offense for `kind_of?` and corrects to `is_a?`' do
expect_offense(<<~RUBY)
x.kind_of? y
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_initialize_spec.rb | Ruby | mit | 12,856 | master | 5,368 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantInitialize, :config do
let(:cop_config) { { 'AllowComments' => true } }
it 'does not register an offense for an empty method not named `initialize`' do
expect_no_offenses(<<~RUBY)
def do_something
end
RUBY
end
it '... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/end_block_spec.rb | Ruby | mit | 12,856 | master | 466 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::EndBlock, :config do
it 'reports an offense and corrects END block' do
expect_offense(<<~RUBY)
END { test }
^^^ Avoid the use of `END` blocks. Use `Kernel#at_exit` instead.
RUBY
expect_correction(<<~RUBY)
at_exit { test ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/safe_navigation_spec.rb | Ruby | mit | 12,856 | master | 57,759 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SafeNavigation, :config do
let(:cop_config) { { 'ConvertCodeThatCanStartToReturnNil' => false } }
let(:target_ruby_version) { 2.3 }
it 'allows calls to methods not safeguarded by respond_to' do
expect_no_offenses('foo.bar')
end
it 'allow... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/quoted_symbols_spec.rb | Ruby | mit | 12,856 | master | 8,205 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::QuotedSymbols, :config do
shared_examples 'enforce single quotes' do
it 'accepts unquoted symbols' do
expect_no_offenses(<<~RUBY)
:a
RUBY
end
it 'accepts single quotes' do
expect_no_offenses(<<~RUBY)
:'a'... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_condition_spec.rb | Ruby | mit | 12,856 | master | 31,577 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantCondition, :config do
context 'when regular condition (if)' do
it 'accepts different when the condition does not match the branch' do
expect_no_offenses(<<~RUBY)
if a
b
else
c
end
RU... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/access_modifier_declarations_spec.rb | Ruby | mit | 12,856 | master | 29,799 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::AccessModifierDeclarations, :config do
shared_examples 'always accepted' do |access_modifier|
it "accepts when #{access_modifier} is a hash literal value" do
expect_no_offenses(<<~RUBY)
class Foo
foo
bar(key: #{ac... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/select_by_regexp_spec.rb | Ruby | mit | 12,856 | master | 25,961 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::SelectByRegexp, :config do
shared_examples 'regexp match' do |method, correction|
message = "Prefer `#{correction}` to `#{method}` with a regexp match."
context "with #{method}" do
it 'registers an offense and corrects for `match?`' do
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/bisected_attr_accessor_spec.rb | Ruby | mit | 12,856 | master | 7,905 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::BisectedAttrAccessor, :config do
it 'registers an offense and corrects when both accessors of the name exists' do
expect_offense(<<~RUBY)
class Foo
attr_reader :bar
^^^^ Combine both accessors into `attr_accessor ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/operator_method_call_spec.rb | Ruby | mit | 12,856 | master | 5,709 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::OperatorMethodCall, :config do
described_class::RESTRICT_ON_SEND.each do |operator_method|
it "registers an offense when using `foo.#{operator_method} bar`" do
expect_offense(<<~RUBY, operator_method: operator_method)
foo.#{operator_... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/missing_respond_to_missing_spec.rb | Ruby | mit | 12,856 | master | 2,574 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MissingRespondToMissing, :config do
it 'registers an offense when respond_to_missing? is not implemented' do
expect_offense(<<~RUBY)
class Test
def method_missing
^^^^^^^^^^^^^^^^^^ When using `method_missing`, define `respon... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/combinable_loops_spec.rb | Ruby | mit | 12,856 | master | 9,015 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::CombinableLoops, :config do
context 'when looping method' do
it 'registers an offense when looping over the same data as previous loop' do
expect_offense(<<~RUBY)
items.each { |item| do_something(item) }
items.each { |item| d... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/map_compact_with_conditional_block_spec.rb | Ruby | mit | 12,856 | master | 12,556 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::MapCompactWithConditionalBlock, :config do
context 'With multiline block' do
it 'registers an offense and corrects to `select` with `if` condition' do
expect_offense(<<~RUBY)
foo.map do |item|
^^^^^^^^^^^^^ Replace `map {... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/arguments_forwarding_spec.rb | Ruby | mit | 12,856 | master | 93,870 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ArgumentsForwarding, :config do
let(:cop_config) do
{
'RedundantRestArgumentNames' => redundant_rest_argument_names,
'RedundantKeywordRestArgumentNames' => redundant_keyword_rest_argument_names,
'RedundantBlockArgumentNames' => r... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/keyword_parameters_order_spec.rb | Ruby | mit | 12,856 | master | 4,725 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::KeywordParametersOrder, :config do
it 'registers an offense and corrects when `kwoptarg` is before `kwarg`' do
expect_offense(<<~RUBY)
def m(arg, optional: 1, required:)
^^^^^^^^^^^ Place optional keyword parameters at the e... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/reduce_to_hash_spec.rb | Ruby | mit | 12,856 | master | 7,639 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::ReduceToHash, :config do
context 'when targeting Ruby 2.6+', :ruby26 do
context 'with `each_with_object({})` pattern' do
it 'registers an offense and corrects with inline block' do
expect_offense(<<~RUBY)
array.each_with_ob... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/redundant_self_assignment_spec.rb | Ruby | mit | 12,856 | master | 4,049 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RedundantSelfAssignment, :config do
context 'when lhs and receiver are the same' do
it 'registers an offense and corrects when assigning to local variable' do
expect_offense(<<~RUBY)
foo = foo.concat(ary)
^ Redundant self... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/trailing_method_end_statement_spec.rb | Ruby | mit | 12,856 | master | 3,666 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::TrailingMethodEndStatement, :config do
let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) }
it 'registers an offense with trailing end on 2 line method' do
expect_offense(<<~RUBY)
def some_method
foo; ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/open_struct_use_spec.rb | Ruby | mit | 12,856 | master | 2,217 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::OpenStructUse, :config do
context 'when using OpenStruct' do
['OpenStruct', '::OpenStruct'].each do |klass|
context "for #{klass}" do
context 'when used in assignments' do
it 'registers an offense' do
expect_off... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/dir_spec.rb | Ruby | mit | 12,856 | master | 1,487 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::Dir, :config do
context 'when using `#expand_path` and `#dirname`' do
it 'registers an offense' do
expect_offense(<<~RUBY)
File.expand_path(File.dirname(__FILE__))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `__dir__` to get... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | spec/rubocop/cop/style/frozen_string_literal_comment_spec.rb | Ruby | mit | 12,856 | master | 32,260 | # frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::FrozenStringLiteralComment, :config do
context 'always' do
let(:cop_config) { { 'Enabled' => true, 'EnforcedStyle' => 'always' } }
it 'accepts an empty source' do
expect_no_offenses('')
end
it 'accepts a source with no tokens' ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.