Ruby on rails 如何使用RSpec测试我的销毁操作?
在my Rails应用程序中,如果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 %> 问题是我似乎找不到一种方法来
用户
想要删除自己的帐户,他必须首先在我的终止
视图中输入密码:
<%= 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>"