env_mock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8395d3c677e97a074f0997295675a6c6c1a99bdff32ea3c7426d2048259186b6
4
+ data.tar.gz: '04922c7124b5b2c952eaafa2bee4f9f05ca1985b383be64593f233062b0986c1'
5
+ SHA512:
6
+ metadata.gz: 2dd211752b76874226c141cf9af40413a2c68139fa61c625435bd81c9974aad3aa9639a263add25edfd2608a0226ab617ea41da6bbf78bdb734df9c25669e1ae
7
+ data.tar.gz: 7cbde983854192b2647255f9b92a1621906d22d51f0d9e02db358f2b2e5426ebd3634232483bb30be8eb57ab8d3e3aa015a8a62e50c03b23978cfbffd5c86e43
@@ -0,0 +1,3 @@
1
+ ## v0.1.0
2
+
3
+ - Enables mock envs given a hash;
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Washington Botelho
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # EnvMock
2
+
3
+ [![CI](https://github.com/wbotelhos/env_mock/workflows/CI/badge.svg)](https://github.com/wbotelhos/env_mock/actions)
4
+ [![Gem Version](https://badge.fury.io/rb/env_mock.svg)](https://badge.fury.io/rb/env_mock)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f312587b4f126bb13e85/maintainability)](https://codeclimate.com/github/wbotelhos/env_mock/maintainability)
6
+ [![codecov](https://codecov.io/gh/wbotelhos/blogy/branch/master/graph/badge.svg?token=VX93Oihxpz)](https://codecov.io/gh/wbotelhos/env_mock)
7
+ [![Patreon](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://www.patreon.com/wbotelhos)
8
+
9
+ Mock your ENVs.
10
+
11
+ ## Install
12
+
13
+ Add the following code on your `Gemfile` and run `bundle install`:
14
+
15
+ ```ruby
16
+ gem 'env_mock'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ ENV['DATABASE_USERNAME'] = 'wbotelhos'
23
+
24
+ ENV['DATABASE_USERNAME']
25
+ => 'root'
26
+
27
+ ENV['TAX_CENTS']
28
+ => nil
29
+
30
+ ENV['UDP']
31
+ => nil
32
+
33
+ EnvMock.mock(DATABASE_USERNAME: 'wbotelhos', TAX_CENTS: 700, 'udp' => true) do
34
+ ENV['DATABASE_USERNAME'] # .to_sym is called for all keys
35
+ => 'wbotelhos'
36
+
37
+ ENV['TAX_CENTS']
38
+ => '700' # `.to_s` is called for all values
39
+
40
+ ENV['UDP'] # .upcase is called for all keys
41
+ => 'true'
42
+ end
43
+
44
+ ENV['DATABASE_USERNAME']
45
+ => 'root'
46
+
47
+ ENV['TAX_CENTS']
48
+ => nil
49
+
50
+ ENV['UDP']
51
+ => nil
52
+ ```
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnvMock
4
+ module_function
5
+
6
+ def mock(hash)
7
+ backup = {}
8
+
9
+ hash.each do |key, value|
10
+ name = key.to_s.upcase
11
+ backup[name] = ENV[name]
12
+ ENV[name] = value.to_s
13
+ end
14
+
15
+ yield
16
+ ensure
17
+ backup.each { |key, value| ENV[key] = value }
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnvMock
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe EnvMock, '.mock' do
4
+ it 'mocks env inside the block' do
5
+ ENV['KEY'] = 'original'
6
+
7
+ described_class.mock('KEY' => 'fake') do
8
+ expect(ENV['KEY']).to eq 'fake'
9
+ end
10
+
11
+ expect(ENV['KEY']).to eq 'original'
12
+ end
13
+
14
+ it 'mocks key as symbol' do
15
+ ENV['KEY'] = 'original'
16
+
17
+ described_class.mock(KEY: 'fake') do
18
+ expect(ENV['KEY']).to eq 'fake'
19
+ end
20
+
21
+ expect(ENV['KEY']).to eq 'original'
22
+ end
23
+
24
+ it 'mocks key downcased' do
25
+ ENV['KEY'] = 'original'
26
+
27
+ described_class.mock('key' => 'fake') do
28
+ expect(ENV['KEY']).to eq 'fake'
29
+ end
30
+
31
+ expect(ENV['KEY']).to eq 'original'
32
+ end
33
+
34
+ it 'mocks key as symbol and downcased' do
35
+ ENV['KEY'] = 'original'
36
+
37
+ described_class.mock(key: 'fake') do
38
+ expect(ENV['KEY']).to eq 'fake'
39
+ end
40
+
41
+ expect(ENV['KEY']).to eq 'original'
42
+ end
43
+
44
+ it 'mocks more than one key at the same time' do
45
+ ENV['KEY'] = 'original'
46
+ ENV['DATA'] = 'first'
47
+
48
+ described_class.mock(data: 'data', key: 'fake') do
49
+ expect(ENV['DATA']).to eq 'data'
50
+ expect(ENV['KEY']).to eq 'fake'
51
+ end
52
+
53
+ expect(ENV['DATA']).to eq 'first'
54
+ expect(ENV['KEY']).to eq 'original'
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'env_mock'
4
+ require 'pry-byebug'
5
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_mock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Washington Botelho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry-byebug
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
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
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Mock your ENVs.
70
+ email: wbotelhos@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - CHANGELOG.md
75
+ - LICENSE
76
+ - README.md
77
+ files:
78
+ - CHANGELOG.md
79
+ - LICENSE
80
+ - README.md
81
+ - lib/env_mock.rb
82
+ - lib/env_mock/version.rb
83
+ - spec/env_mock/mock_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: https://github.com/wbotelhos/env_mock
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.1.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Mock your ENVs.
108
+ test_files:
109
+ - spec/spec_helper.rb
110
+ - spec/env_mock/mock_spec.rb