Do routing specs support redirect routes? [RSpec]

前端 未结 5 1649
暗喜
暗喜 2021-02-05 02:49

After digging fairly deeply on this issue, I\'ve come to an impasse between my understanding of the documentation and my results.

According to https://www.relishapp.com/

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 03:19

    I was running into a similar case where I was trying to test a series of routes, some which should redirect and some which shouldn't. I wanted to keep them in a single routing spec, since that was the most logical way to group them.

    I tried using describe: 'my route', type: request, but found that not to work. However, you can include RSpec::Rails::RequestExampleGroup in your spec context to gain access to the request spec methods. Something like:

    describe "My Routes" do
      context "Don't Redirect" do
        it "gets URL that doesn't redirect" do
          get("business_users/internal_url").should route_to(controller: "business_users", action: "internal_url_action")
        end
      end
    
      context "Redirection" do
        include RSpec::Rails::RequestExampleGroup
        it "redirects to google.com" do
          get "/business_users/1/external_url"
          response.should redirect_to("http://www.google.com")
        end
      end
    end
    

提交回复
热议问题