strenv 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ea50a7c635563c02fa4d773f5ae03d0a2094051
4
- data.tar.gz: 6d3d41c921f2c1884dfbae1ee9ecb9f93a056729
3
+ metadata.gz: 551902e59c197db790faced972427d5b57c19deb
4
+ data.tar.gz: d39af32e84d01fe291851af6e6626ef85010ec63
5
5
  SHA512:
6
- metadata.gz: 4f138db3790030270a6800e904b797b1e3055a10229e23735d2c4f12ed1925be8267288dc7f201c055b1ec0c70a7c1eedf0a0f10fc9fa9d273ed69b1175602bd
7
- data.tar.gz: 4695da4923c2042d18a8a8ea8f6e505d07a929ed127557dff2880317bcfefe41b282d1b7232193e697d8db2b66676fa41ad5867d9c19ac0ee7f5350b3da49c73
6
+ metadata.gz: 3050cea82f79968f5c5c5cf29dcbfcd722dcaee687553331e8838d47fd67808a454a882d763def5a136b39a480506d0e1fdfeffd5aa2e27400600cdab7f88628
7
+ data.tar.gz: 73f8ae4d7844219957b245ea85eb92e83a03939b2c5a82179208ca20711680f3ddf89c49edc404e4a34a4fac7597bcf1e250ce29f12a3c2dc7fa204526751cb6
@@ -2,7 +2,7 @@
2
2
  # often go together. We avoid an extra item in the namespace
3
3
  # and an extra assignment.
4
4
  module STRICT_ENV
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  MalformedKey = Class.new(RuntimeError)
7
7
  MissingVariable = Class.new(RuntimeError)
8
8
 
@@ -16,7 +16,19 @@ module STRICT_ENV
16
16
  ENV[key]
17
17
  end
18
18
 
19
- # Run a block protecting the contents of the environment variables
19
+ # Run a block protecting the contents of the environment variables. This is especially useful for
20
+ # tests/specs that excercise methods that depend on environment variable state.
21
+ # Use this as a wrapper block in "around" aspects. For example, for RSpec:
22
+ #
23
+ # RSpec.configure do |c|
24
+ # c.around(:each) do |example|
25
+ # STRICT_ENV.with_protected_env { example.run }
26
+ # end
27
+ # end
28
+ #
29
+ # Note that this may play up with your editor features if it mutates environment variables
30
+ # based on the position in the script and it runs in the same environment as your objects
31
+ # under test (TextMate does this).
20
32
  def with_protected_env(&blk)
21
33
  preserved = ENV.to_h.dup
22
34
  yield
@@ -6,7 +6,24 @@ describe "STRICT_ENV" do
6
6
  expect(is_defined).to eq('constant')
7
7
  end
8
8
 
9
- context 'STRICT_ENV#[]' do
9
+ context 'STRICT_ENV.with_protected_env' do
10
+ it 'protects the ENV hash from modification' do
11
+ old_envars = ENV.to_h.dup
12
+ STRICT_ENV.with_protected_env do
13
+ old_envars.each_pair do |key, _|
14
+ r = "garbled-#{SecureRandom.hex(64)}"
15
+ ENV[key] = r # HAVOC!
16
+ expect(ENV[key]).to eq(r)
17
+ end
18
+ end
19
+
20
+ ENV.each_pair do | k, v|
21
+ expect(v).not_to match(/^garbled\-/), "#{k} should have been restored"
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'STRICT_ENV[]' do
10
27
  it 'proxies calls to [] to ENV' do
11
28
  ENV.keys.each do | key |
12
29
  expect(STRICT_ENV[key]).to eq(ENV[key])
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "strenv"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
12
- s.date = "2014-07-14"
12
+ s.date = "2014-07-15"
13
13
  s.description = "Creates a STRICT_ENV constant that you can query for environment variables and get meaningful exceptions"
14
14
  s.email = "me@julik.nl"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec