Skip to content

Commit

Permalink
Add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
javierjulio committed Apr 9, 2024
1 parent 91167a0 commit 9e35e00
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions spec/rspec/rails/example/rails_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,20 @@ module RSpec::Rails
expect(results).to all be true
end

describe 'CurrentAttributes' do
let(:current_class) do
Class.new(ActiveSupport::CurrentAttributes) do
attribute :request_id
end
describe 'CurrentAttributes', order: :defined do
class Current < ActiveSupport::CurrentAttributes
attribute :request_id
end

it 'does not leak current attributes between example groups', if: ::Rails::VERSION::MAJOR >= 7 do
groups =
[
RSpec::Core::ExampleGroup.describe("A group") do
include RSpec::Rails::RailsExampleGroup
specify { expect(current_class.attributes).to eq({}) }
end,
RSpec::Core::ExampleGroup.describe("A controller group", type: :controller) do
specify do
current_class.request_id = "123"
expect(current_class.attributes).to eq(request_id: "123")
end
end,
RSpec::Core::ExampleGroup.describe("Another group") do
include RSpec::Rails::RailsExampleGroup
specify { expect(current_class.attributes).to eq({}) }
end
]

results =
groups.map do |group|
group.run(failure_reporter) ? true : failure_reporter.exceptions
end

expect(results).to all be true
it 'sets a current attribute' do
Current.request_id = '123'
expect(Current.request_id).to eq('123')
expect(Current.attributes).to eq(request_id: '123')
end

it 'does not leak current attributes' do
expect(Current.request_id).to eq(nil)
expect(Current.attributes).to eq({})
end
end
end
Expand Down

0 comments on commit 9e35e00

Please sign in to comment.