climate_control 0.0.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aac4a1d4fe272e5369855d9d80c8bfd764b752f27d1bdfad2b19a607d5f0a44e
4
+ data.tar.gz: 8945986d5956f681810ef8a5f164323a3cd2a48e82368618c292f3c6fc7a6caa
5
+ SHA512:
6
+ metadata.gz: c36a6b4ead29b23f93c95457e56f6bc3fd6c5cd596f66fe8243e736edcc5a11cfe9fd5fe62b1cf5fc8cd0c7f4fe72c051c0560338a6496e30c56b3cf095c92ec
7
+ data.tar.gz: cbdf93ff0a149ef67129db0ac0f25838f02c7d2faf6dea87f8ce0acaf54848fb129f4d1b8cbf0ad40c50358cd2186e5a726b2fed5d82fbc9de2c765f4a9bf94d
@@ -0,0 +1,23 @@
1
+ name: CI
2
+ on: [pull_request]
3
+ jobs:
4
+ tests:
5
+ name: Tests
6
+ runs-on: ubuntu-latest
7
+ strategy:
8
+ matrix:
9
+ ruby-version: ['3.0', 2.7, 2.6, 2.5]
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby ${{ matrix.ruby-version }}
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby-version }}
16
+ - name: Install gems
17
+ run: |
18
+ bundle config path vendor/bundle
19
+ bundle install --jobs 4 --retry 3
20
+ - name: Run tests
21
+ run: bundle exec rake
22
+ - name: Run StandardRB
23
+ run: bundle exec standardrb
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ bin
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
@@ -0,0 +1,6 @@
1
+ # Code of Conduct
2
+
3
+ By participating in this project, you agree to abide by the
4
+ [thoughtbot code of conduct][1].
5
+
6
+ [1]: https://thoughtbot.com/open-source-code-of-conduct
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in climate_control.gemspec
4
4
  gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Joshua Clayton and thoughtbot, inc.
1
+ Copyright (c) 2012-2021 Joshua Clayton and thoughtbot, inc.
2
2
 
3
3
  MIT License
4
4
 
data/NEWS CHANGED
@@ -1,2 +1,22 @@
1
+ 1.0.1 (May 26, 2021)
2
+ Require minimum Ruby version of 2.5.0
3
+
4
+ 1.0.0 (March 6, 2021)
5
+ Commit to supporting latest patch versions of Ruby 2.5+
6
+ Improve documentation
7
+ Format code with StandardRB
8
+ Bump gem dependencies
9
+
10
+ 0.2.0 (May 12, 2017)
11
+ Allow nested environment changes in the same thread
12
+
13
+ 0.1.0 (January 7, 2017)
14
+ Remove ActiveSupport dependency
15
+
16
+ 0.0.4 (January 6, 2017)
17
+ Improved thread safety
18
+ Handle TypeErrors during assignment
19
+ Improve documentation
20
+
1
21
  0.0.1 (November 28, 2012)
2
22
  Initial release
data/README.md CHANGED
@@ -18,14 +18,30 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- `ClimateControl` can be used to temporarily assign environment variables
21
+ Climate Control can be used to temporarily assign environment variables
22
22
  within a block:
23
23
 
24
24
  ```ruby
25
25
  ClimateControl.modify CONFIRMATION_INSTRUCTIONS_BCC: 'confirmation_bcc@example.com' do
26
26
  sign_up_as 'john@example.com'
27
+
28
+ confirm_account_for_email 'john@example.com'
29
+
30
+ expect(current_email).to bcc_to('confirmation_bcc@example.com')
31
+ end
32
+ ```
33
+
34
+ To modify multiple environment variables:
35
+
36
+ ```ruby
37
+ ClimateControl.modify CONFIRMATION_INSTRUCTIONS_BCC: 'confirmation_bcc@example.com',
38
+ MAIL_FROM: 'us@example.com' do
39
+ sign_up_as 'john@example.com'
40
+
27
41
  confirm_account_for_email 'john@example.com'
28
- current_email.should bcc_to('confirmation_bcc@example.com')
42
+
43
+ expect(current_email).to bcc_to('confirmation_bcc@example.com')
44
+ expect(current_email).to be_from('us@example.com')
29
45
  end
30
46
  ```
