在Rails 4控制器中使用时,处理问题测试的最佳方法是什么?说我有一个小问题Citations
.
module Citations
extend ActiveSupport::Concern
def citations ; end
end
Run Code Online (Sandbox Code Playgroud)
测试中的预期行为是包含此关注点的任何控制器都将获得此citations
端点.
class ConversationController < ActionController::Base
include Citations
end
Run Code Online (Sandbox Code Playgroud)
简单.
ConversationController.new.respond_to? :yelling #=> true
Run Code Online (Sandbox Code Playgroud)
但是,孤立地测试这种问题的正确方法是什么?
class CitationConcernController < ActionController::Base
include Citations
end
describe CitationConcernController, type: :controller do
it 'should add the citations endpoint' do
get :citations
expect(response).to be_successful
end
end
Run Code Online (Sandbox Code Playgroud)
不幸的是,这失败了.
CitationConcernController
should add the citations endpoint (FAILED - 1)
Failures:
1) CitationConcernController should add the citations endpoint
Failure/Error: get :citations
ActionController::UrlGenerationError:
No route matches {:controller=>"citation_concern", …
Run Code Online (Sandbox Code Playgroud) 使用Ruby API客户端,一个服务帐户,以及每天50k请求的"礼貌限制",我们在发出几百个请求后就开始看到这个错误.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "dailyLimitExceeded",
"message": "Quota Error: profileId ga:REDACTED has exceeded the daily request limit."
}
],
"code": 403,
"message": "Quota Error: profileId ga:REDACTED has exceeded the daily request limit."
}
}
Run Code Online (Sandbox Code Playgroud)
API控制台显示我们仅占配额的21%.前几天,当我们占配额的51%左右时,错误开始发生.
我们的用法从未如此激进: