Skip to content

Commit

Permalink
Refactor spec for current attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Apr 10, 2024
1 parent d1a4c0d commit f7440ad
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions spec/rspec/rails/example/rails_example_group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
module RSpec::Rails
RSpec.describe RailsExampleGroup do
if ::Rails::VERSION::MAJOR >= 7
class CurrentSample < ActiveSupport::CurrentAttributes
attribute :request_id
end

it 'supports tagged_logger' do
expect(described_class.private_instance_methods).to include(:tagged_logger)
end
it 'supports tagged_logger', if: ::Rails::VERSION::MAJOR >= 7 do
expect(described_class.private_instance_methods).to include(:tagged_logger)
end

it 'does not leak context between example groups', if: ::Rails::VERSION::MAJOR >= 7 do
Expand Down Expand Up @@ -37,17 +31,28 @@ class CurrentSample < ActiveSupport::CurrentAttributes
expect(results).to all be true
end

describe 'CurrentAttributes', order: :defined, if: ::Rails::VERSION::MAJOR >= 7 do
include RSpec::Rails::RailsExampleGroup
it 'will not leak ActiveSupport::CurrentAttributes between examples', if: ::Rails::VERSION::MAJOR >= 7 do
group =
RSpec::Core::ExampleGroup.describe("A group", order: :defined) do
include RSpec::Rails::RailsExampleGroup

it 'sets a current attribute' do
CurrentSample.request_id = '123'
expect(CurrentSample.request_id).to eq('123')
end
class CurrentSample < ActiveSupport::CurrentAttributes
attribute :request_id
end

it 'sets a current attribute' do
CurrentSample.request_id = '123'
expect(CurrentSample.request_id).to eq('123')
end

it 'does not leak current attributes' do
expect(CurrentSample.request_id).to eq(nil)
end
end

it 'does not leak current attributes' do
expect(CurrentSample.request_id).to eq(nil)
end
expect(
group.run(failure_reporter) ? true : failure_reporter.exceptions
).to be true
end
end
end

0 comments on commit f7440ad

Please sign in to comment.