Check Route Does Not Exist in Rails 4

I have disabled user registration (Gem Devise) and I want to do a test to make sure that the route /users/sign_up does not exist.

To do this, I created a test in spec/features/user_spec.rb

 require 'spec_helper' require 'capybara/rspec' feature "Users" do scenario "could not register " do expect(:get => "/users/sign_up").not_to be_routable end end 

When I run this test, I have this error:

 1) Users could not register Failure/Error: expect(:get => "/users/sign_up").not_to be_routable NoMethodError: undefined method `routable?' for {:get=>"/users/sign_up"}:Hash # ./spec/features/user_spec.rb:8:in `block (2 levels) in <top (required)>' 
+4
source share
2 answers

From here :

The conjugate be_routable connector is best used with should_not to indicate that this route should not be routable. It is available in the routing specifications (in the specification / routing) and the controller specification (in the specification / controllers).

Inside the Capybara function you can do:

 scenario "could not register " do visit("/user/sign_up") expect(page.status_code).to be(404) end 
+2
source

A similar problem. Decision:

.1 Create spec/routing/users_routing_spec.rb

.2 Inside this file write:

 require "spec_helper" describe UsersController do describe "routing" do it "routes to #index" do expect(:get => "/users/sign_up").not_to be_routable end end 
+3
source

Source: https://habr.com/ru/post/1488433/


All Articles