<commit_before># frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::SubjectStub do
  subject(:cop) { described_class.new }

  it 'complains when subject is stubbed' do
    expect_offense(<<-RUBY)
      describe Foo do
        subject(:foo) { described_class.new }

        before do
          allow(foo).to receive(:bar).and_return(baz)
          ^^^^^^^^^^ Do not stub your test subject.
        end

        it 'uses expect twice' do
          expect(foo.bar).to eq(baz)
        end
      end
    RUBY
  end

  it 'complains when subject is mocked' do
    expect_offense(<<-RUBY)
      describe Foo do
        subject(:foo) { described_class.new }

        before do<commit_msg>Use consistent wording in docstrings<commit_after># frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::SubjectStub do
  subject(:cop) { described_class.new }

  it 'flags when subject is stubbed' do
    expect_offense(<<-RUBY)
      describe Foo do
        subject(:foo) { described_class.new }

        before do
          allow(foo).to receive(:bar).and_return(baz)
          ^^^^^^^^^^ Do not stub your test subject.
        end

        it 'uses expect twice' do
          expect(foo.bar).to eq(baz)
        end
      end
    RUBY
  end

  it 'flags when subject is mocked' do
    expect_offense(<<-RUBY)
      describe Foo do
        subject(:foo) { described_class.new }

        before do
{'fraction_non_alphanumeric': 0.10263720598717035, 'fraction_numerical': 0.0, 'mean_word_length': 2.383132530120482, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5775280', 'n_tokens_mistral': 451, 'n_tokens_neox': 421, 'n_words': 119}