小编7ov*_*r21的帖子

如何使config.exceptions_app与rspec一起工作

在我的Rails 3.2应用程序中,我正在尝试使用config.exceptions_app通过路由表路由异常以呈现特定于错误的页面(尤其是401 Forbidden页面).这是我到目前为止配置的内容:

# application.rb
config.action_dispatch.rescue_responses.merge!('Error::Forbidden' => :forbidden)
config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) }

# development.rb
config.consider_all_requests_local       = false

# test.rb
config.consider_all_requests_local       = false
Run Code Online (Sandbox Code Playgroud)

现在问题的关键是:

module Error
  class Forbidden < StandardError
  end
end

class ErrorsController < ApplicationController
  layout 'error'

  def show
    exception       = env['action_dispatch.exception']
    status_code     = ActionDispatch::ExceptionWrapper.new(env, exception).status_code
    rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[exception.class.name]

    render :action => rescue_response, :status => status_code, :formats => [:html]
  end

  def forbidden
    render :status => :forbidden, :formats => [:html]
  end
end
Run Code Online (Sandbox Code Playgroud)

当我想渲染401响应时,我只是raise Error::Forbidden在开发环境中完美地工作.但是在rspec中运行示例时,例如:

it 'should return …
Run Code Online (Sandbox Code Playgroud)

rails-routing custom-exceptions rspec2 ruby-on-rails-3.2

5
推荐指数
1
解决办法
1357
查看次数

测试 redux-saga 的“all”效果的最佳方法是什么?

我有一个传奇,目前有一个yield all(...),我正在尝试找出如何测试以查看我实际上正在使用all()正确的函数进行调用。这是我正在使用的内容的精简版本:

\n\n
function* start() {\n  // I\'d prefer not to start the status polling and the listening for\n  // the cancellation until after the request has been submitted, but\n  // I\'m having trouble figuring out how to do that. So I\'m just going\n  // to listen for \'em all up front here until I\'m smarter.\n  yield all([\n    waitForCreateRequest(),\n    waitForPollStatus(),\n    waitForCancelRequest(),\n  ])\n}\n\nfunction* waitForCreateRequest() {\n  while ( true ) {  \n    try {\n      const { payload } …
Run Code Online (Sandbox Code Playgroud)

testing redux-saga

3
推荐指数
1
解决办法
2804
查看次数