Skip to content

Commit 91167a0

Browse files
authored
Add spec
1 parent 9089639 commit 91167a0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

spec/rspec/rails/example/rails_example_group_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,40 @@ module RSpec::Rails
3232

3333
expect(results).to all be true
3434
end
35+
36+
describe 'CurrentAttributes' do
37+
let(:current_class) do
38+
Class.new(ActiveSupport::CurrentAttributes) do
39+
attribute :request_id
40+
end
41+
end
42+
43+
it 'does not leak current attributes between example groups', if: ::Rails::VERSION::MAJOR >= 7 do
44+
groups =
45+
[
46+
RSpec::Core::ExampleGroup.describe("A group") do
47+
include RSpec::Rails::RailsExampleGroup
48+
specify { expect(current_class.attributes).to eq({}) }
49+
end,
50+
RSpec::Core::ExampleGroup.describe("A controller group", type: :controller) do
51+
specify do
52+
current_class.request_id = "123"
53+
expect(current_class.attributes).to eq(request_id: "123")
54+
end
55+
end,
56+
RSpec::Core::ExampleGroup.describe("Another group") do
57+
include RSpec::Rails::RailsExampleGroup
58+
specify { expect(current_class.attributes).to eq({}) }
59+
end
60+
]
61+
62+
results =
63+
groups.map do |group|
64+
group.run(failure_reporter) ? true : failure_reporter.exceptions
65+
end
66+
67+
expect(results).to all be true
68+
end
69+
end
3570
end
3671
end

0 commit comments

Comments
 (0)