Class: WebTsunami::Session
- Inherits:
-
Object
- Object
- WebTsunami::Session
- Defined in:
- lib/web_tsunami/session.rb
Overview
Session is a helper class to be used inside a scenario. It's purpose is to avoid low level manipulations to handle cookies and CSRF tokens automatically.
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
-
#root_url ⇒ Object
readonly
Returns the value of attribute root_url.
-
#scenario ⇒ Object
readonly
Returns the value of attribute scenario.
Instance Method Summary collapse
- #get(path, options = {}, &block) ⇒ Object
-
#initialize(scenario, root_url) ⇒ Session
constructor
A new instance of Session.
- #post(path, options = {}, &block) ⇒ Object
Constructor Details
#initialize(scenario, root_url) ⇒ Session
Returns a new instance of Session.
11 12 13 14 15 16 |
# File 'lib/web_tsunami/session.rb', line 11 def initialize(scenario, root_url) @scenario = scenario @root_url = root_url = {} @last_response = nil end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
9 10 11 |
# File 'lib/web_tsunami/session.rb', line 9 def end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
9 10 11 |
# File 'lib/web_tsunami/session.rb', line 9 def last_response @last_response end |
#root_url ⇒ Object (readonly)
Returns the value of attribute root_url.
7 8 9 |
# File 'lib/web_tsunami/session.rb', line 7 def root_url @root_url end |
#scenario ⇒ Object (readonly)
Returns the value of attribute scenario.
7 8 9 |
# File 'lib/web_tsunami/session.rb', line 7 def scenario @scenario end |
Instance Method Details
#get(path, options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/web_tsunami/session.rb', line 18 def get(path, = {}, &block) url = File.join(root_url, path) inject_headers(default_headers, ) scenario.get(url, ) do |response| @last_response = response (response) block&.call(response) end end |
#post(path, options = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/web_tsunami/session.rb', line 28 def post(path, = {}, &block) url = File.join(root_url, path) inject_headers(default_post_headers, ) inject_csrf_token() scenario.post(url, ) do |response| @last_response = response (response) block&.call(response) end end |