title: Stub file in Ruby
body: <p>I have this ruby method that I would like to stub in rspec file:</p>
  
  <pre><code>  def load_environment_config(gateway, trx_type)
      @config = YAML.load_file("config/#{env}.yml")["#{env.upcase}"]
      raise "\n\nMissing gateway configuration for #{gateway} in file config/#{env}.yml!\n" unless @config[gateway]
      @terminal = terminal_for(@config, gateway, trx_type)
      @url = URI.parse("#{@config['processing_url']}#{@terminal['token']}")
    end
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>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(currency) }
  
    let(:yaml_file) { YAML::load(File.read(File.join('spec', 'fixtures', 'yaml', 'test_env.yml'))) }
    let(:config)    { yaml_file['TEST_ENV'] }
    let(:successful_response_file) { File.read(File.join('spec', 'fixtures', 'xml', 'successful_response.xml')) }
  
    allow(request_builder).to receive(:currency).and_return('EUR') 
    allow(request_builder).to receive(:env).and_return('TEST_ENV') 
    allow(request_builder).to receive(:config).and_return(config) 
    allow(request_builder).to receive(:base_params).and_return(base_params)
    allow(request_builder).to receive(:gateway).and_return(gateway)  
    allow(request_builder).to receive(:request_builder)
  </code></pre>
  
  <p>But when I run the rspec code I get this:</p>
  
  <pre><code>Errno::ENOENT:
         No such file or directory @ rb_sysopen - config/TEST_ENV.yml
       # ./models/request_builder.rb:50:in `load_environment_config'
       # ./models/request_builder.rb:45:in `filter_trx_types_list_for'
       # ./models/request_performer.rb:8:in `process_trx'
       # ./models/request_builders/girogate_request_builder.rb:81:in `block in submit!'
       # ./models/request_builders/girogate_request_builder.rb:80:in `each'
       # ./models/request_builders/girogate_request_builder.rb:80:in `submit!'
       # ./spec/models/request_builders/girogate_request_builder_spec.rb:42:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>My idea is to stub the variable config and use yaml file located into spec directory. What is the proper way to override <code>@config</code>? </p>