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/character_literal_spec.rb
Ruby
mit
12,856
master
975
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::CharacterLiteral, :config do it 'registers an offense for character literals' do expect_offense(<<~RUBY) x = ?x ^^ Do not use the character literal - use string literal instead. RUBY expect_correction(<<~RUBY) x = 'x...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/special_global_vars_spec.rb
Ruby
mit
12,856
master
10,163
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::SpecialGlobalVars, :config do context 'when style is use_english_names' do context 'when add require English is disabled' do let(:cop_config) do { 'EnforcedStyle' => 'use_english_names', 'RequireEnglish' => false ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/mixin_usage_spec.rb
Ruby
mit
12,856
master
4,230
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MixinUsage, :config do context 'include' do it 'registers an offense when using outside class (used above)' do expect_offense(<<~RUBY) include M ^^^^^^^^^ `include` is used at the top level. Use inside `class` or `module`. ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/multiple_comparison_spec.rb
Ruby
mit
12,856
master
12,365
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MultipleComparison, :config do it 'does not register an offense for comparing an lvar' do expect_no_offenses(<<~RUBY) a = "a" if a == "a" print a end RUBY end it 'registers an offense and corrects when `a` is com...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/one_class_per_file_spec.rb
Ruby
mit
12,856
master
5,613
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::OneClassPerFile, :config do context 'when multiple top-level definitions exist' do it 'registers an offense for two top-level classes' do expect_offense(<<~RUBY) class Foo end class Bar ^^^^^^^^^ Do not defin...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/negated_if_else_condition_spec.rb
Ruby
mit
12,856
master
10,237
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::NegatedIfElseCondition, :config do it 'registers an offense and corrects when negating condition with `!` for `if-else`' do expect_offense(<<~RUBY) if !x ^^^^^ Invert the negated condition and swap the if-else branches. do_some...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/partition_instead_of_double_select_spec.rb
Ruby
mit
12,856
master
13,551
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::PartitionInsteadOfDoubleSelect, :config do context 'when using select and reject with same receiver and block' do it 'registers an offense and corrects select followed by reject' do expect_offense(<<~RUBY) positives = arr.select { |x...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/in_pattern_then_spec.rb
Ruby
mit
12,856
master
2,309
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::InPatternThen, :config do context '>= Ruby 2.7', :ruby27 do it 'registers an offense for `in b;`' do expect_offense(<<~RUBY) case a in b; c ^ Do not use `in b;`. Use `in b then` instead. end RUBY ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/data_inheritance_spec.rb
Ruby
mit
12,856
master
6,914
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::DataInheritance, :config do context 'Ruby >= 3.2', :ruby32 do it 'registers an offense when extending instance of `Data.define`' do expect_offense(<<~RUBY) class Person < Data.define(:first_name, :last_name) ^^...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/each_for_simple_loop_spec.rb
Ruby
mit
12,856
master
5,703
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EachForSimpleLoop, :config do it 'does not register offense if range starting point is not constant' do expect_no_offenses('(a..10).each {}') end it 'does not register offense if range endpoint is not constant' do expect_no_offenses('(0.....
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/it_assignment_spec.rb
Ruby
mit
12,856
master
4,441
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ItAssignment, :config do it 'registers an offense when assigning a local `it` variable' do expect_offense(<<~RUBY) it = 5 ^^ `it` is the default block parameter; consider another name. RUBY end it 'registers an offense when na...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/negative_array_index_spec.rb
Ruby
mit
12,856
master
18,035
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::NegativeArrayIndex, :config do shared_examples 'registers an offense for simple index' do |array_receiver, index_receiver, method_name, n| offense_text = "#{index_receiver}.#{method_name} - #{n}" offense_length = offense_text.length carets...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/documentation_spec.rb
Ruby
mit
12,856
master
14,149
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Documentation, :config do let(:config) do RuboCop::Config.new('Style/CommentAnnotation' => { 'Keywords' => %w[TODO FIXME OPTIMIZE HACK REVIEW] }) end it 'registers an offense for non-empty cla...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_double_splat_hash_braces_spec.rb
Ruby
mit
12,856
master
8,748
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantDoubleSplatHashBraces, :config do it 'registers an offense when using double splat hash braces' do expect_offense(<<~RUBY) do_something(**{foo: bar, baz: qux}) ^^^^^^^^^^^^^^^^^^^^^^ Remove the redundant double sp...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/hash_fetch_chain_spec.rb
Ruby
mit
12,856
master
4,984
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::HashFetchChain, :config do context 'ruby >= 2.3' do context 'with chained `fetch` methods' do shared_examples 'fetch chain' do |argument| context "when the 2nd argument is `#{argument}`" do it 'does not register an offense ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_freeze_spec.rb
Ruby
mit
12,856
master
7,661
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantFreeze, :config do let(:prefix) { nil } shared_examples 'immutable objects' do |o| it "registers an offense for frozen #{o}" do expect_offense([prefix, <<~RUBY].compact.join("\n"), o: o) CONST = %{o}.freeze ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/regexp_literal_spec.rb
Ruby
mit
12,856
master
20,016
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RegexpLiteral, :config do let(:config) do supported_styles = { 'SupportedStyles' => %w[slashes percent_r mixed] } RuboCop::Config.new('Style/PercentLiteralDelimiters' => percent_literal_delimiters_config, ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/method_call_without_args_parentheses_spec.rb
Ruby
mit
12,856
master
8,418
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MethodCallWithoutArgsParentheses, :config do it 'registers an offense for parens in method call without args' do expect_offense(<<~RUBY) top.test() ^^ Do not use parentheses for method calls with no arguments. RUBY exp...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/ip_addresses_spec.rb
Ruby
mit
12,856
master
2,582
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::IpAddresses, :config do let(:cop_config) { {} } it 'does not register an offense on an empty string' do expect_no_offenses("''") end context 'IPv4' do it 'registers an offense for a valid address' do expect_offense(<<~RUBY) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/map_to_hash_spec.rb
Ruby
mit
12,856
master
7,966
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MapToHash, :config do context '>= Ruby 2.6', :ruby26 do %i[map collect].each do |method| context "for `#{method}.to_h` with block arity 1" do it 'registers an offense and corrects' do expect_offense(<<~RUBY, method: method)...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/file_open_spec.rb
Ruby
mit
12,856
master
3,924
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::FileOpen, :config do it 'registers an offense when using `File.open` without a block' do expect_offense(<<~RUBY) File.open('file') ^^^^^^^^^^^^^^^^^ `File.open` without a block may leak a file descriptor; use the block form. RUBY ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/stderr_puts_spec.rb
Ruby
mit
12,856
master
1,251
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::StderrPuts, :config do it "registers an offense when using `$stderr.puts('hello')`" do expect_offense(<<~RUBY) $stderr.puts('hello') ^^^^^^^^^^^^ Use `warn` instead of `$stderr.puts` to allow such output to be disabled. RUBY e...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_each_spec.rb
Ruby
mit
12,856
master
8,919
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantEach, :config do it 'registers an offense when using `each.each`' do expect_offense(<<~RUBY) array.each.each { |v| do_something(v) } ^^^^^ Remove redundant `each`. RUBY expect_correction(<<~RUBY) array.eac...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_interpolation_spec.rb
Ruby
mit
12,856
master
6,358
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantInterpolation, :config do it 'registers an offense for "#{1 + 1}"' do expect_offense(<<~'RUBY') "#{1 + 1}" ^^^^^^^^^^ Prefer `to_s` over string interpolation. RUBY expect_correction(<<~RUBY) (1 + 1).to_s RUB...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/lambda_call_spec.rb
Ruby
mit
12,856
master
6,097
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::LambdaCall, :config do context 'when style is set to call' do let(:cop_config) { { 'EnforcedStyle' => 'call' } } it 'registers an offense for x.()' do expect_offense(<<~RUBY) x.(a, b) ^^^^^^^^ Prefer the use of `x.call(a...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/block_comments_spec.rb
Ruby
mit
12,856
master
1,352
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::BlockComments, :config do it 'registers an offense for block comments' do expect_offense(<<~RUBY) =begin ^^^^^^ Do not use block comments. comment =end RUBY expect_correction(<<~RUBY) # comment RUBY end...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/static_class_spec.rb
Ruby
mit
12,856
master
3,181
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::StaticClass, :config do it 'registers an offense when class has only class method' do expect_offense(<<~RUBY) class C ^^^^^^^ Prefer modules to classes with only class methods. def self.class_method; end end RUBY ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/negated_if_spec.rb
Ruby
mit
12,856
master
4,598
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::NegatedIf do subject(:cop) do config = RuboCop::Config.new( 'Style/NegatedIf' => { 'SupportedStyles' => %w[both prefix postfix], 'EnforcedStyle' => 'both' } ) described_class.new(config) end describe 'with ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/alias_spec.rb
Ruby
mit
12,856
master
6,120
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Alias, :config do context 'when EnforcedStyle is prefer_alias_method' do let(:cop_config) { { 'EnforcedStyle' => 'prefer_alias_method' } } it 'registers an offense for alias with symbol args' do expect_offense(<<~RUBY) alias :al...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/option_hash_spec.rb
Ruby
mit
12,856
master
2,609
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::OptionHash, :config do let(:cop_config) { { 'SuspiciousParamNames' => suspicious_names } } let(:suspicious_names) { ['options'] } it 'registers an offense' do expect_offense(<<~RUBY) def some_method(options = {}) ^...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_exception_spec.rb
Ruby
mit
12,856
master
4,252
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantException, :config do shared_examples 'common behavior' do |keyword, runtime_error| it "reports an offense for a #{keyword} with #{runtime_error}" do expect_offense(<<~RUBY, keyword: keyword, runtime_error: runtime_error) %{...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/mutable_constant_spec.rb
Ruby
mit
12,856
master
21,256
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MutableConstant, :config do let(:prefix) { nil } shared_examples 'mutable objects' do |o| context 'when assigning with =' do it "registers an offense for #{o} assigned to a constant " \ 'and corrects by adding .freeze' do ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/empty_lambda_parameter_spec.rb
Ruby
mit
12,856
master
637
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EmptyLambdaParameter, :config do it 'registers an offense for an empty block parameter with a lambda' do expect_offense(<<~RUBY) -> () { do_something } ^^ Omit parentheses for the empty lambda parameters. RUBY expect_correc...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/collection_querying_spec.rb
Ruby
mit
12,856
master
4,803
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::CollectionQuerying, :config do it 'registers an offense for `.count.positive?`' do expect_offense(<<~RUBY) x.count.positive? ^^^^^^^^^^^^^^^ Use `any?` instead. RUBY expect_correction(<<~RUBY) x.any? RUBY end ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/string_literals_spec.rb
Ruby
mit
12,856
master
12,773
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::StringLiterals, :config do context 'configured with single quotes preferred' do let(:cop_config) { { 'EnforcedStyle' => 'single_quotes' } } it 'registers an offense for double quotes when single quotes suffice' do expect_offense(<<~'RUB...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/bare_percent_literals_spec.rb
Ruby
mit
12,856
master
2,563
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::BarePercentLiterals, :config do shared_examples 'accepts other delimiters' do it 'accepts __FILE__' do expect_no_offenses('__FILE__') end it 'accepts regular expressions' do expect_no_offenses('/%Q?/') end it 'accepts...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/hash_like_case_spec.rb
Ruby
mit
12,856
master
2,408
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::HashLikeCase, :config do context 'MinBranchesCount: 2' do let(:cop_config) { { 'MinBranchesCount' => 2 } } it 'registers an offense when using `case-when` with string conditions and literal bodies of the same type' do expect_offense(<<~...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_interpolation_unfreeze_spec.rb
Ruby
mit
12,856
master
4,209
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantInterpolationUnfreeze, :config do context 'target_ruby_version >= 3.0', :ruby30 do it 'registers an offense for `@+`' do expect_offense(<<~'RUBY') +"#{foo} bar" ^ Don't unfreeze interpolated strings as they are alrea...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/array_join_spec.rb
Ruby
mit
12,856
master
1,152
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ArrayJoin, :config do it 'registers an offense for an array followed by string' do expect_offense(<<~RUBY) %w(one two three) * ", " ^ Favor `Array#join` over `Array#*`. RUBY expect_correction(<<~RUBY) %...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/file_null_spec.rb
Ruby
mit
12,856
master
3,004
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::FileNull, :config do it 'does not register an offense for an empty string' do expect_no_offenses(<<~RUBY) "" RUBY end it 'does not register an offense when there is an invalid byte sequence error' do expect_no_offenses(<<~'RUBY'...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/implicit_runtime_error_spec.rb
Ruby
mit
12,856
master
1,631
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ImplicitRuntimeError, :config do it 'registers an offense for `raise` without error class' do expect_offense(<<~RUBY) raise 'message' ^^^^^^^^^^^^^^^ Use `raise` with an explicit exception class and message, rather than just a message....
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/send_spec.rb
Ruby
mit
12,856
master
2,506
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Send, :config do context 'with send' do context 'and with a receiver' do it 'registers an offense for an invocation with args' do expect_offense(<<~RUBY) Object.send(foo) ^^^^ Prefer `Object#__send__` or `O...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/preferred_hash_methods_spec.rb
Ruby
mit
12,856
master
2,058
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::PreferredHashMethods, :config do context 'with enforced `short` style' do let(:cop_config) { { 'EnforcedStyle' => 'short' } } it 'registers an offense for has_key? with one arg' do expect_offense(<<~RUBY) o.has_key?(o) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/keyword_arguments_merging_spec.rb
Ruby
mit
12,856
master
3,168
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::KeywordArgumentsMerging, :config do it 'registers an offense and corrects when using `merge` with keyword arguments' do expect_offense(<<~RUBY) foo(x, **options.merge(y: 1)) ^^^^^^^^^^^^^^^^^^^ Provide additional arguments dir...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/class_equality_comparison_spec.rb
Ruby
mit
12,856
master
7,733
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ClassEqualityComparison, :config do let(:cop_config) { { 'AllowedMethods' => [] } } it 'registers an offense and corrects when comparing class using `==` for equality' do expect_offense(<<~RUBY) var.class == Date ^^^^^^^^^^^^^ U...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/empty_class_definition_spec.rb
Ruby
mit
12,856
master
15,197
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EmptyClassDefinition, :config do context 'when EnforcedStyle is class_keyword' do let(:cop_config) { { 'EnforcedStyle' => 'class_keyword' } } it 'registers an offense for Class.new assignment to constant' do expect_offense(<<~RUBY) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_parentheses_spec.rb
Ruby
mit
12,856
master
57,963
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantParentheses, :config do shared_examples 'redundant' do |expr, correct, type, options| it "registers an offense for parentheses around #{type}", *options do expect_offense(<<~RUBY, expr: expr) %{expr} ^{expr} Don't us...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/next_spec.rb
Ruby
mit
12,856
master
16,923
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Next, :config do let(:cop_config) { { 'MinBodyLength' => 1 } } shared_examples 'iterators' do |condition| let(:opposite) { condition == 'if' ? 'unless' : 'if' } it "registers an offense for #{condition} inside of downto" do expect_of...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/multiline_memoization_spec.rb
Ruby
mit
12,856
master
4,545
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MultilineMemoization, :config do shared_examples 'with all enforced styles' do context 'with a single line memoization' do it 'allows expression on first line' do expect_no_offenses('foo ||= bar') end it 'allows expressi...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/magic_comment_format_spec.rb
Ruby
mit
12,856
master
8,591
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MagicCommentFormat, :config do subject(:cop_config) do { 'EnforcedStyle' => enforced_style, 'DirectiveCapitalization' => directive_capitalization, 'ValueCapitalization' => value_capitalization } end let(:enforced_style) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_line_continuation_spec.rb
Ruby
mit
12,856
master
27,729
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantLineContinuation, :config do context 'when a line continuation precedes the arguments to an unparenthesized method call' do shared_examples 'no offense' do |argument| it "does not register an offense when the first argument is `#{ar...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/rescue_standard_error_spec.rb
Ruby
mit
12,856
master
12,257
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RescueStandardError, :config do context 'implicit' do let(:cop_config) do { 'EnforcedStyle' => 'implicit', 'SupportedStyles' => %w[implicit explicit] } end context 'when rescuing in a begin block' do it 'accepts rescui...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/inline_comment_spec.rb
Ruby
mit
12,856
master
624
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::InlineComment, :config do it 'registers an offense for a trailing inline comment' do expect_offense(<<~RUBY) two = 1 + 1 # A trailing inline comment ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid trailing inline comments. RUBY end...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/sample_spec.rb
Ruby
mit
12,856
master
4,906
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Sample, :config do shared_examples 'offense' do |wrong, right| it "registers an offense for #{wrong}" do expect_offense(<<~RUBY, wrong: wrong) [1, 2, 3].%{wrong} ^{wrong} Use `#{right}` instead of `#{wrong}`. ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/empty_else_spec.rb
Ruby
mit
12,856
master
23,305
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EmptyElse, :config do let(:missing_else_config) { {} } shared_examples 'autocorrect' do |keyword| context 'MissingElse is disabled' do it 'does autocorrection' do expect_offense(source) expect_correction(corrected_source)...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/hash_transform_values_spec.rb
Ruby
mit
12,856
master
11,651
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::HashTransformValues, :config do context 'when using Ruby 2.4 or newer', :ruby24 do context 'with inline block' do it 'flags each_with_object when transform_values could be used' do expect_offense(<<~RUBY) {a: 1, b: 2}.each_...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/stabby_lambda_parentheses_spec.rb
Ruby
mit
12,856
master
1,474
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::StabbyLambdaParentheses, :config do shared_examples 'common' do it 'does not check the old lambda syntax' do expect_no_offenses('lambda(&:nil?)') end it 'does not check a stabby lambda without arguments' do expect_no_offenses(...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/numeric_literals_spec.rb
Ruby
mit
12,856
master
7,964
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::NumericLiterals, :config do include_context 'with exclude limit tracking' let(:cop_config) { { 'MinDigits' => 5 } } it 'registers an offense for a long undelimited integer' do expect_offense(<<~RUBY) a = 12345 ^^^^^ Use under...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/numeric_literal_prefix_spec.rb
Ruby
mit
12,856
master
2,705
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::NumericLiteralPrefix, :config do context 'octal literals' do context 'when config is zero_with_o' do let(:cop_config) { { 'EnforcedOctalStyle' => 'zero_with_o' } } it 'registers an offense for prefixes `0` and `0O`' do expect_...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/safe_navigation_chain_length_spec.rb
Ruby
mit
12,856
master
1,894
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::SafeNavigationChainLength, :config do let(:cop_config) { { 'Max' => max } } let(:max) { 2 } it 'registers an offense when exceeding safe navigation chain length' do expect_offense(<<~RUBY) x&.foo&.bar&.baz ^^^^^^^^^^^^^^^^ Avoid s...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/trailing_body_on_module_spec.rb
Ruby
mit
12,856
master
3,080
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::TrailingBodyOnModule, :config do let(:config) { RuboCop::Config.new('Layout/IndentationWidth' => { 'Width' => 2 }) } it 'registers an offense when body trails after module definition' do expect_offense(<<~RUBY) module Foo body ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/or_assignment_spec.rb
Ruby
mit
12,856
master
7,221
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::OrAssignment, :config do context 'when using var = var ? var : something' do it 'registers an offense with normal variables' do expect_offense(<<~RUBY) foo = foo ? foo : 'default' ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the double pi...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/auto_resource_cleanup_spec.rb
Ruby
mit
12,856
master
1,342
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::AutoResourceCleanup, :config do it 'registers an offense for File.open without block' do expect_offense(<<~RUBY) File.open("filename") ^^^^^^^^^^^^^^^^^^^^^ Use the block version of `File.open`. RUBY end it 'registers an offen...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/accessor_grouping_spec.rb
Ruby
mit
12,856
master
14,504
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::AccessorGrouping, :config do context 'when EnforcedStyle is grouped' do let(:cop_config) { { 'EnforcedStyle' => 'grouped' } } it 'registers an offense and corrects when using separated accessors' do expect_offense(<<~RUBY) class...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/return_nil_in_predicate_method_definition_spec.rb
Ruby
mit
12,856
master
12,213
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ReturnNilInPredicateMethodDefinition, :config do context 'when defining predicate method' do it 'registers an offense when using `return`' do expect_offense(<<~RUBY) def foo? return if condition ^^^^^^ Return `fal...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/and_or_spec.rb
Ruby
mit
12,856
master
17,873
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::AndOr, :config do context 'when style is conditionals' do cop_config = { 'EnforcedStyle' => 'conditionals' } let(:cop_config) { cop_config } { 'and' => '&&', 'or' => '||' }.each do |operator, prefer| it "accepts \"#{operator}\" out...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/begin_block_spec.rb
Ruby
mit
12,856
master
250
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::BeginBlock, :config do it 'reports an offense for a BEGIN block' do expect_offense(<<~RUBY) BEGIN { test } ^^^^^ Avoid the use of `BEGIN` blocks. RUBY end end
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/each_with_object_spec.rb
Ruby
mit
12,856
master
4,469
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EachWithObject, :config do it 'finds inject and reduce with passed in and returned hash' do expect_offense(<<~RUBY) [].inject({}) { |a, e| a } ^^^^^^ Use `each_with_object` instead of `inject`. [].reduce({}) do |a, e| ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/empty_case_condition_spec.rb
Ruby
mit
12,856
master
9,988
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EmptyCaseCondition, :config do shared_examples 'detect/correct empty case, accept non-empty case' do it 'registers an offense and autocorrects' do expect_offense(source) expect_correction(corrected_source) end let(:source_wit...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/env_home_spec.rb
Ruby
mit
12,856
master
1,505
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EnvHome, :config do it "registers and corrects an offense when using `ENV['HOME']`" do expect_offense(<<~RUBY) ENV['HOME'] ^^^^^^^^^^^ Use `Dir.home` instead. RUBY expect_correction(<<~RUBY) Dir.home RUBY end it...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/select_by_kind_spec.rb
Ruby
mit
12,856
master
13,233
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::SelectByKind, :config do shared_examples 'class check' do |method, correction| message = "Prefer `#{correction}` 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/module_function_spec.rb
Ruby
mit
12,856
master
3,546
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ModuleFunction, :config do context 'when enforced style is `module_function`' do let(:cop_config) { { 'EnforcedStyle' => 'module_function' } } it 'registers an offense for `extend self` in a module' do expect_offense(<<~RUBY) mo...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/multiline_in_pattern_then_spec.rb
Ruby
mit
12,856
master
3,795
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MultilineInPatternThen, :config do context '>= Ruby 2.7', :ruby27 do it 'registers an offense for empty `in` statement with `then`' do expect_offense(<<~RUBY) case foo in bar then ^^^^ Do not use `then` for mul...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/format_string_spec.rb
Ruby
mit
12,856
master
11,510
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::FormatString, :config do context 'when enforced style is sprintf' do let(:cop_config) { { 'EnforcedStyle' => 'sprintf' } } it 'registers an offense for a string followed by something' do expect_offense(<<~RUBY) puts "%d" % 10 ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/top_level_method_definition_spec.rb
Ruby
mit
12,856
master
3,157
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::TopLevelMethodDefinition, :config do it 'registers an offense top-level methods' do expect_offense(<<~RUBY) def foo; end ^^^^^^^^^^^^ Do not define methods at the top-level. RUBY end it 'registers an offense top-level class me...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/map_into_array_spec.rb
Ruby
mit
12,856
master
17,828
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MapIntoArray, :config do it 'registers an offense and corrects when using `each` with `<<` to build an array' do expect_offense(<<~RUBY) dest = [] src.each { |e| dest << e * 2 } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `map` instead of...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/dig_chain_spec.rb
Ruby
mit
12,856
master
6,457
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::DigChain, :config do it 'does not register an offense for unchained `dig` without a receiver' do expect_no_offenses(<<~RUBY) dig RUBY end it 'does not register an offense for `X::dig`' do expect_no_offenses(<<~RUBY) X::dig...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/empty_heredoc_spec.rb
Ruby
mit
12,856
master
2,032
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EmptyHeredoc, :config do it 'registers an offense when using empty `<<~EOS` heredoc' do expect_offense(<<~RUBY) <<~EOS ^^^^^^ Use an empty string literal instead of heredoc. EOS RUBY expect_correction(<<~RUBY) '' ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/class_vars_spec.rb
Ruby
mit
12,856
master
1,110
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ClassVars, :config do it 'registers an offense for class variable declaration' do expect_offense(<<~RUBY) class TestClass; @@test = 10; end ^^^^^^ Replace class var @@test with a class instance var. RUBY end i...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/it_block_parameter_spec.rb
Ruby
mit
12,856
master
9,365
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ItBlockParameter, :config do context '>= Ruby 3.4', :ruby34 do context 'EnforcedStyle: allow_single_line' do let(:cop_config) { { 'EnforcedStyle' => 'allow_single_line' } } it 'registers an offense when using multiline `it` parameters...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/conditional_assignment_assign_in_condition_spec.rb
Ruby
mit
12,856
master
38,756
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ConditionalAssignment, :config do shared_examples 'all variable types' do |variable| it 'registers an offense assigning any variable type to ternary' do expect_offense(<<~RUBY, variable: variable) %{variable} = foo? ? 1 : 2 ^...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_sort_by_spec.rb
Ruby
mit
12,856
master
2,257
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantSortBy, :config do it 'autocorrects array.sort_by { |x| x }' do expect_offense(<<~RUBY) array.sort_by { |x| x } ^^^^^^^^^^^^^^^^^ Use `sort` instead of `sort_by { |x| x }`. RUBY expect_correction(<<~RUBY) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/invertible_unless_condition_spec.rb
Ruby
mit
12,856
master
4,731
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::InvertibleUnlessCondition, :config do let(:cop_config) do { 'InverseMethods' => { :!= => :==, :even? => :odd?, :odd? => :even?, :>= => :<, :< => :>=, :zero? => :nonzero?, # non-standard...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/when_then_spec.rb
Ruby
mit
12,856
master
1,144
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::WhenThen, :config do it 'registers an offense for when b;' do expect_offense(<<~RUBY) case a when b; c ^ Do not use `when b;`. Use `when b then` instead. end RUBY expect_correction(<<~RUBY) case a ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/if_unless_modifier_spec.rb
Ruby
mit
12,856
master
43,592
# frozen_string_literal: true ###### # Note: most of these tests probably belong in the shared context "condition modifier cop" ###### RSpec.describe RuboCop::Cop::Style::IfUnlessModifier, :config do let(:allow_cop_directives) { true } let(:allow_uri) { true } let(:line_length_config) do { 'Enabled' =>...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/attr_spec.rb
Ruby
mit
12,856
master
2,434
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Attr, :config do it 'registers an offense attr' do expect_offense(<<~RUBY) class SomeClass attr :name ^^^^ Do not use `attr`. Use `attr_reader` instead. end RUBY end it 'registers an offense for attr within cla...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/semicolon_spec.rb
Ruby
mit
12,856
master
8,716
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Semicolon, :config do let(:cop_config) { { 'AllowAsExpressionSeparator' => false } } it 'registers an offense for a single expression' do expect_offense(<<~RUBY) puts "this is a test"; ^ Do not use semicolons to...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/encoding_spec.rb
Ruby
mit
12,856
master
3,648
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::Encoding, :config do it 'does not register an offense when no encoding present' do expect_no_offenses(<<~RUBY) def foo() end RUBY end it 'does not register an offense when encoding present but not UTF-8' do expect_no_offenses(<<...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/colon_method_call_spec.rb
Ruby
mit
12,856
master
1,756
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ColonMethodCall, :config do it 'registers an offense for instance method call' do expect_offense(<<~RUBY) test::method_name ^^ Do not use `::` for method calls. RUBY expect_correction(<<~RUBY) test.method_name RU...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_regexp_constructor_spec.rb
Ruby
mit
12,856
master
2,389
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantRegexpConstructor, :config do it 'registers an offense when wrapping `/regexp/` with `Regexp.new`' do expect_offense(<<~RUBY) Regexp.new(/regexp/) ^^^^^^^^^^^^^^^^^^^^ Remove the redundant `Regexp.new`. RUBY expect_co...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/trailing_comma_in_arguments_spec.rb
Ruby
mit
12,856
master
26,187
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::TrailingCommaInArguments, :config do shared_examples 'single line lists' do |extra_info| [%w[( )], %w[[ ]]].each do |start_bracket, end_bracket| context "with `#{start_bracket}#{end_bracket}` brackets" do it 'registers an offense for...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/empty_method_spec.rb
Ruby
mit
12,856
master
8,678
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::EmptyMethod, :config do context 'when configured with compact style' do let(:cop_config) { { 'EnforcedStyle' => 'compact' } } context 'with an empty instance method definition' do it 'registers an offense for empty method' do ex...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_conditional_spec.rb
Ruby
mit
12,856
master
3,232
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantConditional, :config do it 'registers an offense for ternary with boolean results' do expect_offense(<<~RUBY) x == y ? true : false ^^^^^^^^^^^^^^^^^^^^^ This conditional expression can just be replaced by `x == y`. RUBY ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_filter_chain_spec.rb
Ruby
mit
12,856
master
4,994
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantFilterChain, :config do let(:config) do RuboCop::Config.new('AllCops' => { 'ActiveSupportExtensionsEnabled' => false }) end %i[select filter find_all].each do |method| it "registers an offense when using `##{method}` followed by ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/multiline_if_then_spec.rb
Ruby
mit
12,856
master
2,840
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::MultilineIfThen, :config do it 'does not get confused by empty elsif branch' do expect_no_offenses(<<~RUBY) if cond elsif cond end RUBY end it 'registers an offense for then in multiline if' do expect_offense(<<~RUBY...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/redundant_heredoc_delimiter_quotes_spec.rb
Ruby
mit
12,856
master
4,936
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::RedundantHeredocDelimiterQuotes, :config do it 'registers an offense when using the redundant heredoc delimiter single quotes with `<<~`' do expect_offense(<<~RUBY) do_something(<<~'EOS') ^^^^^^^^ Remove the redundant here...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/class_and_module_children_spec.rb
Ruby
mit
12,856
master
16,921
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ClassAndModuleChildren, :config do context 'nested style' do let(:cop_config) { { 'EnforcedStyle' => 'nested' } } it 'registers an offense for not nested classes' do expect_offense(<<~RUBY) class FooClass::BarClass ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/conditional_assignment_assign_to_condition_spec.rb
Ruby
mit
12,856
master
54,655
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ConditionalAssignment, :config do let(:config) do RuboCop::Config.new('Style/ConditionalAssignment' => { 'Enabled' => true, 'SingleLineConditionsOnly' => true, 'IncludeT...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/parentheses_around_condition_spec.rb
Ruby
mit
12,856
master
7,896
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::ParenthesesAroundCondition, :config do let(:cop_config) { { 'AllowSafeAssignment' => true } } it 'registers an offense for parentheses around condition' do expect_offense(<<~RUBY) if (x > 10) ^^^^^^^^ Don't use parentheses around...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
spec/rubocop/cop/style/fetch_env_var_spec.rb
Ruby
mit
12,856
master
12,875
# frozen_string_literal: true RSpec.describe RuboCop::Cop::Style::FetchEnvVar, :config do let(:cop_config) { { 'AllowedVars' => [] } } context 'when it is evaluated with no default values' do it 'registers an offense' do expect_offense(<<~RUBY) ENV['X'] ^^^^^^^^ Use `ENV.fetch('X', nil)`...