I\'m trying to get cookie values in the Cucumber step:
Step definitions
When /^I log in$/ do
#
Here is my code of step defenition:
Then /^cookie "([^\"]*)" should be like "([^\"]*)"$/ do |cookie, value|
cookie_value = Capybara.current_session.driver.request.cookies.[](cookie)
if cookie_value.respond_to? :should
cookie_value.should =~ /#{value}/
else
assert cookie_value =~ /#{value}/
end
end
Here is example of output when test fails:
expected: /change/
got: "/edit" (using =~)
Diff:
@@ -1,2 +1,2 @@
-/change/
+"/edit"
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:244:in `/^cookie "([^\"]*)" should be like "([^\"]*)"$/'
features/auth.feature:57:in `And cookie "go" should be like "change"'