ice_age 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2760620f23a7e61b8158f31fa1eb1aa903136ccca5a37c38c079e018cdaeb294
4
- data.tar.gz: c046715ad5d668eef9dab818237c0088da05e6a68ef39ac6c60a41f1f5d991ea
3
+ metadata.gz: a509f52ea42b9283d2d9d9b58ea8c58670eb98cf84e06ca79bce8e82f188b034
4
+ data.tar.gz: 96aaf024a4a18719980dc7f9f75332fcc7b096a7c12774ea7b7a23af7e1d94bf
5
5
  SHA512:
6
- metadata.gz: 49310d47cd6aea17abf6a6edd4553a05ee4fa101d91af64bef0d309e322aa6bed3e205934fa7d293b3f33f2d4222ba6ef9b2447a5b8ada0a2cb0ce54946feaef
7
- data.tar.gz: 606b8cdcb9b612dfcb615ebf58a0f1f4be5d88df910e977a8d98ccdc56ad2d2dc68aae882712c03bcbde73466fbe38a41f82dd5dddb229c6462c92059aaa6b06
6
+ metadata.gz: 86474f9dc9331a377c949ac08c2bed16a2d0562b135d86150b0f6da007f5334597b7b6a8703bbde40343fa931af5f193b807e5768dd52a5dff2f646e286bc854
7
+ data.tar.gz: 2d0816db323ceadae0f536dbf548e3a59b4ffa91ed5d1299125d35795a158dea17fc07bb205edb4070e3a7b4255873bddf4dd2d3912fbccb5963d85177788ede
@@ -1,35 +1,39 @@
1
1
  require 'set'
2
2
 
3
3
  class IceAge
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
 
6
6
  class << self
7
- def restore
8
- raise "#{self.class.name}.frozen never called!" unless @env
9
7
 
10
- ENV.clear.update(@env)
8
+ def freeze
9
+ raise 'already frozen' if frozen?
10
+
11
+ @env = ENV.to_h.freeze
11
12
  end
12
13
 
13
- def changes
14
- (Set.new(ENV.to_h) - Set.new(@env)).to_h.keys
14
+ def frozen?
15
+ !!@env
16
+ end
17
+
18
+ def restore
19
+ raise "#{self.class.name}.frozen never called!" unless frozen?
20
+
21
+ ENV.clear.update(@env)
15
22
  end
16
23
 
17
24
  def endure!
25
+ changes = (Set.new(ENV.to_h) - Set.new(@env)).to_h.keys
18
26
  unless changes.empty?
19
- raise 'ENV changed during test setup: ' + changes.to_s
27
+ msg = changes.map {|k| { k => { @env[k] => ENV[k] } }}.to_s
28
+ raise 'ENV changed after freeze: ' + msg
20
29
  end
21
30
  end
22
31
 
23
- def freeze
24
- raise 'already frozen' if @env
25
-
26
- @env = ENV.to_h.freeze
27
- end
28
32
  end
29
33
  end
30
34
 
31
- IceAge.freeze
32
35
 
33
- if defined? RSpec
36
+ # load framework plugins
37
+ begin
34
38
  require_relative 'ice_age/rspec'
35
- end
39
+ rescue LoadError; end
@@ -2,6 +2,10 @@ require 'rspec/core'
2
2
 
3
3
  RSpec.configure do |config|
4
4
 
5
+ config.before(:suite) do
6
+ IceAge.frozen? ? IceAge.endure! : IceAge.freeze
7
+ end
8
+
5
9
  config.before do
6
10
  IceAge.restore
7
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_age
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
  - Daniel Pepper
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec/core
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,19 +53,18 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Freeze your ENVironment for testing.
56
- email:
56
+ email:
57
57
  executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - lib/ice_age.rb
62
62
  - lib/ice_age/rspec.rb
63
- - spec/ice_age_spec.rb
64
63
  homepage: https://github.com/dpep/rb_ice_age
65
64
  licenses:
66
65
  - MIT
67
66
  metadata: {}
68
- post_install_message:
67
+ post_install_message:
69
68
  rdoc_options: []
70
69
  require_paths:
71
70
  - lib
@@ -80,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
79
  - !ruby/object:Gem::Version
81
80
  version: '0'
82
81
  requirements: []
83
- rubygems_version: 3.0.8
84
- signing_key:
82
+ rubygems_version: 3.0.3
83
+ signing_key:
85
84
  specification_version: 4
86
85
  summary: IceAge
87
- test_files:
88
- - spec/ice_age_spec.rb
86
+ test_files: []
@@ -1,60 +0,0 @@
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