-
Notifications
You must be signed in to change notification settings - Fork 15
/
last_env.rb
45 lines (36 loc) · 925 Bytes
/
last_env.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
# Should be used with CapybaraInterceptor, see capybara_interceptor.rb in this directory.
#
# Gives access to last_session, last_env in feature specs. Handy for debugging intermittent
# failures. Reading last_session, last_env etc. in a feature spec isn't usually needed however,
# so consider aiming for minimal usage of this.
module LastEnv
def self.current=(env)
@current = env
end
def self.current
@current
end
def self.reset
@current = nil
end
def last_env
LastEnv.current
end
def last_session
# Or last_controller&.session
last_env['rack.session']
end
def last_request
last_controller&.request
end
def last_response
last_controller&.response
end
def last_controller
last_env['action_controller.instance']
end
end
RSpec.configure do |config|
config.include LastEnv, type: :feature
config.after(:each, type: :feature) { LastEnv.reset }
end