Giter Site home page Giter Site logo

stub_env's People

Contributors

fatgeekuk avatar ljkbennett avatar sindrenm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

stub_env's Issues

version 1.0.0 `stub_env` is raising {} does not implement: stubbed?

I created a repo to reproduce the bug.

Reproduce

$ git clone [email protected]:jmoody/freezing-cyril.git
$ cd freezing-cyril
$ bundle install
$ bundle exec rspec spec/lib/launcher_spec.rb

Expected

An error not to be raised.

Found

   Failure/Error: stub_env('DEVICE_TARGET', 'device')
       {"RBENV_VERSION"=>"2.2.0",
          <snip>,
        "BUNDLE_ORIG_MANPATH"=>"/opt/local/share/man:"}
        does not implement: stubbed?

I accidentally stole this code

I had never seen this gem before today; have just come across it now.

Oops

I wrote a gem in 2018, called rspec-stubbed_env*, and I have to assume I used code from a gist, or a stack overflow, which had a solution for the problem of stubbing ENV in Ruby & RSpec. That solution had apparently been copied directly from your TestHelpers class, because aside from the class name and documentation the code is identical.

As evidence of this you can check my specs which are testing things at a wholly different level than your specs. I also wrapped the helpers inclusion in an RSpec shared_context. My documentation of usage is totally different from yours, though I may add your usage style as well, since it technically would work.

What now?

  • I will add appropriate copyright notice periods to the license (e.g. Copyright © 2014 LittlOwlLabs)
  • I am going to add you, @ljkbennett, as an author of the gem I created which uses your TestHelpers class, and note the origin in the documentation and the class file.
  • I am going to incorporate the fixes in the open PRs you have, and retain the name change, as it seems this gem isn't being maintained for the last few years. I already have a number of gems that depend on my version, and I plan to continue maintaining it.
  • Would be happy to merge projects over to your namespace (stub_env) if you want to add me as a maintainer.

* I am in the process of migrating my gem from Github to Gitlab.

Stubbing doesn't work with Hash#fetch

Soeh, it looks like Hash#fetch doesn't really call [] at all.

it "gets 'pokémanz' from WHATMON, not 'digimon'" do
  ENV["WHATMON"] = "digimon"
  stub_env "WHATMON", "pokémanz"
  expect(ENV.fetch("WHATMON")).to eq "pokémanz"
end

The result:

Failure/Error: expect(ENV.fetch("WHATMON")).to eq "pokémanz"

  expected: "pokémanz"
       got: "digimon"

  (compared using ==)

However, this passes as expected (notice I've changed fetch into [] syntax:

it "gets 'pokémanz' from WHATMON, not 'digimon'" do
  ENV["WHATMON"] = "digimon"
  stub_env "WHATMON", "pokémanz"
  expect(ENV["WHATMON"]).to eq "pokémanz"
end

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

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.