ruby-on-rails – 使用设计应用程序测试错误

ruby-on-rails – 使用设计应用程序测试错误,第1张

概述当我将设计模块添加到我的rails应用程序时,我的测试会出错 73) Error:test_should_update_task(TasksControllerTest):ActionView::Template::Error: undefined method `authenticate' for nil:NilClass /home/razor/.gem/ruby/1.9.1/ge 当我将设计模块添加到我的rails应用程序时,我的测试会出错

73) Error:test_should_update_task(TasksControllerTest):ActionVIEw::Template::Error: undefined method `authenticate' for nil:NilClass    /home/razor/.gem/ruby/1.9.1/gems/devise-2.1.2/lib/devise/controllers/helpers.rb:56:in `current_user'    /home/razor/.gem/ruby/1.9.1/gems/devise-2.1.2/lib/devise/controllers/helpers.rb:52:in `user_signed_in?'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/abstract_controller/helpers.rb:53:in `user_signed_in?'    /home/razor/work/judgement/app/vIEws/layouts/application.HTML.erb:11:in `_app_vIEws_layouts_application_HTML_erb___67557477041607610_29516700'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/template.rb:145:in `block in render'    /home/razor/.gem/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications.rb:123:in `block in instrument'    /home/razor/.gem/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'    /home/razor/.gem/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications.rb:123:in `instrument'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/template.rb:143:in `render'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/renderer/template_renderer.rb:59:in `render_with_layout'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/renderer/template_renderer.rb:45:in `render_template'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/renderer/template_renderer.rb:18:in `render'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/renderer/renderer.rb:36:in `render_template'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_vIEw/renderer/renderer.rb:17:in `render'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/abstract_controller/rendering.rb:110:in `_render_template'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_controller/Metal/streaming.rb:225:in `_render_template'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/abstract_controller/rendering.rb:103:in `render_to_body'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_controller/Metal/renderers.rb:28:in `render_to_body'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_controller/Metal/compatibility.rb:50:in `render_to_body'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/abstract_controller/rendering.rb:88:in `render'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_controller/Metal/rendering.rb:16:in `render'    /home/razor/.gem/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_controller/Metal/instrumentation.rb:40:in `block (2 levels) in render'    /home/razor/.gem/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'93 tests,36 assertions,0 failures,73 errors,0 skipsErrors running test:functionals! #<RuntimeError: Command Failed with status (73): [/usr/bin/ruby19 -I"lib:test" -I"/usr/lib64...]>

application.HTML.erb的位置

<!DOCTYPE HTML><HTML>    <head>        <Title>Judgement</Title>        <%= stylesheet_link_tag    "application",:media => "all" %>        <%= JavaScript_include_tag "application" %>        <%= csrf_Meta_Tags %>    </head>    <body>        <nav>            <% if user_signed_in? then %>            <%= link_to "You are #{current_user.email}",edit_user_registration_path %>            <%= link_to "Exit",destroy_user_session_path,{ :method => :delete,:confirm => "Are you sure"} %>            <% else %>            <%= link_to "Sign In",new_user_session_path %>            <%= link_to "Register",new_user_registration_path %>            <% end %>        </nav>        <%= yIEld %>        <div >            <%= notice %>        </div>        <div >            <%= alert %>        </div>    </body></HTML>

所以这看起来像错误,因为“user_signed_in?”帮手.但我无法理解错误的重点.

我对所有Rails魔法都不太熟悉.

UPD:已解决

我必须补充一下

class ActionController::TestCase  include Devise::TestHelpersend

到我的test / test_helper.rb

解决方法 我建议使用这个功能: https://gist.github.com/989413.你的测试会更加孤立.在你的罐子里,你可以像这样存根:helper.stub(:user_signed_in?){false}.函数user_signed_in?应该根据需要返回true或false.

这里有一个类似的问题:Testing helpers in Rails 3 with Rspec 2 and Devise

编辑Test :: Unit

它认为你应该重新定义一个用Test :: Unit模拟的方法.像这样的东西:

module Devise  module Controllers    module Helpers          def user_signed_in?        true #Return false if you want      end    end  endend
总结

以上是内存溢出为你收集整理的ruby-on-rails – 使用设计应用程序测试错误全部内容,希望文章能够帮你解决ruby-on-rails – 使用设计应用程序测试错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1267781.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存