ljkbennett / stub_env

RSpec helper for stubbing ENV values
MIT License
33 stars 5 forks source link

Doesn't work with aws-sdk because it uses values_at #11

Open costi opened 4 years ago

costi commented 4 years ago

https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb#L62-L68

[13] pry(#<Ocr>)> ENV.values_at('AWS_REGION')
=> [nil]
[14] pry(#<Ocr>)> ENV['AWS_REGION']
=> "us-east-1"

values_at source code:

VALUE
rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
{
    VALUE result = rb_ary_new2(argc);
    long i;

    for (i=0; i<argc; i++) {
        rb_ary_push(result, rb_hash_aref(hash, argv[i]));
    }
    return result;
}

So rb_hash_aref seems to be unaffected by the stubs. https://github.com/ruby/ruby/blob/master/hash.c#L7552

    rb_define_method(rb_cHash, "[]", rb_hash_aref, 1);
pboling commented 1 year ago

Hi @costi and @Darhazer - I have a currently maintained hard fork of this gem over at rspec-stubbed_env:

I've already applied all fixes in Issues and PRs from this repository.

See https://github.com/pboling/rspec-stubbed_env for more.