File: open_struct_spec.rb

package info (click to toggle)
ruby-rubocop-performance 1.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: ruby: 6,722; makefile: 8
file content (28 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Performance::OpenStruct do
  subject(:cop) { described_class.new(config) }

  let(:config) { RuboCop::Config.new }

  it 'registers an offense for OpenStruct.new' do
    expect_offense(<<~RUBY)
      OpenStruct.new(key: "value")
                 ^^^ Consider using `Struct` over `OpenStruct` to optimize the performance.
    RUBY
  end

  it 'registers an offense for a fully qualified ::OpenStruct.new' do
    expect_offense(<<~RUBY)
      ::OpenStruct.new(key: "value")
                   ^^^ Consider using `Struct` over `OpenStruct` to optimize the performance.
    RUBY
  end

  it 'does not register offense for Struct' do
    expect_no_offenses(<<~RUBY)
      MyStruct = Struct.new(:key)
      MyStruct.new('value')
    RUBY
  end
end