gpt4 book ai didi

rspec - 检查 Rails 4 中不存在的路线

转载 作者:行者123 更新时间:2023-12-04 19:09:05 24 4
gpt4 key购买 nike

我停用了用户注册 (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)>'

最佳答案

有类似的问题。解决办法是:

.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

关于rspec - 检查 Rails 4 中不存在的路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17337639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com