Hello!

I think the problem is that Rails itself, as far as I can see, does not
provide anyway of asserting against router redirects, both the request /
controller specs are using a different part of the Rails testing utils
that "run" the stack (or part of in the case of controller specs) which
allows them, and us, to assert on the response, (checking that its a
redirect).

Routing specs by contrast use the rails routing helpers
https://api.rubyonrails.org/v6.1.3.1/classes/ActionDispatch/Assertions/RoutingAssertions.html
under the hood which assert on how the router recognises routes. You'd
need to find a way to get them to assert a redirect to enable us to!

Cheers
Jon

On April 26, 2021, Goulven CHAMPENOIS <goulve...@gmail.com> wrote:
> Hello fellow testers,
> I'm adding tests to an app that needs to redirect a lot of legacy
> URLs, and was surprised that routing specs do not natively allow
> testing redirection.
> Since Rails `routes.rb` allows both routing _and_ redirecting, I
> presumed that routing specs would also handle both. I know controller
> and request specs handle redirection, but it feels weird to split
> tests like this, as it would lead to split my tests into request and
> routing specs though the path are very similar, and it's a functional
> unit.
> I was able to test redirection by including
> `RSpec::Rails::RequestExampleGroup` in my routing specs but that feels
> weird too, and the syntax is a little different: `get '/path'` versus
> `get: '/path'`.
> I'd feel more comfortable if I could natively write in the same
> file:```
> expect(get: '/blog/2018/01/slug').to route_to('posts#show')expect(get:
> '/cms/2018/01/slug').to redirect_to('/blog/2018/01/slug')```
> Is there a cleaner workaround, or is it something which could be added
> to rspec-rails?


> - Ruby version: 2.5.8
> - Rails version: 6.1.3.1
> - RSpec version: 3.10.1
> - RSpec-Rails version:5.0.1
>
>  --
>  You received this message because you are subscribed to the Google
> Groups "rspec" group.
>  To unsubscribe from this group and stop receiving emails from it,
> send an email to rspec+unsubscr...@googlegroups.com
> <mailto:rspec+unsubscr...@googlegroups.com>.
>  To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/e270ea61-5cdf-44ef-881c-
> 37db783e75dan%40googlegroups.com
> <https://groups.google.com/d/msgid/rspec/e270ea61-5cdf-44ef-881c-
> 37db783e75dan%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rspec+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/9da6c9367d5a1a2ccdae155e7692ff24519c2caa%40hey.com.

Reply via email to