Skip to content

Commit

Permalink
Do not leak test specific globals into subsequent specs
Browse files Browse the repository at this point in the history
This controller actions spec leaks global state into subsequent specs that lead to very hard to debug spec errors.
  • Loading branch information
tvdeyen committed Feb 20, 2019
1 parent 3557b92 commit 9b9a315
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions spec/libraries/controller_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
end

context "with custom current_user_method" do
before do
around do |example|
Alchemy.current_user_method = 'current_admin'
example.run
Alchemy.current_user_method = 'current_user'
end

it "calls the custom method" do
Expand All @@ -37,16 +39,14 @@
end

context "with not implemented current_user_method" do
before do
around do |example|
Alchemy.current_user_method = 'not_implemented_method'
end

after do
example.run
Alchemy.current_user_method = 'current_user'
end

it "raises an error" do
expect{
expect {
controller.send :current_alchemy_user
}.to raise_error(Alchemy::NoCurrentUserFoundError)
end
Expand All @@ -60,6 +60,8 @@
after do
# We must never change the app's locale
expect(::I18n.locale).to eq(:en)
# Reset the current language so its fresh for every subsequent test
RequestStore.store[:alchemy_current_language] = nil
end

context "with a Language argument" do
Expand Down

0 comments on commit 9b9a315

Please sign in to comment.