ljkbennett / stub_env Goto Github PK
View Code? Open in Web Editor NEWRSpec helper for stubbing ENV values
License: MIT License
RSpec helper for stubbing ENV values
License: MIT License
I created a repo to reproduce the bug.
$ git clone [email protected]:jmoody/freezing-cyril.git
$ cd freezing-cyril
$ bundle install
$ bundle exec rspec spec/lib/launcher_spec.rb
An error not to be raised.
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 had never seen this gem before today; have just come across it now.
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.
Copyright © 2014 LittlOwlLabs
)TestHelpers
class, and note the origin in the documentation and the class file.stub_env
) if you want to add me as a maintainer.* I am in the process of migrating my gem from Github to Gitlab.
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
[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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.