Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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 使用rspec,如何测试以正确顺序接收哈希参数的方法?_Ruby_Rspec_Savon - Fatal编程技术网

Ruby 使用rspec,如何测试以正确顺序接收哈希参数的方法?

Ruby 使用rspec,如何测试以正确顺序接收哈希参数的方法?,ruby,rspec,savon,Ruby,Rspec,Savon,不幸的是,我需要与Soap API交互。如果这还不够糟糕的话,API已经打开了参数顺序,这意味着,不管它是XML,它都必须按照正确的元素顺序进行结构 我正在使用Savon,所以我正在构建一个有序散列。然而,经过一些重构之后,真正的调用停止了工作,而我的所有测试都继续通过。典型的测试如下所示: it 'should receive correctly ordered hash' do example_id = 12345789 our_api = Example::ApiGateway.n

不幸的是,我需要与Soap API交互。如果这还不够糟糕的话,API已经打开了参数顺序,这意味着,不管它是XML,它都必须按照正确的元素顺序进行结构

我正在使用Savon,所以我正在构建一个有序散列。然而,经过一些重构之后,真正的调用停止了工作,而我的所有测试都继续通过。典型的测试如下所示:

it 'should receive correctly ordered hash' do
  example_id = 12345789
  our_api = Example::ApiGateway.new()
  params = {:message=>{'ApiKey' => api_key, 'ExampleId' => example_id}}
  Savon::Client.any_instance.should_receive(:call).with(:get_user_details, params).and_return(mocked_response())
  our_api.get_user(example_id: example_id)
end
哈希比较完全不关心键的顺序,因此不管实际接收到的哈希顺序如何,此测试都会通过。我希望只获取
调用
方法接收的参数,然后我可以比较每个散列的有序键,但我找不到如何做到这一点


如何确保Savon调用以正确的顺序接收消息哈希?

因此在下一个google中我找到了答案
should\u receive
可以占用一个块,这样我就可以按照

it 'should receive correctly ordered hash' do
  example_id = 12345789
  our_api = Example::ApiGateway.new()
  params = {:message=>{'ApiKey' => api_key, 'ExampleId' => example_id}}
  Savon::Client.any_instance.should_receive(:call){ |arg1, arg2|
     arg1.should eq(:get_user_details)
     #Ensure order here manually
     arg2[:message].keys.should eq(params[:message].keys)
     mocked_response()
  }
  our_api.get_user(example_id: example_id)
end
现在我的测试会像预期的那样在钥匙被弄乱时中断,我可以花更多的时间来处理其他人脆弱的代码