如何在控制器 RSpec 中测试 Devise,错误:未定义方法“分配”对于 #

发布于 2024-12-01 23:21:15 字数 1169 浏览 0 评论 0原文

我收到以下错误:

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

尝试测试 文档

这是我所拥有的:

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

建议?谢谢

I'm getting the following error:

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

When attempting to test per the docs.

Here's is what I have:

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

Suggestions? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

A君 2024-12-08 23:21:15

Rspec 发生了一些变化,现在使用分配

此处的文档

Rspec has changed a bit, it's now using assigns.

Doc here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文