Peter Penzov
Peter Penzov

Reputation: 1646

undefined method `to_sym' when yaml file is stubbed

I have this rspec task which I would like to implement with stubbed config file:

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

I get error at this line:

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


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

Do you know how I can fix this issue?

Upvotes: 0

Views: 180

Answers (1)

TomDunning
TomDunning

Reputation: 4877

You've passed in config rather than :config to the expected call.

It should be:

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

Upvotes: 2

Related Questions