[rspec-users] cucumber/webrat, need to set user in session, can't stub or mock. Fixtures?

David Chelimsky dchelimsky at gmail.com
Mon Apr 27 16:27:29 EDT 2009

On Mon, Apr 27, 2009 at 3:09 PM, doug livesey <biot023 at gmail.com> wrote:
> Hi -- I'm assuming that there are excellent reasons for not enabling stubs &
> mocks in cucumber, but I find myself in a bit of a pickle without them.

Aslak and I were discussing this very thing earlier today. There are
definitely good reasons not to use message expectations (mocks - see
in cucumber, but stubs are different and we're thinking there should
be support for them.

I haven't tried this, but you should be able to do what RSpec does to
adapt to different mock/stub frameworks. To use rspec's, for example,
you should be able to say:

require 'spec/mocks/framework'
require 'spec/mocks/extensions'


Before do
  $rspec_stubs ||= Spec::Mocks::Space.new

After do

Now you *should* have the same mocking/stubbing methods you do in
rspec examples in cucumber step definitions, and the stubs get cleared
out after each scenario. See if that works, and then maybe we can
figure out a way to generalize rspec's mock-framework-adapter
framework so cucumber can use it as well (so you'd be able to stub w/
mocha, rr, flexmock, or any other).


> Basically, I want to write a feature that has the home page displaying if
> there is a logged in user (identified by a call to current_user, which in
> turn checks session[:user_id]), and that displays an unauthorised access
> page if there isn't.
> I guess normally, I'd have webrat walk through my app, including logging in?
> Unfortunately, the login doesn't happen in this application, though. It
> happens in another that shares state with this one, so I can't do this.
> Could someone advise how I can set up my scenario so that there is a valid
> user either in the session, or stubbed from the current_user?
> Would this be something to do with fixtures?
> If so, could someone point me at some docs that show me how to use them with
> cucumber?
> Thanks for any & all help,
>    Doug.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list