Cucumber + Capybara + cookies

223 views
Skip to first unread message

Randy Schmidt

unread,
Apr 29, 2010, 4:49:25 PM4/29/10
to Philly.rb
Oh how I wish "cucumber cookies" weren't a real thing. It makes
googling for an answer kinda hard.

I'm starting to use Cucumber + Capybara on a site that authenticates
with a single-sign-on server. I don't really want to test that aspect
(at least yet) so I want to do everything but reach out to the profile
server. It turns out that if I have a cookie[:user_id] with the id of
a user in the database, I don't need to reach out to the server. I've
tried everything I can think of (and googled) to be able to set a
cookie in the step definition that will get used in the controller but
it isn't working.

Anybody have experience with kind of thing? Any suggestions?

Thanks!
--
Forge38 LLC
Randy Schmidt
ra...@forge38.com
http://forge38.com
267-334-6833

--
You received this message because you are subscribed to the Google Groups "Philly.rb" group.
To post to this group, send email to phil...@googlegroups.com.
To unsubscribe from this group, send email to phillyrb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/phillyrb?hl=en.

John Trupiano

unread,
Apr 29, 2010, 4:59:35 PM4/29/10
to phil...@googlegroups.com
On Thu, Apr 29, 2010 at 4:49 PM, Randy Schmidt <m...@r38y.com> wrote:
Oh how I wish "cucumber cookies" weren't a real thing. It makes
googling for an answer kinda hard.

Try using negative keywords: cucumber cookies -food -recipe -photos

-John

Mat Schaffer

unread,
Apr 29, 2010, 5:26:57 PM4/29/10
to phil...@googlegroups.com
Have you tried making a dev-only controller/action in the app that
sends out the cookie?

This is basically a mock profile server.

Kfitz wrote one of those to support cucumber testing at CIM and as I
understand it worked out well.

-Mat

Randy Schmidt

unread,
Apr 29, 2010, 5:41:35 PM4/29/10
to phil...@googlegroups.com
Haha, I was just coming back to this to say that I did this:

class StubUserSessionsController < ApplicationController
def new
user = User.find_by_username(params[:username])
unless user.blank?
cookies[:sat] = params[:username]
cookies[:user_id] = user.id
end
redirect_to root_url
end
end

ActionController::Routing::Routes.draw do |map|
map.stub_log_in '/stub_log_in/:username', :controller =>
'stub_user_sessions', :action => 'new'
end

Thanks for the suggestion and confirmation that it isn't too much of a hack :P

Cheers!

Randy Schmidt

unread,
Apr 29, 2010, 5:43:31 PM4/29/10
to phil...@googlegroups.com
Oh, to be clear, I added that to env.rb so it didn't cruft up the real
app. Working like a charm!!

Kevin Fitzpatrick

unread,
Apr 29, 2010, 5:45:46 PM4/29/10
to phil...@googlegroups.com
Try the Capybara list, too. I remember talking to Jonas about this and he didn't think it was a problem. That being said I have absolutely no idea what the syntax is.

---------------------

Kevin Fitzpatrick
@kfitzpatrick
267.254.6225
Reply all
Reply to author
Forward
0 new messages