5

我停用了用户注册(Gem Devise),我想进行测试以确保该路线/users/sign_up不存在。

为此,我在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

当我运行这个测试时,我有这个错误:

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

2 回答 2

4

有类似的问题。解决方案是:

.1 创建spec/routing/users_routing_spec.rb

.2 在该文件中写入:

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
于 2014-11-10T00:53:29.357 回答
2

这里

be_routeable 匹配器最好与 should_not 一起使用,以指定给定路由不应该是可路由的。它可用于路由规范(在规范/路由中)和控制器规范(在规范/控制器中)。

在 Capybara 功能中,您可以执行以下操作:

scenario "could not register " do
  visit("/user/sign_up")
  expect(page.status_code).to be(404)
end
于 2013-06-27T08:22:34.100 回答