简体   繁体   English

如何在Controller RSpec中测试Devise,错误:未定义的方法`assign&#39;for# <RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8>

[英]How to test Devise in a Controller RSpec, error: undefined method `assign' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8>

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 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 谢谢

Rspec has changed a bit, it's now using assigns . Rspec已经改变了一点,它现在正在使用assigns

Doc here . 在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 # 的未定义方法“get” <rspec::core::examplegroup::nested_1:0x00000106db51f8></rspec::core::examplegroup::nested_1:0x00000106db51f8> - undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000106db51f8> #的未定义方法`disallow_value&#39; <RSpec::Core::ExampleGroup::Nested_1:0x0000000a4b3a98> - undefined method `disallow_value' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000000a4b3a98> RSpec错误“ Rspec :: Core :: ExampleGroup :: Nested的未定义方法&#39;respond_to&#39;” - RSpec error “undefined method 'respond_to' for Rspec::Core::ExampleGroup::Nested” 失败/错误:访问movies_url NameError:#的未定义局部变量或方法“ movies_url” <RSpec::Core::ExampleGroup::Nested_1:0x007ff450c81800> - Failure/Error: visit movies_url NameError: undefined local variable or method `movies_url' for #<RSpec::Core::ExampleGroup::Nested_1:0x007ff450c81800> RSpec :: Core :: ExampleGroup :: Nested_2中未定义的方法&#39;it&#39; - undefined method `it' in RSpec::Core::ExampleGroup::Nested_2 未初始化常量 RSpec::Core::ExampleGroup::Nested_1::Factory - uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Factory RSpec:#的未定义方法“允许” - RSpec: undefined method `allow' for #<RSpec::Core::ExampleGroup::Nested RSpec 3未定义方法`允许&#39;为# <RSpec::Core::ExampleGroup…> - RSpec 3 undefined method `allow' for #<RSpec::Core::ExampleGroup…> 简单的Rspec长度验证测试-NoMethodError:#的未定义方法“之前” <RSpec::Core::ExampleGroup::Nested_2:0x007fb8a24bac00> - Simple Rspec Length Validation Test - NoMethodError: Undefined method `before' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fb8a24bac00> RSpec :: Core :: ExampleGroup:Class的未定义方法“ alias_example_to” - undefined method `alias_example_to' for RSpec::Core::ExampleGroup:Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM