I\'m trying to get cookie values in the Cucumber step:
Step definitions
When /^I log in$/ do
#
Step Definitions
Then /^cookies should be set^/ do
Capybara
.current_session # Capybara::Session
.driver # Capybara::RackTest::Driver
.request # Rack::Request
.cookies # { "author" => "me" }
.[]('author').should_not be_nil
end
This works, however, I'm still looking for a less verbose way. Moreover, I'd like to know how to get the session data in a step definition.
Updated
To get the session data one should do the following:
Step Definitions
Then /^session data should be set$/ do
cookies = Capybara
.current_session
.driver
.request
.cookies
session_key = Rails
.application
.config
.session_options
.fetch(:key)
session_data = Marshal.load(Base64.decode64(cookies.fetch(session_key)))
session_data['author'].should_not be_nil
end
This is quite verbose too.