ice_age 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2760620f23a7e61b8158f31fa1eb1aa903136ccca5a37c38c079e018cdaeb294
4
+ data.tar.gz: c046715ad5d668eef9dab818237c0088da05e6a68ef39ac6c60a41f1f5d991ea
5
+ SHA512:
6
+ metadata.gz: 49310d47cd6aea17abf6a6edd4553a05ee4fa101d91af64bef0d309e322aa6bed3e205934fa7d293b3f33f2d4222ba6ef9b2447a5b8ada0a2cb0ce54946feaef
7
+ data.tar.gz: 606b8cdcb9b612dfcb615ebf58a0f1f4be5d88df910e977a8d98ccdc56ad2d2dc68aae882712c03bcbde73466fbe38a41f82dd5dddb229c6462c92059aaa6b06
@@ -0,0 +1,35 @@
1
+ require 'set'
2
+
3
+ class IceAge
4
+ VERSION = '0.0.1'
5
+
6
+ class << self
7
+ def restore
8
+ raise "#{self.class.name}.frozen never called!" unless @env
9
+
10
+ ENV.clear.update(@env)
11
+ end
12
+
13
+ def changes
14
+ (Set.new(ENV.to_h) - Set.new(@env)).to_h.keys
15
+ end
16
+
17
+ def endure!
18
+ unless changes.empty?
19
+ raise 'ENV changed during test setup: ' + changes.to_s
20
+ end
21
+ end
22
+
23
+ def freeze
24
+ raise 'already frozen' if @env
25
+
26
+ @env = ENV.to_h.freeze
27
+ end
28
+ end
29
+ end
30
+
31
+ IceAge.freeze
32
+
33
+ if defined? RSpec
34
+ require_relative 'ice_age/rspec'
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec/core'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ config.before do
6
+ IceAge.restore
7
+ end
8
+
9
+ end
@@ -0,0 +1,60 @@
1
+ # it_behaves_like
2
+
3
+ RSpec.shared_examples 'nothing changed' do
4
+ it { expect(ENV['ICE_AGE_TEST']).to eq '123' }
5
+ end
6
+
7
+ describe IceAge do
8
+ it_behaves_like 'nothing changed'
9
+
10
+ context 'when updated in before block' do
11
+ before { ENV['ICE_AGE_TEST'] = 'xxx' }
12
+
13
+ it { expect(ENV['ICE_AGE_TEST']).to eq 'xxx' }
14
+ it { expect(ENV.fetch('ICE_AGE_TEST')).to eq 'xxx' }
15
+
16
+ context 'when nested' do
17
+ it { expect(ENV['ICE_AGE_TEST']).to eq 'xxx' }
18
+ end
19
+
20
+ it { expect(ENV['ICE_AGE_TEST']).to eq 'xxx' }
21
+
22
+ context 'when nested and changed' do
23
+ before { ENV['ICE_AGE_TEST'] = 'yyy' }
24
+
25
+ it { expect(ENV['ICE_AGE_TEST']).to eq 'yyy' }
26
+ end
27
+
28
+ it { expect(ENV['ICE_AGE_TEST']).to eq 'xxx' }
29
+ end
30
+
31
+ it_behaves_like 'nothing changed'
32
+
33
+
34
+ context 'when updated in an example' do
35
+ it 'works as expected' do
36
+ ENV['ICE_AGE_TEST'] = 'zzz'
37
+
38
+ expect(ENV['ICE_AGE_TEST']).to eq 'zzz'
39
+ end
40
+
41
+ # then resets
42
+ it_behaves_like 'nothing changed'
43
+ end
44
+
45
+ it_behaves_like 'nothing changed'
46
+
47
+
48
+ context 'when updated in the wrong spot' do
49
+ # evaluated before testing starts, when file is initially loaded
50
+ ENV['ICE_AGE_TEST'] = 'xxx'
51
+
52
+ it 'did not permit ENV to change' do
53
+ expect(ENV['ICE_AGE_TEST']).not_to eq 'xxx'
54
+ end
55
+
56
+ it_behaves_like 'nothing changed'
57
+ end
58
+
59
+ it_behaves_like 'nothing changed'
60
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ice_age
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Pepper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec/core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Freeze your ENVironment for testing.
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/ice_age.rb
62
+ - lib/ice_age/rspec.rb
63
+ - spec/ice_age_spec.rb
64
+ homepage: https://github.com/dpep/rb_ice_age
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.0.8
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: IceAge
87
+ test_files:
88
+ - spec/ice_age_spec.rb