Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.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 如何让故事与restful_认证和cucumber一起工作?_Ruby On Rails_Rspec_Cucumber_Restful Authentication_Rspec Stories - Fatal编程技术网

Ruby on rails 如何让故事与restful_认证和cucumber一起工作?

Ruby on rails 如何让故事与restful_认证和cucumber一起工作?,ruby-on-rails,rspec,cucumber,restful-authentication,rspec-stories,Ruby On Rails,Rspec,Cucumber,Restful Authentication,Rspec Stories,克隆最新稳定版本的 (2.3.2) (1.2.2) (0.2.0.4…发表于2009年3月24日) (1.2.2) (修复了格式化的用户路径和一些其他问题) , (和其他一些人) 在一个干净的rails应用程序中,并遵循(我相信是)每个插件的所有说明,cucumber stories仍然失败:-(。以下是问题的摘要: 尽管创建了“map.root:controller=>“my_controller””路由,重定向仍无法立即工作: 这个调用不需要存根就可以使用这些方法吗 哦,我正在尝试运行a

克隆最新稳定版本的

  • (2.3.2)
  • (1.2.2)
  • (0.2.0.4…发表于2009年3月24日)
  • (1.2.2)
  • (修复了格式化的用户路径和一些其他问题)
  • ,
  • (和其他一些人)
在一个干净的rails应用程序中,并遵循(我相信是)每个插件的所有说明,cucumber stories仍然失败:-(。以下是问题的摘要:

  • 尽管创建了“map.root:controller=>“my_controller””路由,重定向仍无法立即工作: 这个调用不需要存根就可以使用这些方法吗
  • 哦,我正在尝试运行autospec,所以我执行了以下命令来启动它:

    export AUTOFEATURE=true rake spec:server:start ruby script/autospec export AUTOFEATURE=true rake规范:服务器:启动 ruby脚本/autospec
    我没有太多的指导,只有同情——我最近花了几个小时处理同样的问题。从好的方面来说,这就是我学习RSpec的方式

    有一件事我确实发现了,很多失败都是我无论如何都想改变的——例如,我不想在登录时重定向到“/”,而是在其他地方


    最后,一旦我找到了要查找的位置,大多数故障都很容易修复。

    我正在解决同样的问题。我还没有解决,但我认为ApplicationController.send(:public,:logged\u In?,:current\u user,:authorized?)需要改为进入support/env.rb。

    我不得不将user_steps.rb中注销函数的定义更改为:

    def注销
    获取“/注销”
    结束

    在它试图获取“/session/destroy”之前,只有在您不删除默认路由的情况下,它才会存在

    另外,请确保在应用程序控制器中包含“AuthenticatedSystem”


    不过,我仍在努力解决其他一些问题……

    我做了一些研究,以下是我得到的结果。
    ra\u response\u steps.rb
    expectredirect会变得粗糙,然后故事会定义是否应该遵循重定向。 此操作失败,因为Webrat会话实现具有以下代码:

    def request_page(url, http_method, data) #:nodoc: h = headers h['HTTP_REFERER'] = @current_url if @current_url debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect} and HTTP headers #{h.inspect}" if h.empty? send "#{http_method}", url, data || {} else send "#{http_method}", url, data || {}, h end save_and_open_page if exception_caught? && Webrat.configuration.open_error_files? raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code? reset @current_url = url @http_method = http_method @data = data if internal_redirect? check_for_infinite_redirects request_page(response_location, :get, {}) end return response end def请求页面(url、http方法、数据):nodoc: h=标题 h['HTTP\u REFERER']=@current\u url如果@current\u url debug#U log“请求页面:#{http#u method.to_s.upcase}#{url},带有#{data.inspect}和http头#{h.inspect}” 如果h是空的? 发送“#{http_method}”、url、数据||{} 其他的 发送“#{http_method}”,url,数据|{},h 结束 如果捕获到异常,请保存和打开页面&Webrat.configuration.open\u错误文件? raise PageLoadError.new(“页面加载未成功(代码:#{response_Code.inspect}):\n#{formatted_error}”),除非代码成功? 重置 @当前url=url @http\u方法=http\u方法 @数据=数据 如果内部用户重定向? 检查\u是否有\u无限\u重定向 请求页面(响应位置,:get,{}) 结束 返回响应 结束 请注意
    if internal_redirect?…end
    。这是一个使我们的测试失败的if,因为webrat正在跟踪重定向。 作为一种解决方法,您可以在webrat会话中对这些行进行注释,但这可能不是一个好的解决方案。我会做更多的工作,并在某个地方发布一个补丁。

    至于“受保护的方法”问题,我发现如果我不使用autospec并保留config.cache\u classes=true,那么测试就会通过

    将config.cache\u classes=false再次引入错误

    问题似乎在于rails中如何实现类缓存,或者rspec如何管理已创建的类。不幸的是,我没有足够的资源来进一步研究整个日志,并且似乎在以下位置对此进行了很好的讨论:

    我也遇到了上面提到的一些错误。但我的应用程序中出现的第一个问题是:

    多个步骤定义具有相同的Regexp:

    features/step_definitions/user_steps.rb:16:in
    /^(.*)(.*)名为“(.*)”$/”的用户
    features/step\u definitions/user\u steps.rb:29:in
    /^中没有名为“(.”的(.*)用户。 *)“$/”

    (多余的)

    当然,我可以解决这个问题,但是还会出现更多的错误(包括控制器上的受保护的logged_-in?方法、失败的rspec等等)


    有谁知道,我们是否都犯了一些根本性的错误?或者只是restful_认证在其当前版本中被破坏了?

    我发现这篇博客文章很好地解释了问题的症结:

    基本上,restful认证测试是尝试测试一些不应该使用webrat测试的东西。因此,上面建议的更改与我认为可能应该更改的相反

    我已经更改了Restful身份验证测试,这样它们就不会测试重定向,而只测试您最终到达的页面。但是,某些重定向似乎仍然存在问题,我不明白:

    Then she should be at the new session page                     # features/step_definitions/ra_response_steps.rb:15
      expected "session/new", got redirected to "http://www.example.com/session/new" (Spec::Expectations::ExpectationNotMetError)
    

    我不明白这个example.com是从哪里来的。还有其他人有类似的错误吗?

    哈哈……谢谢你的同情。不幸的是,我的学习速度比你慢,过去三天我一直在努力想办法解决这个问题……也许一整晚的睡眠不会有什么坏处。:-)不幸的是,下面的答案没有太大的帮助…有没有可能有人知道为什么至少出现了“受保护方法”错误?太棒了Hugo!非常感谢。这解决了问题的重定向部分。 def request_page(url, http_method, data) #:nodoc: h = headers h['HTTP_REFERER'] = @current_url if @current_url debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect} and HTTP headers #{h.inspect}" if h.empty? send "#{http_method}", url, data || {} else send "#{http_method}", url, data || {}, h end save_and_open_page if exception_caught? && Webrat.configuration.open_error_files? raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code? reset @current_url = url @http_method = http_method @data = data if internal_redirect? check_for_infinite_redirects request_page(response_location, :get, {}) end return response end
    Then she should be at the new session page                     # features/step_definitions/ra_response_steps.rb:15
      expected "session/new", got redirected to "http://www.example.com/session/new" (Spec::Expectations::ExpectationNotMetError)