Skip to content

Instantly share code, notes, and snippets.

@jaydorsey
Created January 26, 2024 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydorsey/9399a70759d636fb37c4c9708abb0e14 to your computer and use it in GitHub Desktop.
Save jaydorsey/9399a70759d636fb37c4c9708abb0e14 to your computer and use it in GitHub Desktop.
RSpec Rails.logger block test
# frozen_string_literal: true
class MyStuff
OOPS = 'Oops'
def self.call
Rails.logger.warn { OOPS }
end
end
# frozen_string_literal: true
RSpec.describe MyStuff do
let(:result) { described_class.call }
before do
allow(Rails.logger).to receive(:warn)
result
end
it 'logs a warning' do
expect(Rails.logger).to have_received(:warn) do |&block|
expect(block.call).to eq(MyStuff::OOPS)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment