- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是在 Rails 4.0.11 上。我正在使用 minitest 和 webmock 为与 API 交互的工作人员编写测试。我的测试文件中有两个测试用例(到目前为止)。当我运行这两个测试时,第二个测试(标题中带有“成功”的测试)失败。当我注释掉通过的测试(标题中带有“重试”的测试)时,失败的测试用例通过了。测试用例似乎互相干扰,但我不知道如何干扰。
(我在这些代码示例中混淆了公司 secret 数据。嗨,老板!)
这是测试:
require 'test_helper'
class FoocorpCheckStatusWorkerTest < ActiveSupport::TestCase
REQUEST_HEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'text/xml', 'User-Agent'=>'Ruby'}
EXPECTED_BODY = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<POSBizServices xmlns=\"http://api.foocorp.com\">\n <POSBizServiceHeader>\n <userId>ABC</userId>\n <password>abc123</password>\n <clientId>123</clientId>\n <action>CHECKSTATUS</action>\n <responseFormat>XML</responseFormat>\n </POSBizServiceHeader>\n <request>\n <checkStatus>\n <ecpdId>123</ecpdId>\n <refNum>12345678</refNum>\n </checkStatus>\n </request>\n</POSBizServices>\n"
def sample_response_body(order_level_status_code: '', line_level_status_code: '')
return <<-SAMPLE_RESPONSE_BODY
<?xml version="1.0" encoding="UTF-8"?>
<POSBizServices xmlns="http://api.foocorp.com">
<POSBizServiceHeader>
<userId>ABC</userId>
<password>abc123</password>
<clientId>123</clientId>
<statusCode>#{order_level_status_code}</statusCode>
<statusDescription>2015-01-29 14:03:07 [QA13:MS_WSQA4_ONEPOS_01:01] : Request Processed Successfully</statusDescription>
<action>CHECKSTATUS</action>
<responseFormat>XML</responseFormat>
</POSBizServiceHeader>
<response>
<statusResponse>
<count>1</count>
<orderStatus>
<orderId>12345678</orderId>
<orderDate>01/27/2015</orderDate>
<stats>1,0</stats>
<aceOrderNo></aceOrderNo>
<locationCode></locationCode>
<lineInfoList>
<count>1</count>
<lineStatus>
<lineSeq>1</lineSeq>
<statusCode>#{line_level_status_code}</statusCode>
<statusDesc>No Status Yet.</statusDesc>
</lineStatus>
</lineInfoList>
</orderStatus>
</statusResponse>
</response>
</POSBizServices>
SAMPLE_RESPONSE_BODY
end
test "retry codes leave activity processor step in waiting state and activity in auto_processing state" do
activity_processor_step = activity_processor_steps(:vip_vm_password_reset_step)
activity = activity_processor_step.activity
FoocorpVipCheckStatusWorker::STATUS_CODE_MATRIX[:retry].each do |status_code_pair|
stub_request(:post, FOOCORP_VIP_CONFIG[:base_url]).
with(:body => /^.*$/,
:headers => REQUEST_HEADERS
).
to_return(:status => 200, :body => sample_response_body(order_level_status_code: status_code_pair.first, line_level_status_code: status_code_pair.last), :headers => {})
FoocorpVipCheckStatusWorker.new.perform
activity.reload
assert_equal("auto_processing", activity.state)
activity_processor_step.reload
assert_equal("waiting", activity_processor_step.state)
end
end
test "success codes complete activity and activity processor step" do
activity_processor_step = activity_processor_steps(:vip_vm_password_reset_step)
activity = activity_processor_step.activity
FoocorpVipCheckStatusWorker::STATUS_CODE_MATRIX[:success].each do |status_code_pair|
stub_request(:post, FOOCORP_VIP_CONFIG[:base_url]).
with(:body => /^.*$/,
:headers => REQUEST_HEADERS
).
to_return(:status => 200, :body => sample_response_body(order_level_status_code: status_code_pair.first, line_level_status_code: status_code_pair.last), :headers => {})
FoocorpVipCheckStatusWorker.new.perform
activity.reload
assert_equal("completed", activity.state)
activity_processor_step.reload
assert_equal("completed", activity_processor_step.state)
end
end
end
这是 worker :
class FoocorpVipCheckStatusWorker
@queue = :short_running
# Foocorp VIP returns an order-level status code and description
# and a line-level status code and description. The comments describing
# the status codes in STATUS_CODE_MATRIX are from Foocorp's Docs.
#
# Array format for status codes is:
# ["(order-level status code)", "(line-level status code)"]
STATUS_CODE_MATRIX = {
:success => [
["00057", "00051"] # Request Processed Successfully
],
:retry => [
["00057", "00053"], # No Status Yet
["00057", "00054"], # Order processed successfully but activation is pending.
["00099", ""], # Unexpected error occurred during processing e.g. null pointer exception which causes thread to terminate.
["00059", ""], # Server time out occurred.
["10009", ""], # Back End call returned invalid agent data.
["10010", ""], # Application fails to load ECPD profile details.
["00058", "10013"], # Backend calls fails to load Billing information for account. It may be due to some internal issue.
["00058", "10032"], # Exception occurred in Bulk Service write
["00058", "10033"], # Error occurred in Bulk Service write for reassign
["00058", "10040"], # Sub Account create failed
["00058", "10144"] # UNABLE TO RETRIEVE CREDIT INFORMATION
]
}
def perform
ActivityProcessorStep.where(state: "waiting").where("vip_ref_num IS NOT NULL").each do |activity_processor_step|
client = Remote::Clients::FoocorpVipClient.new(
:params => {
:ecpd_id => activity_processor_step.activity.carrier_account.parent_account.api_access_id,
:vip_ref_num => activity_processor_step.vip_ref_num
}
)
response = client.check_status
#TODO: Remove debugging code
#binding.pry
order_status_code = response.first[:order_status_code]
order_status_desc = response.first[:order_status_desc]
line_status_code = response.last[:line_status_code]
line_status_desc = response.last[:line_status_desc]
status_codes = [order_status_code, line_status_code]
response_message = line_status_desc.present? ? line_status_desc : order_status_desc
response_message ||= "No status description given"
success = STATUS_CODE_MATRIX[:success].detect{ |codes_array| codes_array == [order_status_code, line_status_code]}.present?
retry_status_check = STATUS_CODE_MATRIX[:retry].detect{ |codes_array| codes_array == [order_status_code, line_status_code]}.present?
stale_request = retry_status_check && Time.now > (activity_processor_step.created_at + activity_processor_step.days_to_expire.days)
if success
activity_processor_step.update_activity_status('Complete', nil, nil, response_message)
elsif stale_request
activity_processor_step.update_activity_status('Failure', nil, nil, "Activity processor step expired.")
elsif !retry_status_check
activity_processor_step.update_activity_status('Failure', nil, nil, response_message)
end
end
end
end
这是我的终端输出:
运行两个测试用例:
me@domo-kun ~/my-project (feature_foocorp_check_status_worker=)$ be rake test TEST=test/workers/foocorp_check_status_worker_test.rb
Run options: --seed 58882
# Running tests:
.F
Fabulous tests in 2.009658s, 0.9952 tests/s, 11.4447 assertions/s.
1) Failure:
FoocorpCheckStatusWorkerTest#test_success_codes_complete_activity_and_activity_processor_step [/Users/steven/Development/my-company/my_company/test/workers/foocorp_check_status_worker_test.rb:86]:
Expected: "completed"
Actual: "auto_processing"
2 tests, 23 assertions, 1 failures, 0 errors, 0 skips
注释掉第一个(“重试”)测试用例:
me@domo-kun ~/my-project (feature_foocorp_check_status_worker=)$ be rake test TEST=test/workers/foocorp_check_status_worker_test.rb
Run options: --seed 14937
# Running tests:
.
Fabulous tests in 3.474386s, 0.2878 tests/s, 0.5756 assertions/s.
1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
当我一起运行两个测试并在工作线程中使用 binding.pry
(此处注释掉)来检查“成功”测试用例期间 response
的值时(失败的),我得到以下两个结果。我期望在这两种情况下得到相同的结果(第二个)。
运行两个测试用例:
[1] pry(#<VerizonVipCheckStatusWorker>)> response
=> [{:order_status_code=>"00057",
:order_status_desc=>"",
:_summary=>{:order_status_code=>"00057", :order_status_desc=>""}},
{:line_status_code=>"00053",
:line_status_desc=>"No Status Yet.",
:_summary=>{}}]
注释掉第一个(“重试”)测试用例:
[2] pry(#<VerizonVipCheckStatusWorker>)> response
=> [{:order_status_code=>"00057",
:order_status_desc=>"",
:_summary=>{:order_status_code=>"00057", :order_status_desc=>""}},
{:line_status_code=>"00051",
:line_status_desc=>"No Status Yet.",
:_summary=>{}}]
最后一个示例中的响应值是我期望在“重试”测试用例的第一次迭代期间的值,而不是在“成功”情况下的值。
我尝试将设置方法中的内容移至您在此处看到的常量和 sample_response_body
方法中。我也尝试添加此拆卸方法,但没有帮助:
def teardown
WebMock.reset!
end
我正在从头开始编写工作程序和测试,因此完全有可能在某个地方出现愚蠢的语法/逻辑错误。我为这个可能过于冗长的问题表示歉意,但这确实让我抓狂。感谢您的帮助。谢谢。
最佳答案
事实证明,我正在适配器类中缓存我的响应,因此它忽略了 WebMock 提供的响应。
关于unit-testing - 一个测试用例似乎干扰了另一测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28307346/
这是我的 + 部分: function insert(){ var linkElement = document.getElementById("BackButton"); var linkEl
我有两辆 buggy 在轨道上移动,它们都使用超声波测量模块来检测路径中的障碍物,并由 Arduino 微 Controller 控制。两个超声波传感器以相同的频率工作,并且这个频率不能改变。两个超声
希望能快速解决这个问题。我有一个用文件位置替换特定值的脚本。不幸的是,该位置似乎经常包含\n 或 n\(因为当前目录位于临时文件夹中),导致该行中断或从该行中完全删除自身,从而使文件夹位置无效。 临时
我使用的是 Mac OSX 10.10.1。我通常使用brew或pip来安装所有东西。我注意到我的 virtualenv 总是抓取我本地安装的所有 Python 包。我通过删除我的 $PYTHONPA
我正在尝试使用 str_replace 将两个字母的语言缩写转换为完整的单词。我遇到的问题是它们在回显时会相互影响。 $lang = str_replace("en", "English", $lan
我已经创建了用于结束通话的 aidl 文件 ITelephony.aidl。现在,在通话结束之前,我需要生成正在进行的通话中的语音,以便听众认为接下来的工作有问题。我尝试通过三种方式自己解决这个问题:
使用这个查询,我得到了我需要的每个客户下的订单数量的结果。但是,当我在 SELECT 字段中使用 SUM(OrderLine.ActualPrice) 并使用内部联接将 Order 表链接到包含价格的
在 Spring Boot 应用程序中,仅使用注释,我想实现安全性 我已将 @EnableGlobalMethodSecurity(jsr360Enabled=true) 添加到配置类。该类还有一个
我一直在 Linux 下开发一个多线程程序,对信号处理有特殊要求。例如,我需要程序打印单个 Ctrl-C 输入的统计信息。 我使用 pthread_sigmask 和 sigwait 实现了这一点,即
作为我第一次涉足 Dynamic Scala 领域,我想我会尝试通过 applyDynamic 访问 bean 属性。 我的第一个非常粗略的剪裁是 trait BeanProperties ext
我知道这是一个令人沮丧的话题,但我尝试遵循文档和其他类似的帖子。 我的问题是,除非重新加载页面,否则 JS 将无法工作。 我有以下 JS: $(function() { $('a.form-sho
我正在使用 JQuery Ajax 从服务器获取脚本。 $.ajax({ url: src, type: "GET", dataType: "script", time
我正在尝试根据每个产品的选定数量分别输出计算价格。我尝试复制代码并重命名所有变量,但输出是由各种增加/减少按钮触发的。 这是目前的代码: $(".incr-btn_mobile").on("click
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: jQuery in Greasemonkey 1.0 conflicts with websites usi
我在一个 iOS 应用程序 (Obj-C) 中有一个 View ,它在中心有一个 ImageView ,紧接着在其下方有一个 slider 。 ImageView 显示专辑封面, slider 可用于
我有一个 View Controller ,将 UITapGestureRecognizer 附加到它的主 UIView,并使用户能够点击屏幕以使状态、导航和工具栏重新出现/消失(如照片应用程序)。我
我正在尝试在我的应用程序中设置 log4j,但我的一个第三方 JAR 似乎以某种方式不断将我的日志级别设置为“关闭”。它仅在执行该库中的代码时发生。我不知道它是如何做到这一点的,因为我没有使用它知道名
我有一个 UIScrollView,其框架与包含的 View Controller 相同。 当 ScrollView 的缩放比例大于 1 时,从屏幕左侧 50% 开始从左向右滑动会导致 interac
我是网页设计的新手,最近接触了 Bootstrap。我最近也开始使用 Codepen。在 Codepen 中完成一个元素后,我将代码从那里复制并粘贴到 Sublime 中,无论出于何种原因,它更改了我
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我是一名优秀的程序员,十分优秀!