以下是我尝试规范的观点:
%h2 Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= devise_error_messages!
%br= f.label :email
%br= f.email_field :email, autofocus: true
%br= f.label :password
%br= f.password_field :password, autocomplete: 'off'
%br= f.label :password_confirmation
%br= f.password_field :password_confirmation, autocomplete: 'off'
= f.submit 'Sign up'
= render 'devise/shared/links'
这是我的规格:
require 'spec_helper'
describe 'devise/registrations/new', js: true, type: :view do
it 'has a name field' do
render
rendered.should contain('Email')
end
end
返回错误undefined local variable or method 'resource'
。
我当时正在等待。我需要存根变量。
将它放在渲染函数之前:
expect(view).to receive(:resource).and_return(stub_model(User))
结果:
An error occurred in an `around(:example)` hook
NoMethodError: undefined method `method_removed' for #<User not initialized>
occurred at /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activemodel-4.1.1/lib/active_model/attribute_methods.rb:435:in `method_missing'
和
does not implement: resource
我认为这意味着视图没有实现资源......