Cannot override :type of specs in spec/routing in order to test external redirect scenarios #801

Closed
shyam-habarakada opened this Issue Aug 5, 2013 · 10 comments

4 participants

@shyam-habarakada

I have a route that does an external redirect, which I want to test like,

it "should route to the www site" do
  get "/some/path"
  response.should redirect_to("http://www.google.com")
end

There is apparently no standard way to test for redirects (see http://stackoverflow.com/questions/10842448/do-routing-specs-support-redirect-routes-rspec), which is why I am trying to use a request spec for this.

However, I'm unable to override the :type of my spec like,

describe "redirected routes", :type => :request do
  ...
end

This looks like a bug.

@JonRowe
RSpec member

I'm guessing the rspec-rails auto typing is happening later in the scope (or both are applying), so a workaround for this would be to place the spec in a different folder...

@shyam-habarakada

Yes, I worked around by putting it in spec/external_routing. The issue is about this being confusing. We should add something to the docs (or a feature) to make it clearer how to spec external redirects.

@JonRowe
RSpec member

Well I also feel you should be able to specify the type metadata regardless of any auto setup happening behind the scenes. A caveat could also be added to the documentation, but that's actually a Rails issue too (as it's there test helpers in use)

@alindeman

Docs welcomed as a PR, but I'm going to close this issue as I think everything is technically performing correctly.

@alindeman alindeman closed this Aug 8, 2013
@shyam-habarakada

Would you like me to update the README and send a pull request?

@alindeman

Sure!

@JonRowe
RSpec member

@alindeman are we concerned at all by the fact that the magic overrides manually set :type?

@myronmarston
RSpec member

FWIW, I'd advocate moving away from the auto-assignment of :type based on file location. I suggested an alternate approach in #662, and if we're going to move in that direction the 3.0 release is the time to do so.

@shyam-habarakada

Keeping with the rails way, it would be great if by default :type was derived based on location but does not overwrite an override that the spec author has put in.

@alindeman alindeman reopened this Aug 13, 2013
@alindeman alindeman closed this in #807 Oct 28, 2013
@shyam-habarakada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment