forked from rspec/rspec-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrails_example_group_spec.rb
60 lines (52 loc) · 2.06 KB
/
rails_example_group_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module RSpec::Rails
RSpec.describe RailsExampleGroup do
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
groups =
[
RSpec::Core::ExampleGroup.describe("A group") do
include RSpec::Rails::RailsExampleGroup
specify { expect(ActiveSupport::ExecutionContext.to_h).to eq({}) }
end,
RSpec::Core::ExampleGroup.describe("A controller group", type: :controller) do
specify do
Rails.error.set_context(foo: "bar")
expect(ActiveSupport::ExecutionContext.to_h).to eq(foo: "bar")
end
end,
RSpec::Core::ExampleGroup.describe("Another group") do
include RSpec::Rails::RailsExampleGroup
specify { expect(ActiveSupport::ExecutionContext.to_h).to eq({}) }
end
]
results =
groups.map do |group|
group.run(failure_reporter) ? true : failure_reporter.exceptions
end
expect(results).to all be true
end
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
# rubocop:disable Lint/ConstantDefinitionInBlock
class CurrentSample < ActiveSupport::CurrentAttributes
attribute :request_id
end
# rubocop:enable Lint/ConstantDefinitionInBlock
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
expect(
group.run(failure_reporter) ? true : failure_reporter.exceptions
).to be true
end
end
end