Skip to content

Commit f7440ad

Browse files
committed
Refactor spec for current attributes
1 parent d1a4c0d commit f7440ad

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

spec/rspec/rails/example/rails_example_group_spec.rb

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
module RSpec::Rails
22
RSpec.describe RailsExampleGroup do
3-
if ::Rails::VERSION::MAJOR >= 7
4-
class CurrentSample < ActiveSupport::CurrentAttributes
5-
attribute :request_id
6-
end
7-
8-
it 'supports tagged_logger' do
9-
expect(described_class.private_instance_methods).to include(:tagged_logger)
10-
end
3+
it 'supports tagged_logger', if: ::Rails::VERSION::MAJOR >= 7 do
4+
expect(described_class.private_instance_methods).to include(:tagged_logger)
115
end
126

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

40-
describe 'CurrentAttributes', order: :defined, if: ::Rails::VERSION::MAJOR >= 7 do
41-
include RSpec::Rails::RailsExampleGroup
34+
it 'will not leak ActiveSupport::CurrentAttributes between examples', if: ::Rails::VERSION::MAJOR >= 7 do
35+
group =
36+
RSpec::Core::ExampleGroup.describe("A group", order: :defined) do
37+
include RSpec::Rails::RailsExampleGroup
4238

43-
it 'sets a current attribute' do
44-
CurrentSample.request_id = '123'
45-
expect(CurrentSample.request_id).to eq('123')
46-
end
39+
class CurrentSample < ActiveSupport::CurrentAttributes
40+
attribute :request_id
41+
end
42+
43+
it 'sets a current attribute' do
44+
CurrentSample.request_id = '123'
45+
expect(CurrentSample.request_id).to eq('123')
46+
end
47+
48+
it 'does not leak current attributes' do
49+
expect(CurrentSample.request_id).to eq(nil)
50+
end
51+
end
4752

48-
it 'does not leak current attributes' do
49-
expect(CurrentSample.request_id).to eq(nil)
50-
end
53+
expect(
54+
group.run(failure_reporter) ? true : failure_reporter.exceptions
55+
).to be true
5156
end
5257
end
5358
end

0 commit comments

Comments
 (0)