Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a route does not exists in Rails 4

I deactivated the user registration (Gem Devise) and I want to make a test to be sure the route /users/sign_up does not exists.

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)>'
like image 450
John Smith Avatar asked Jun 27 '13 07:06

John Smith


2 Answers

Got similar issue. The solution is:

.1 Create spec/routing/users_routing_spec.rb

.2 Inside that 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
like image 93
jmarceli Avatar answered Sep 27 '22 21:09

jmarceli


From here:

The be_routable matcher is best used with should_not to specify that a given route should not be routable. It is available in routing specs (in spec/routing) and controller specs (in spec/controllers).

Inside a Capybara feature you could do:

scenario "could not register " do
  visit("/user/sign_up")
  expect(page.status_code).to be(404)
end
like image 24
toro2k Avatar answered Sep 27 '22 20:09

toro2k