yaml文件存根时未定义的方法“ to_sym”

时间:2018-09-17 08:08:53

标签: ruby rspec

我有这个rspec任务,我想通过存根配置文件来实现:

let(:request_builder) { described_class.new(env: nil) } 
  let(:trx_types)       { ['davivienda'] }
  let(:trx_type)        { 'davivienda' }
  let(:gateway)         { 'girogate' }
  let(:currency)        { 'USD' }
  let(:base_params)     { request_builder.send(:base_params) }

  before(:each) { allow(request_builder).to receive(:currency).and_return('USD') }

  let(:yaml_file) { YAML::load(File.read(File.join('spec', 'fixtures', 'yaml', 'env.yml'))) }
  let(:config)    { yaml_file['SOF_DEV'] }

  context '#submit!' do

    it "sends test transactions" do

      allow(request_builder).to receive(config).and_return(config) 
      request_builder.submit!

      PAYMENT_TYPE_WITH_BASE_PARAMS.each do |x|
        expect(request_builder).te receive(:process_trx).with(factory(x), :gateway, :base_params)
      end
    end
  end

此行出现错误:

allow(request_builder).to receive(config).and_return(config) 


NoMethodError:
       undefined method `to_sym' for #<Hash:0x007f86484eb440>

您知道如何解决此问题吗?

1 个答案:

答案 0 :(得分:1)

您已将Array ( [0] => Invalid HTTP request method (GET) from [ip address here] - Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36) ) 而不是config传递给了预期的呼叫。

应该是:

:config