Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用RSpec测试我的销毁操作?_Ruby On Rails_Ruby On Rails 3_Rspec_Rspec Rails - Fatal编程技术网

Ruby on rails 如何使用RSpec测试我的销毁操作?

Ruby on rails 如何使用RSpec测试我的销毁操作?,ruby-on-rails,ruby-on-rails-3,rspec,rspec-rails,Ruby On Rails,Ruby On Rails 3,Rspec,Rspec Rails,在my Rails应用程序中,如果用户想要删除自己的帐户,他必须首先在我的终止视图中输入密码: <%= form_for @user, :method => :delete do |f| %> <%= f.label :password %><br/> <%= f.password_field :password %> <%= f.submit %> <% end %> 问题是我似乎找不到一种方法来

在my Rails应用程序中,如果
用户
想要删除自己的帐户,他必须首先在我的
终止
视图中输入密码:

<%= form_for @user, :method => :delete do |f| %>

  <%= f.label :password %><br/>
  <%= f.password_field :password %>

  <%= f.submit %>

<% end %>
问题是我似乎找不到一种方法来用RSpec测试这一点

我所拥有的是:

describe 'DELETE #destroy' do

  before :each do
    @user = FactoryGirl.create(:user)
  end

  context "success" do

    it "deletes the user" do
      expect{ 
        delete :destroy, :id => @user, :password => "password"
      }.to change(User, :count).by(-1)
    end

  end

end
但是,这给了我一个错误:

ActionView::MissingTemplate:
Missing template users/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fa7f51310d8>"
ActionView::MissingTemplate:
缺少模板用户/destroy、应用程序/destroy和{:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder]}。搜索:
* "#"
有人能告诉我我在这里遗漏了什么,或者建议一个更好的方法来测试这个动作吗


谢谢您的帮助。

根据
默认情况下视图是存根的。因此,我认为您应该在测试方法中添加
controller.prepend\u view\u path'users/destroy'

首先我所说的是:

在销毁操作中,您有
params[:user][:password]
,但在测试中,您只提供
params[:id]
params[:password]


在控制器中,您在过滤器之前的
中创建
@user

谢谢,但不幸的是,这没有帮助。也许,添加
controller.prepend\u view\u path'app/views'
,文档中不清楚。可能存在重复的
ActionView::MissingTemplate:
Missing template users/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007fa7f51310d8>"