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)>'
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With