在rspec中配置期望

时间:2018-09-27 08:15:59

标签: ruby rspec

我想用expect实现rspec。我尝试过:

RSpec:

describe WechatRequestBuilder do

  let(:request_builder) { described_class.new(env: 'test_env') }   
  let(:trx_types)       { ['wechat'] }
  let(:trx_type)        { 'wechat' }
  let(:gateway)         { 'wechat' }
  let(:currency)        { 'CNY' }
  let(:base_params)     { request_builder.send(:base_params) }

  it_behaves_like 'request builder', true   

  context '#submit!' do

    it "sends test transactions" do     
      allow(request_builder).to receive(:process_trx).with(trx_types, gateway)  
      binding.pry

      request_builder.submit! 
      expect(request_builder.submit!).to receive(:process_trx).with(trx_types, gateway)
    end
  end
end

请求修饰符:

class RequestModifier   
  def get_trx_type(request_body)
    doc = Nokogiri::XML(request_body)
    doc.search("transaction_type").first.text
  end
end

我试图找到一些具有binding.pry但没有运气的物体:

[1] pry(#<RSpec::ExampleGroups::WechatRequestBuilder::Submit>)> request_builder
=> #<WechatRequestBuilder:0x007ffc1af4fd80 @env="test_env", @request_modifier=#<RequestModifier:0x007ffc1af4fd30>>

基于上述代码,您能否举一些例子,我应该配置为“期望”吗?目前我得到:

(nil).process_trx(["wechat"], "wechat")
           expected: 1 time with arguments: (["wechat"], "wechat")
           received: 0 times

0 个答案:

没有答案