gpt4 book ai didi

ruby-on-rails - 如何在 Controller RSpec 中测试设计,错误:未定义方法 `assign' for #

转载 作者:行者123 更新时间:2023-12-04 06:20:46 24 4
gpt4 key购买 nike

我收到以下错误:

undefined method `assign' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8>

尝试按照 the docs 进行测试时.

这是我所拥有的:

user_controller_spec.rb
require 'spec_helper'

describe "devise/sessions/new.html.erb" do
let(:user) do
stub_model(User).as_new_record
end

before do
assign(:user, user)
# Devise provides resource and resource_name helpers and
# mappings so stub them here.
@view.stub(:resource).and_return(user)
@view.stub(:resource_name).and_return('user')
@view.stub(:devise_mapping).and_return(Devise.mappings[:user])
end

it "renders a form to sign the user in" do
render
rendered.should have_selector("form",
:method => "post",
:action => user_session_path
) do |form|
form.should have_selector("input", :type => "submit")
end
end
end

建议?谢谢

最佳答案

Rspec 有所改变,现在使用 assigns .

Doc here .

关于ruby-on-rails - 如何在 Controller RSpec 中测试设计,错误:未定义方法 `assign' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7223391/

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