Skip to content

Commit 3013459

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

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

spec/rspec/rails/example/rails_example_group_spec.rb

Lines changed: 24 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,30 @@ 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+
# rubocop:disable Lint/ConstantDefinitionInBlock
40+
class CurrentSample < ActiveSupport::CurrentAttributes
41+
attribute :request_id
42+
end
43+
# rubocop:enable Lint/ConstantDefinitionInBlock
44+
45+
it 'sets a current attribute' do
46+
CurrentSample.request_id = '123'
47+
expect(CurrentSample.request_id).to eq('123')
48+
end
49+
50+
it 'does not leak current attributes' do
51+
expect(CurrentSample.request_id).to eq(nil)
52+
end
53+
end
4754

48-
it 'does not leak current attributes' do
49-
expect(CurrentSample.request_id).to eq(nil)
50-
end
55+
expect(
56+
group.run(failure_reporter) ? true : failure_reporter.exceptions
57+
).to be true
5158
end
5259
end
5360
end

0 commit comments

Comments
 (0)