31
47
 
@@ -76,6 +92,19 @@ block, except for the overrides. Transparency is crucial because the code
76
92
  executed within the block is not for `ClimateControl` to manage or modify. See
77
93
  the tests for more detail about the specific behaviors.
78
94
 
95
+ ## Why Use Climate Control?
96
+
97
+ By following guidelines regarding environment variables outlined by the
98
+ [twelve-factor app](http://12factor.net/config), testing code in an isolated
99
+ manner becomes more difficult:
100
+
101
+ * avoiding modifications and testing values, we introduce mystery guests
102
+ * making modifications and testing values, we introduce risk as environment
103
+ variables represent global state
104
+
105
+ Climate Control modifies environment variables only within the context of the
106
+ block, ensuring values are managed properly and consistently.
107
+
79
108
  ## Contributing
80
109
 
81
110
  1. Fork it
@@ -84,6 +113,8 @@ the tests for more detail about the specific behaviors.
84
113
  4. Push to the branch (`git push origin my-new-feature`)
85
114
  5. Create new Pull Request
86
115
 
116
+ This project uses [StandardRB](https://github.com/testdouble/standard) to ensure formatting.
117
+
87
118
  ## License
88
119
 
89
- climate_control is copyright 2012 Joshua Clayton and thoughtbot, inc. It is free software and may be redistributed under the terms specified in the LICENSE.txt file.
120
+ climate_control is copyright 2012-2021 Joshua Clayton and thoughtbot, inc. It is free software and may be redistributed under the terms specified in the [LICENSE](https://github.com/thoughtbot/climate_control/blob/main/LICENSE) file.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:rspec)
5
5
 
@@ -1,24 +1,25 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'climate_control/version'
3
+ require "climate_control/version"
5
4
 
6
5
  Gem::Specification.new do |gem|
7
- gem.name = 'climate_control'
8
- gem.version = ClimateControl::VERSION
9
- gem.authors = ['Joshua Clayton']
10
- gem.email = ['joshua.clayton@gmail.com']
11
- gem.description = %q{Modify your ENV}
12
- gem.summary = %q{Modify your ENV easily with ClimateControl}
13
- gem.homepage = 'https://github.com/thoughtbot/climate_control'
6
+ gem.name = "climate_control"
7
+ gem.version = ClimateControl::VERSION
8
+ gem.authors = ["Joshua Clayton"]
9
+ gem.email = ["joshua.clayton@gmail.com"]
10
+ gem.description = "Modify your ENV"
11
+ gem.summary = "Modify your ENV easily with ClimateControl"
12
+ gem.homepage = "https://github.com/thoughtbot/climate_control"
13
+ gem.license = "MIT"
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ['lib']
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
19
18
 
20
- gem.add_dependency 'activesupport', '>= 3.0'
21
- gem.add_development_dependency 'rspec', '~> 2.11'
22
- gem.add_development_dependency 'rake', '~> 0.9.2'
23
- gem.add_development_dependency 'simplecov', '~> 0.7.1'
19
+ gem.required_ruby_version = ">= 2.5.0"
20
+
21
+ gem.add_development_dependency "rspec", "~> 3.10.0"
22
+ gem.add_development_dependency "rake", "~> 12.3.3"
23
+ gem.add_development_dependency "simplecov", "~> 0.9.1"
24
+ gem.add_development_dependency "standard", "~> 1.0.0"
24
25
  end
@@ -1,8 +1,16 @@
1
- require 'climate_control/modifier'
2
- require 'climate_control/version'
1
+ require "climate_control/environment"
2
+ require "climate_control/errors"
3
+ require "climate_control/modifier"
4
+ require "climate_control/version"
3
5
 
4
6
  module ClimateControl
7
+ @@env = ClimateControl::Environment.new
8
+
5
9
  def self.modify(environment_overrides, &block)
6
- Modifier.new(environment_overrides, &block).process
10
+ Modifier.new(env, environment_overrides, &block).process
11
+ end
12
+
13
+ def self.env
14
+ @@env
7
15
  end
8
16
  end
@@ -0,0 +1,33 @@
1
+ require "forwardable"
2
+
3
+ module ClimateControl
4
+ class Environment
5
+ extend Forwardable
6
+
7
+ def initialize
8
+ @semaphore = Mutex.new
9
+ @owner = nil
10
+ end
11
+
12
+ def_delegators :env, :[]=, :to_hash, :[], :delete
13
+
14
+ def synchronize
15
+ if @owner == Thread.current
16
+ return yield if block_given?
17
+ end
18
+
19
+ @semaphore.synchronize do
20
+ @owner = Thread.current
21
+ yield if block_given?
22
+ ensure
23
+ @owner = nil
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def env
30
+ ENV
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module ClimateControl
2
+ class UnassignableValueError < ArgumentError; end
3
+ end
@@ -1,14 +1,13 @@
1
- require 'active_support/core_ext/hash/keys'
2
-
3
1
  module ClimateControl
4
2
  class Modifier
5
- def initialize(environment_overrides = {}, &block)
6
- @environment_overrides = environment_overrides.dup.stringify_keys!
3
+ def initialize(env, environment_overrides = {}, &block)
4
+ @environment_overrides = stringify_keys(environment_overrides)
7
5
  @block = block
6
+ @env = env
8
7
  end
9
8
 
10
9
  def process
11
- begin
10
+ @env.synchronize do
12
11
  prepare_environment_for_block
13
12
  run_block
14
13
  ensure
@@ -32,7 +31,10 @@ module ClimateControl
32
31
 
33
32
  def copy_overrides_to_environment
34
33
  @environment_overrides.each do |key, value|
35
- ENV[key] = value
34
+ @env[key] = value
35
+ rescue TypeError => e
36
+ raise UnassignableValueError,
37
+ "attempted to assign #{value} to #{key} but failed (#{e.message})"
36
38
  end
37
39
  end
38
40
 
@@ -49,22 +51,28 @@ module ClimateControl
49
51
  end
50
52
 
51
53
  def delete_keys_that_do_not_belong
52
- (keys_to_remove - keys_changed_by_block).each {|key| ENV.delete(key) }
54
+ (keys_to_remove - keys_changed_by_block).each { |key| @env.delete(key) }
53
55
  end
54
56
 
55
57
  def revert_changed_keys
56
58
  (@original_env.keys - keys_changed_by_block).each do |key|
57
- ENV[key] = @original_env[key]
59
+ @env[key] = @original_env[key]
58
60
  end
59
61
  end
60
62
 
61
63
  def clone_environment
62
- ENV.to_hash
64
+ @env.to_hash
65
+ end
66
+
67
+ def stringify_keys(env)
68
+ env.each_with_object({}) do |(key, value), hash|
69
+ hash[key.to_s] = value
70
+ end
63
71
  end
64
72
 
65
73
  class OverlappingKeysWithChangedValues
66
74
  def initialize(hash_1, hash_2)
67
- @hash_1 = hash_1
75
+ @hash_1 = hash_1 || {}
68
76
  @hash_2 = hash_2
69
77
  end
70
78
 
@@ -1,3 +1,3 @@
1
1
  module ClimateControl
2
- VERSION = '0.0.3'
2
+ VERSION = "1.0.1".freeze
3
3
  end
@@ -1,14 +1,163 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe 'Climate control' do
4
- it 'allows modification of the environment' do
3
+ Thing = Class.new
4
+
5
+ describe "Climate control" do
6
+ it "allows modification of the environment" do
5
7
  block_run = false
6
- ClimateControl.modify FOO: 'bar' do
7
- expect(ENV['FOO']).to eq 'bar'
8
+ ClimateControl.modify FOO: "bar" do
9
+ expect(ENV["FOO"]).to eq "bar"
8
10
  block_run = true
9
11
  end
10
12
 
11
- expect(ENV['FOO']).to be_nil
12
- expect(block_run).to be_true
13
+ expect(ENV["FOO"]).to be_nil
14
+ expect(block_run).to be true
15
+ end
16
+
17
+ it "modifies the environment" do
18
+ with_modified_env VARIABLE_1: "bar", VARIABLE_2: "qux" do
19
+ expect(ENV["VARIABLE_1"]).to eq "bar"
20
+ expect(ENV["VARIABLE_2"]).to eq "qux"
21
+ end
22
+
23
+ expect(ENV["VARIABLE_1"]).to be_nil
24
+ expect(ENV["VARIABLE_2"]).to be_nil
25
+ end
26
+
27
+ it "allows for environment variables to be assigned within the block" do
28
+ with_modified_env VARIABLE_1: "modified" do
29
+ ENV["ASSIGNED_IN_BLOCK"] = "assigned"
30
+ end
31
+
32
+ expect(ENV["ASSIGNED_IN_BLOCK"]).to eq "assigned"
33
+ end
34
+
35
+ it "reassigns previously set environment variables" do
36
+ ENV["VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV"] = "original"
37
+ expect(ENV["VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV"]).to eq "original"
38
+
39
+ with_modified_env VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV: "overridden" do
40
+ expect(ENV["VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV"]).to eq "overridden"
41
+ end
42
+
43
+ expect(ENV["VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV"]).to eq "original"
44
+ end
45
+
46
+ it "persists the change when overriding the variable in the block" do
47
+ with_modified_env VARIABLE_MODIFIED_AND_THEN_ASSIGNED: "modified" do
48
+ ENV["VARIABLE_MODIFIED_AND_THEN_ASSIGNED"] = "assigned value"
49
+ end
50
+
51
+ expect(ENV["VARIABLE_MODIFIED_AND_THEN_ASSIGNED"]).to eq "assigned value"
52
+ end
53
+
54
+ it "resets environment variables even if the block raises" do
55
+ expect {
56
+ with_modified_env FOO: "bar" do
57
+ raise "broken"
58
+ end
59
+ }.to raise_error("broken")
60
+
61
+ expect(ENV["FOO"]).to be_nil
62
+ end
63
+
64
+ it "preserves environment variables set within the block" do
65
+ ENV["CHANGED"] = "old value"
66
+
67
+ with_modified_env IRRELEVANT: "ignored value" do
68
+ ENV["CHANGED"] = "new value"
69
+ end
70
+
71
+ expect(ENV["CHANGED"]).to eq "new value"
72
+ end
73
+
74
+ it "returns the value of the block" do
75
+ value = with_modified_env VARIABLE_1: "bar" do
76
+ "value inside block"
77
+ end
78
+
79
+ expect(value).to eq "value inside block"
80
+ end
81
+
82
+ it "handles threads correctly" do
83
+ # failure path without mutex
84
+ # [thread_removing_env] BAZ is assigned
85
+ # 0.25s passes
86
+ # [other_thread] FOO is assigned and ENV is copied (which includes BAZ)
87
+ # 0.25s passes
88
+ # [thread_removing_env] thread resolves and BAZ is removed from env; other_thread still retains knowledge of BAZ
89
+ # 0.25s passes
90
+ # [other_thread] thread resolves, FOO is removed, BAZ is copied back to ENV
91
+
92
+ thread_removing_env = Thread.new {
93
+ with_modified_env BAZ: "buzz" do
94
+ sleep 0.5
95
+ end
96
+
97
+ expect(ENV["BAZ"]).to be_nil
98
+ }
99
+
100
+ other_thread = Thread.new {
101
+ sleep 0.25
102
+ with_modified_env FOO: "bar" do
103
+ sleep 0.5
104
+ end
105
+
106
+ expect(ENV["FOO"]).to be_nil
107
+ }
108
+
109
+ thread_removing_env.join
110
+ other_thread.join
111
+
112
+ expect(ENV["FOO"]).to be_nil
113
+ expect(ENV["BAZ"]).to be_nil
114
+ end
115
+
116
+ it "is re-entrant" do
117
+ ret = with_modified_env(FOO: "foo") {
118
+ with_modified_env(BAR: "bar") do
119
+ "bar"
120
+ end
121
+ }
122
+
123
+ expect(ret).to eq("bar")
124
+
125
+ expect(ENV["FOO"]).to be_nil
126
+ expect(ENV["BAR"]).to be_nil
127
+ end
128
+
129
+ it "raises when the value cannot be assigned properly" do
130
+ message = generate_type_error_for_object(Thing.new)
131
+
132
+ expect {
133
+ with_modified_env(FOO: Thing.new)
134
+ }.to raise_error ClimateControl::UnassignableValueError, /attempted to assign .*Thing.* to FOO but failed \(#{message}\)$/
135
+ end
136
+
137
+ def with_modified_env(options, &block)
138
+ ClimateControl.modify(options, &block)
139
+ end
140
+
141
+ def generate_type_error_for_object(object)
142
+ message = nil
143
+
144
+ begin
145
+ "1" + object
146
+ rescue TypeError => e
147
+ message = e.message
148
+ end
149
+
150
+ message
151
+ end
152
+
153
+ around do |example|
154
+ old_env = ENV.to_hash
155
+
156
+ example.run
157
+
158
+ ENV.clear
159
+ old_env.each do |key, value|
160
+ ENV[key] = value
161
+ end
13
162
  end
14
163
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,13 @@
1
- require 'simplecov'
2
- SimpleCov.start
1
+ begin
2
+ require "simplecov"
3
+ SimpleCov.start
4
+ rescue LoadError
5
+ warn "warning: simplecov gem not found; skipping coverage"
6
+ end
3
7
 
4
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
8
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
5
9
  $LOAD_PATH << File.join(File.dirname(__FILE__))
6
10
 
7
- require 'rubygems'
8
- require 'rspec'
9
- require 'climate_control'
10
-
11
- Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
11
+ require "rubygems"
12
+ require "rspec"
13
+ require "climate_control"
metadata CHANGED
@@ -1,80 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: climate_control
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joshua Clayton
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-30 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: activesupport
14
+ name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '3.0'
22
- type: :runtime
19
+ version: 3.10.0
20
+ type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '3.0'
26
+ version: 3.10.0
30
27
  - !ruby/object:Gem::Dependency
31
- name: rspec
28
+ name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '2.11'
33
+ version: 12.3.3
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '2.11'
40
+ version: 12.3.3
46
41
  - !ruby/object:Gem::Dependency
47
- name: rake
42
+ name: simplecov
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 0.9.2
47
+ version: 0.9.1
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: 0.9.2
54
+ version: 0.9.1
62
55
  - !ruby/object:Gem::Dependency
63
- name: simplecov
56
+ name: standard
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
- version: 0.7.1
61
+ version: 1.0.0
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
- version: 0.7.1
68
+ version: 1.0.0
78
69
  description: Modify your ENV
79
70
  email:
80
71
  - joshua.clayton@gmail.com
@@ -82,46 +73,45 @@ executables: []
82
73
  extensions: []
83
74
  extra_rdoc_files: []
84
75
  files:
85
- - .gitignore
86
- - .travisci.yml
76
+ - ".github/workflows/ci.yml"
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
87
79
  - Gemfile
88
- - LICENSE.txt
80
+ - LICENSE
89
81
  - NEWS
90
82
  - README.md
91
83
  - Rakefile
92
84
  - climate_control.gemspec
93
85
  - lib/climate_control.rb
86
+ - lib/climate_control/environment.rb
87
+ - lib/climate_control/errors.rb
94
88
  - lib/climate_control/modifier.rb
95
89
  - lib/climate_control/version.rb
96
90
  - spec/acceptance/climate_control_spec.rb
97
- - spec/lib/climate_control/modifier_spec.rb
98
91
  - spec/spec_helper.rb
99
92
  homepage: https://github.com/thoughtbot/climate_control
100
- licenses: []
101
- post_install_message:
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
102
97
  rdoc_options: []
103
98
  require_paths:
104
99
  - lib
105
100
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
101
  requirements:
108
- - - ! '>='
102
+ - - ">="
109
103
  - !ruby/object:Gem::Version
110
- version: '0'
104
+ version: 2.5.0
111
105
  required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
106
  requirements:
114
- - - ! '>='
107
+ - - ">="
115
108
  - !ruby/object:Gem::Version
116
109
  version: '0'
117
110
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 1.8.23
120
- signing_key:
121
- specification_version: 3
111
+ rubygems_version: 3.2.3
112
+ signing_key:
113
+ specification_version: 4
122
114
  summary: Modify your ENV easily with ClimateControl
123
115
  test_files:
124
116
  - spec/acceptance/climate_control_spec.rb
125
- - spec/lib/climate_control/modifier_spec.rb
126
117
  - spec/spec_helper.rb
127
- has_rdoc:
data/.travisci.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- before_install:
6
- - gem update --system
7
- branches:
8
- only:
9
- - master
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ClimateControl::Modifier do
4
- it 'modifies the environment' do
5
- with_modified_env VARIABLE_1: 'bar', VARIABLE_2: 'qux' do
6
- expect(ENV['VARIABLE_1']).to eq 'bar'
7
- expect(ENV['VARIABLE_2']).to eq 'qux'
8
- end
9
-
10
- expect(ENV['VARIABLE_1']).to be_nil
11
- expect(ENV['VARIABLE_2']).to be_nil
12
- end
13
-
14
- it 'allows for environment variables to be assigned within the block' do
15
- with_modified_env VARIABLE_1: 'modified' do
16
- ENV['ASSIGNED_IN_BLOCK'] = 'assigned'
17
- end
18
-
19
- expect(ENV['ASSIGNED_IN_BLOCK']).to eq 'assigned'
20
- end
21
-
22
- it 'reassigns previously set environment variables' do
23
- ENV['VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV'] = 'original'
24
- expect(ENV['VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV']).to eq 'original'
25
-
26
- with_modified_env VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV: 'overridden' do
27
- expect(ENV['VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV']).to eq 'overridden'
28
- end
29
-
30
- expect(ENV['VARIABLE_ASSIGNED_BEFORE_MODIFYING_ENV']).to eq 'original'
31
- end
32
-
33
- it 'persists the change when overriding the variable in the block' do
34
- with_modified_env VARIABLE_MODIFIED_AND_THEN_ASSIGNED: 'modified' do
35
- ENV['VARIABLE_MODIFIED_AND_THEN_ASSIGNED'] = 'assigned value'
36
- end
37
-
38
- expect(ENV['VARIABLE_MODIFIED_AND_THEN_ASSIGNED']).to eq 'assigned value'
39
- end
40
-
41
- it 'resets environment variables even if the block raises' do
42
- expect {
43
- with_modified_env FOO: 'bar' do
44
- raise 'broken'
45
- end
46
- }.to raise_error
47
-
48
- expect(ENV['FOO']).to be_nil
49
- end
50
-
51
- it 'preserves environment variables set within the block' do
52
- ENV['CHANGED'] = 'old value'
53
-
54
- with_modified_env IRRELEVANT: 'ignored value' do
55
- ENV['CHANGED'] = 'new value'
56
- end
57
-
58
- expect(ENV['CHANGED']).to eq 'new value'
59
- end
60
-
61
- it 'returns the value of the block' do
62
- value = with_modified_env VARIABLE_1: 'bar' do
63
- 'value inside block'
64
- end
65
-
66
- expect(value).to eq 'value inside block'
67
- end
68
-
69
- def with_modified_env(options, &block)
70
- ClimateControl::Modifier.new(options, &block).process
71
- end
72
-
73
- around do |example|
74
- old_env = ENV.to_hash
75
-
76
- example.run
77
-
78
- ENV.clear
79
- old_env.each do |key, value|
80
- ENV[key] = value
81
- end
82
- end
83
- end