Resource urls only work *after* a get() in controller spec

I’m encountering an interesting symptom during example execution. I’m
making a shared example group that dries up belongs-to-me before_filter
testing, and it makes a callback to the example group that says
it_should_behave_like that. The callback tells the shared example
where to expect a redirect for failure.

It seems that prior to
executing a get() (etc), the resource-based url functions aren’t
accessible. Following the get(), topics_url works fine. But before
then, it gives an error like this:

http://pastie.org/376096

Is
this a known issue? Is there a workaround I can use? I haven’t
stepped through get() to see what its doing that brings in the resource
functions, but if it’s not well-known, I can do so and followup with
the answer.

Thanks in advance,

Randy

[email protected] wrote:

http://pastie.org/376096

Is
this a known issue? Is there a workaround I can use?

For a workaround try doing a “include ActionController::UrlWriter” in
your shared example group.

-Ben

thanks, Ben - that didn’t do the trick, though.

I traced it down as far as this:

the controller hasn’t initialized its current url - that’s the immediate
cause of the method-on-nil complaint. It hasn’t, because the controller
isn’t technically handling a request yet (i.e., process()). I tried
monkey-patching the controller to allow me to call its
initialize_current_url to get around this, but I didn’t (yet) find how
to fake up its request and params sufficiently to have that work.

Understandably, the controller can’t know what the current url is,
unless rpsec-rails were to have a way to discover it from the example
group. I’m not sure that I’m proposing a change to a declarative style
for controller actions - for my purpose, I’d be satisfied to fake it to
think ‘index’ is the current url (in advance of processing the real
request as specified by get() and friends).

Hopefully this rings enough bells to make a workaround self-evident to
somebody. Anybody? Else I’ll see what I can dig up from the
rspec/rspec-rails source that can be enough of a resource.

Thanks,

Randy

----- Original Message ----