Steak, Warden (w/ Devise) + OAuth2

61 views
Skip to first unread message

Josep Mª Bach

unread,
Aug 24, 2010, 7:52:26 AM8/24/10
to Steak
Hey guys,

I am using Devise in my app to log in with OAuth2 (for Github) and
OpenID (for Google). The thing is, that since I'm not able to do a
manual login helper (like visit login_path; fill_in('login', :with =>
'user') etc), I tried to mock warden like I did before in some of my
controller tests in another app. But from steak scope I can't access
any "request" object to mock with. So how would be the best way to
test it?

Maybe manually creating a user and assigning it to current_user or
something like that? Seems odd to me, but it might be the simplest
solution, I don't know.

Thanks!

Pessoal

unread,
Aug 24, 2010, 9:53:53 AM8/24/10
to ste...@googlegroups.com
Maybe you could use something like fakeweb to simulate real api usage

Abraços,
Daniel Lopes


2010/8/24 Josep Mª Bach <josep....@gmail.com>

Luismi Cavallé

unread,
Aug 24, 2010, 10:55:58 AM8/24/10
to ste...@googlegroups.com
Hello,

I've never used Warden or Devise, and I don't know if you've already tried this, but there's a couple of things to can try:

http://wiki.github.com/hassox/warden/testing
http://wiki.github.com/plataformatec/devise/test-with-rails3-and-rspec

Just remember Steak features are ultimately regular RSpec specs.

And please, let us know your findings!

Cheers,

-- Luismi

Pessoal

unread,
Aug 24, 2010, 11:25:25 AM8/24/10
to ste...@googlegroups.com
Hello Luismi, 

I don't think it will work because in steak we don't have access to things like current controller (that we have in Rspec normal controllers specs). So try to stub things related to views and controllers will not work.

Cheers,
Daniel Lopes

Luismi Cavallé

unread,
Aug 24, 2010, 11:37:28 AM8/24/10
to ste...@googlegroups.com
If I'm not wrong in the first link it doesn't rely on the presence of a current controller. It looks more like an integration test. You might be right about the second link.

-- Luismi

Josep Mª Bach

unread,
Aug 25, 2010, 5:21:50 AM8/25/10
to Steak
Hello!

Thanks a lot Luismi, with the first link I got it up and running in no
time. I just did this:

feature "Home page:" do
include Warden::Test::Helpers

background do
@user = User.create(...) # Or use fixtures, factories or whatever,
even a stub user
login_as @user
visit home_page
end

...

after do
User.delete_all
Warden.test_reset!
end

end

And it works flawlessly. Moreover, it doesn't depend on which strategy
you use with Devise or whatever, since it affects only Warden! Great.

Thank you guys! Maybe this should be posted on the recently created
"Resources" page on steak repo! I bet this will save a lot of time to
many people ;)

Josep M. Bach

On 24 ago, 17:37, Luismi Cavallé <lmcava...@gmail.com> wrote:
> If I'm not wrong in the first link it doesn't rely on the presence of a current controller. It looks more like an integration test. You might be right about the second link.
>
> -- Luismi
>
> On Aug 24, 2010, at 5:25 PM, Pessoal wrote:
>
>
>
> > Hello Luismi,
>
> > I don't think it will work because in steak we don't have access to things like current controller (that we have in Rspec normal controllers specs). So try to stub things related to views and controllers will not work.
>
> > Cheers,
> > Daniel Lopes
>

Luismi Cavallé

unread,
Aug 25, 2010, 7:01:03 AM8/25/10
to ste...@googlegroups.com
Very nice! For additional convenience, I'd suggest this:

http://gist.github.com/549262

I've just linked that gist from the Resources wiki page.

Cheers!

-- Luismi

Reply all
Reply to author
Forward
0 new messages