ice_age 0.1.3 → 0.2.1

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
  SHA256:
3
- metadata.gz: 5aef79cd00d3dff9d8ebc088e350e305a24138f1cdc9ac39a5c27e276f5a0f75
4
- data.tar.gz: 0afc51b74ef066ec4825c54d08638057d714efaa9a8e65417ffc871bba41500c
3
+ metadata.gz: 7276aef4fd57579f60d778064a82a3a0eb71b3392c25f590ae73b0497d3857f1
4
+ data.tar.gz: f0d4c7cf0ace0b56ab46cb5625cfafdf52ec130b29cf70682c659186a2a4d66e
5
5
  SHA512:
6
- metadata.gz: 7156d83c11ee7544b4a129e96a1dc64822ebc16a54cb056e0f96288c48bd0b892f4b83a40bd8759ee9bbd3680225057392e5185c47b87b4c2265ace4ca7fcb1c
7
- data.tar.gz: e578cb717cb0a2147b4d1e93b22222e25fe6f597600bacc03b2dc7358dc09e10e472e2d880c7bee5678e6b063cbe287c3653042256167a9ed1f711ee5ef0de4c
6
+ metadata.gz: 9ecf655a96c47c7d7a96ae92cff272ac5df1deb958edbf8e855a6fa6e0bb4dc9613c8c288724510e66869809ffa7679252b197df3c8df111b5e4b08fb2db8f74
7
+ data.tar.gz: b15f8878442a7ebc63a6bca1902641db99d88a8b0a5b82cfb49fb8e416640efda4a952d2738668d1cce80c5333e8d08650d2fd03fbbe0ea4f216e32235b3612c
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ ### v0.2.1 (2026-11-27)
2
+ - Requires Ruby 3.3 or newer.
3
+ - `endure!` detects deleted ENV variables.
4
+
5
+ ### v0.2.0 (2021-04-01)
6
+ - whitelist pry commands
7
+ - module conversion
8
+
9
+ ### v0.1.3 (2020-12-16)
10
+ - code cleaup
11
+ - codecov
12
+ - github-action (#4)
13
+ - improve gemspec
14
+ - upgrade changelog to md format
15
+ - safeguards
16
+ - travis-ci and codecov
17
+ - codebeat
18
+ - move repo: rb_ prefix => _rb suffix
19
+ - put readme usage examle into spec
20
+
21
+ ### v0.1.2 (2020-09-28)
22
+ - restore after, not before
23
+
24
+ ### v0.1.1 (2020-09-28)
25
+ - delay freeze
26
+
27
+ ### v0.1.0 (2020-09-13)
28
+ - freeze immediately
29
+
30
+ ### v0.0.2 (2020-09-13)
31
+ - auto freeze during before(:suite)
32
+ - improved endure! msg
33
+ - add examples
34
+
35
+ ### v0.0.1 (2020-09-04)
36
+ - initial launch
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Daniel Pepper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ IceAge
2
+ ======
3
+ ![Gem](https://img.shields.io/gem/dt/ice_age?style=plastic)
4
+ [![codecov](https://codecov.io/gh/dpep/ice_age_rb/branch/main/graph/badge.svg?token=S5F1PF9066)](https://codecov.io/gh/dpep/ice_age_rb)
5
+
6
+ Freeze your ENVironment during testing. ENV is reset after each test, making it trivial to maintain test isolation while testing your code with different environment variable values.
7
+
8
+
9
+ ## Install
10
+ ```ruby
11
+ # Gemfile
12
+ group :test do
13
+ gem 'ice_age'
14
+ end
15
+ ```
16
+
17
+
18
+ ## Usage
19
+ ```ruby
20
+ require 'ice_age'
21
+
22
+ describe 'Feature' do
23
+ context 'with new feature enabled' do
24
+ before { ENV['FEATURE_ENABLED'] = 'true' }
25
+
26
+ it { expect(ENV['FEATURE_ENABLED']).to eq 'true' }
27
+
28
+ # run tests against enabled feature
29
+ end
30
+
31
+ # ENV resets
32
+ it { expect(ENV['FEATURE_ENABLED']).to be_nil }
33
+
34
+ # run tests when feature is disabled
35
+ end
36
+ ```
37
+
38
+
39
+ #### Catch ENV changes at load time
40
+ ENV is frozen when the suite starts, so a change made while spec files load (outside a `before` or example block) leaks into every test. To catch these, freeze ENV earlier by requiring `ice_age/freeze` at the top of `spec_helper.rb`:
41
+
42
+ ```ruby
43
+ require 'ice_age/freeze'
44
+ ```
45
+
46
+ The suite then fails to start, listing each variable that changed after the freeze.
47
+
48
+
49
+
50
+ ## Inglorious Alternatives
51
+ ```ruby
52
+ before do
53
+ allow(ENV).to receive(:[]).and_call_original
54
+ allow(ENV).to receive(:[]).with('FEATURE_ENABLED').and_return('true')
55
+ end
56
+
57
+
58
+ before do
59
+ stub_const('ENV', ENV.to_hash.merge('FEATURE_ENABLED' => 'true'))
60
+ end
61
+
62
+
63
+ around do |example|
64
+ ENV['FEATURE_ENABLED'] = 'true'
65
+
66
+ example.run
67
+
68
+ ENV['FEATURE_ENABLED'] = nil
69
+ end
70
+
71
+
72
+ # https://github.com/thoughtbot/climate_control
73
+ around do |example|
74
+ ClimateControl.modify FEATURE_ENABLED: 'true' do
75
+ example.run
76
+ end
77
+ end
78
+
79
+
80
+ # https://github.com/ljkbennett/stub_env
81
+ before do
82
+ stub_env('FEATURE_ENABLED', 'true')
83
+ end
84
+ ```
85
+
86
+ ----
@@ -1,3 +1,3 @@
1
- class IceAge
2
- VERSION = '0.1.3'
1
+ module IceAge
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/ice_age.rb CHANGED
@@ -1,36 +1,40 @@
1
1
  require 'ice_age/version'
2
- require 'set'
3
2
 
4
- class IceAge
5
- class << self
3
+ module IceAge
4
+ extend self
6
5
 
7
- def freeze
8
- raise 'already frozen' if frozen?
6
+ def freeze
7
+ raise 'already frozen' if frozen?
9
8
 
10
- @env = ENV.to_h.freeze
11
- end
9
+ @env = ENV.to_h.freeze
10
+ end
12
11
 
13
- def frozen?
14
- !!@env
15
- end
12
+ def frozen?
13
+ !!@env
14
+ end
16
15
 
17
- def restore
18
- raise 'not frozen' unless frozen?
16
+ def restore
17
+ raise 'not frozen' unless frozen?
19
18
 
20
- ENV.replace(@env)
21
- end
19
+ ENV.replace(@env)
20
+ end
22
21
 
23
- def endure!
24
- raise 'not frozen' unless frozen?
22
+ def endure!
23
+ raise 'not frozen' unless frozen?
25
24
 
26
- changes = (Set.new(ENV.to_h) - Set.new(@env)).to_h.keys
27
- unless changes.empty?
28
- msg = changes.map {|k| { k => { @env[k] => ENV[k] } }}.to_s
29
- raise 'ENV changed after freeze: ' + msg
30
- end
25
+ changes = (ENV.keys | @env.keys).reject { |k| ENV[k] == @env[k] } - WHITELIST
26
+ unless changes.empty?
27
+ msg = changes.map {|k| { k => { @env[k] => ENV[k] } }}.to_s
28
+ raise 'ENV changed after freeze: ' + msg
31
29
  end
32
-
33
30
  end
31
+
32
+ WHITELIST = [
33
+ 'COLUMNS',
34
+ 'DISABLE_PRY',
35
+ 'LINES',
36
+ ].freeze
37
+ private_constant :WHITELIST
34
38
  end
35
39
 
36
40
  # load framework plugins
metadata CHANGED
@@ -1,59 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_age
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2020-12-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: codecov
13
+ name: debug
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
18
+ version: '1'
34
19
  type: :development
35
20
  prerelease: false
36
21
  version_requirements: !ruby/object:Gem::Requirement
37
22
  requirements:
38
23
  - - ">="
39
24
  - !ruby/object:Gem::Version
40
- version: '0'
25
+ version: '1'
41
26
  - !ruby/object:Gem::Dependency
42
- name: rake
27
+ name: rspec
43
28
  requirement: !ruby/object:Gem::Requirement
44
29
  requirements:
45
30
  - - ">="
46
31
  - !ruby/object:Gem::Version
47
- version: '0'
32
+ version: '3.10'
48
33
  type: :development
49
34
  prerelease: false
50
35
  version_requirements: !ruby/object:Gem::Requirement
51
36
  requirements:
52
37
  - - ">="
53
38
  - !ruby/object:Gem::Version
54
- version: '0'
39
+ version: '3.10'
55
40
  - !ruby/object:Gem::Dependency
56
- name: rspec
41
+ name: rspec-debugging
57
42
  requirement: !ruby/object:Gem::Requirement
58
43
  requirements:
59
44
  - - ">="
@@ -72,20 +57,22 @@ dependencies:
72
57
  requirements:
73
58
  - - ">="
74
59
  - !ruby/object:Gem::Version
75
- version: '0'
60
+ version: '1'
76
61
  type: :development
77
62
  prerelease: false
78
63
  version_requirements: !ruby/object:Gem::Requirement
79
64
  requirements:
80
65
  - - ">="
81
66
  - !ruby/object:Gem::Version
82
- version: '0'
67
+ version: '1'
83
68
  description: Freeze your ENVironment for testing.
84
- email:
85
69
  executables: []
86
70
  extensions: []
87
71
  extra_rdoc_files: []
88
72
  files:
73
+ - CHANGELOG.md
74
+ - LICENSE.txt
75
+ - README.md
89
76
  - lib/ice_age.rb
90
77
  - lib/ice_age/freeze.rb
91
78
  - lib/ice_age/rspec.rb
@@ -94,7 +81,6 @@ homepage: https://github.com/dpep/ice_age_rb
94
81
  licenses:
95
82
  - MIT
96
83
  metadata: {}
97
- post_install_message:
98
84
  rdoc_options: []
99
85
  require_paths:
100
86
  - lib
@@ -102,15 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
88
  requirements:
103
89
  - - ">="
104
90
  - !ruby/object:Gem::Version
105
- version: '0'
91
+ version: '3.3'
106
92
  required_rubygems_version: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  requirements: []
112
- rubygems_version: 3.0.8
113
- signing_key:
98
+ rubygems_version: 4.0.16
114
99
  specification_version: 4
115
100
  summary: IceAge
116
101
  test_files: []