tcfg 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.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +20 -0
- data/README.md +90 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/tcfg.rb +3 -0
- data/lib/tcfg/tcfg_base.rb +10 -0
- data/lib/tcfg/tcfg_helper.rb +122 -0
- data/lib/tcfg/tcfg_module.rb +7 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39595952f6c08c280797fd9c93ee54dd72824b48
|
4
|
+
data.tar.gz: 7920588447e198f58433ff1b46587bdd4c724a8d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f924cc3a03d1213429ab451eead6e61bf0556ab2cdc616f9fb67a19b436deb20e31d9fbd5852e236316a6eb7476cc12f6ade545fee347054a413bb484c1995fa
|
7
|
+
data.tar.gz: 08f13614791d8ce60f4da75adf2eac7c7bd10e7b81fd33bba0b90e7b46ecbb792bad508e18484499501e207346a1a6f7c5f672fba80adb81ef6f1f658362ae30
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.13)
|
5
|
+
i18n (= 0.6.1)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
addressable (2.3.5)
|
8
|
+
builder (3.2.2)
|
9
|
+
descendants_tracker (0.0.3)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
faraday (0.9.0)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
git (1.2.6)
|
14
|
+
github_api (0.11.3)
|
15
|
+
addressable (~> 2.3)
|
16
|
+
descendants_tracker (~> 0.0.1)
|
17
|
+
faraday (~> 0.8, < 0.10)
|
18
|
+
hashie (>= 1.2)
|
19
|
+
multi_json (>= 1.7.5, < 2.0)
|
20
|
+
nokogiri (~> 1.6.0)
|
21
|
+
oauth2
|
22
|
+
hashie (2.0.5)
|
23
|
+
highline (1.6.21)
|
24
|
+
i18n (0.6.1)
|
25
|
+
jeweler (2.0.1)
|
26
|
+
builder
|
27
|
+
bundler (>= 1.0)
|
28
|
+
git (>= 1.2.5)
|
29
|
+
github_api
|
30
|
+
highline (>= 1.6.15)
|
31
|
+
nokogiri (>= 1.5.10)
|
32
|
+
rake
|
33
|
+
rdoc
|
34
|
+
json (1.8.1)
|
35
|
+
jwt (0.1.11)
|
36
|
+
multi_json (>= 1.5)
|
37
|
+
mini_portile (0.5.2)
|
38
|
+
multi_json (1.9.0)
|
39
|
+
multi_xml (0.5.5)
|
40
|
+
multipart-post (2.0.0)
|
41
|
+
nokogiri (1.6.1)
|
42
|
+
mini_portile (~> 0.5.0)
|
43
|
+
oauth2 (0.9.3)
|
44
|
+
faraday (>= 0.8, < 0.10)
|
45
|
+
jwt (~> 0.1.8)
|
46
|
+
multi_json (~> 1.3)
|
47
|
+
multi_xml (~> 0.5)
|
48
|
+
rack (~> 1.2)
|
49
|
+
rack (1.5.2)
|
50
|
+
rake (10.1.1)
|
51
|
+
rdoc (4.1.1)
|
52
|
+
json (~> 1.4)
|
53
|
+
rspec (2.14.1)
|
54
|
+
rspec-core (~> 2.14.0)
|
55
|
+
rspec-expectations (~> 2.14.0)
|
56
|
+
rspec-mocks (~> 2.14.0)
|
57
|
+
rspec-core (2.14.8)
|
58
|
+
rspec-expectations (2.14.5)
|
59
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
60
|
+
rspec-mocks (2.14.6)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
activesupport (~> 3.2)
|
67
|
+
jeweler (~> 2)
|
68
|
+
rspec (~> 2.14)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 rob
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
TCFG
|
2
|
+
====
|
3
|
+
|
4
|
+
TCFG (pronounced "tee config") is test suite configuration for the real world. TCFG offers:
|
5
|
+
|
6
|
+
* Support for easily controlling which environment your tests execute against
|
7
|
+
|
8
|
+
* A tiered structure to configuration which allows for every kind of configuration scenario to be supported.
|
9
|
+
|
10
|
+
Background
|
11
|
+
----------
|
12
|
+
|
13
|
+
The Wiki contains more in depth information. Some good places to start:
|
14
|
+
|
15
|
+
* [Test suite configuration manifesto](https://github.com/rschultheis/tcfg/wiki/Test-Suite-Configuration-Manifesto)
|
16
|
+
|
17
|
+
* [The tiers of configuration in TCFG](https://github.com/rschultheis/tcfg/wiki/The-tiers-of-configuration-in-TCFG)
|
18
|
+
|
19
|
+
|
20
|
+
Getting started
|
21
|
+
---------------
|
22
|
+
|
23
|
+
### Using in RSpec
|
24
|
+
|
25
|
+
Start by installing the gem:
|
26
|
+
|
27
|
+
$ gem install tcfg
|
28
|
+
|
29
|
+
In the project root, make a yaml file called tcfg.yml that contains all configuration you want to be able to control. For a selenium suite, it might look something like this:
|
30
|
+
|
31
|
+
---
|
32
|
+
#start with basic defaults
|
33
|
+
BROWSER: firefox
|
34
|
+
BASE_URL: http://localhost:8080
|
35
|
+
LOG_LEVEL: INFO
|
36
|
+
|
37
|
+
#This is a special section with overrides by 'environment'
|
38
|
+
tcfg_environments:
|
39
|
+
QA:
|
40
|
+
BASE_URL: http://qa.mysite.com
|
41
|
+
|
42
|
+
Production:
|
43
|
+
BASE_URL: https://mysite.com
|
44
|
+
|
45
|
+
Then configure RSpec to use tcfg in your spec helper file (typically called spec/spec_helper.rb):
|
46
|
+
|
47
|
+
require 'tcfg'
|
48
|
+
|
49
|
+
RSpec.configure do |config|
|
50
|
+
config.include TCFG::Helper
|
51
|
+
end
|
52
|
+
|
53
|
+
Now you can access configuration in any before, after, or it block, like:
|
54
|
+
|
55
|
+
require 'selenium-webdriver'
|
56
|
+
RSpec.configure do |config|
|
57
|
+
config.before(:all) do
|
58
|
+
@browser = Selenium::WebDriver.for tcfg['BROWSER']
|
59
|
+
end
|
60
|
+
|
61
|
+
config.before(:each) do
|
62
|
+
@browser.get tcfg['BASE_URL']
|
63
|
+
end
|
64
|
+
|
65
|
+
config.after(:all) do
|
66
|
+
@browser.quit
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
If you need to access configuration outside of a before, after, or it block you can use the TCFG module directly:
|
71
|
+
|
72
|
+
Log.level = TCFG.tcfg['LOG_LEVEL']
|
73
|
+
|
74
|
+
To control your test suite, you can use environment variables. To change the browser used:
|
75
|
+
|
76
|
+
#To execute with all default configuration
|
77
|
+
$ rspec
|
78
|
+
|
79
|
+
#To change the browser used
|
80
|
+
$ TCFG_BROWSER=chrome rspec
|
81
|
+
|
82
|
+
#To change which environment the tests execute against:
|
83
|
+
$ TCFG_ENVIRONMENT=QA rspec
|
84
|
+
|
85
|
+
|
86
|
+
### Other uses
|
87
|
+
|
88
|
+
TCFG is a general purpose configuration framework. It should be possible to use with most Ruby test frameworks or even for non testing uses. If you have a use and aren't sure how to handle it with tcfg, file an issue we'll see if we can help you out.
|
89
|
+
|
90
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "tcfg"
|
18
|
+
gem.homepage = "http://github.com/rschultheis/tcfg"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Test suite configuration for the real world"
|
21
|
+
gem.description = "A tiered approach to configuration which allows for full control of your test suite through environment variables"
|
22
|
+
gem.email = "robert.schultheis@gmail.com"
|
23
|
+
gem.authors = ["robert schultheis"]
|
24
|
+
gem.files = [
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.md",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
] + Dir.glob('lib/**/*.rb')
|
32
|
+
|
33
|
+
# dependencies defined in Gemfile
|
34
|
+
|
35
|
+
end
|
36
|
+
Jeweler::RubygemsDotOrgTasks.new
|
37
|
+
|
38
|
+
require 'rspec/core'
|
39
|
+
require 'rspec/core/rake_task'
|
40
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
41
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :spec
|
45
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/tcfg.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
require 'active_support/core_ext/hash/deep_merge'
|
4
|
+
|
5
|
+
require_relative 'tcfg_base'
|
6
|
+
|
7
|
+
module TCFG
|
8
|
+
module Helper
|
9
|
+
DEFAULT_CONFIG_FILE = 'tcfg.yml'
|
10
|
+
|
11
|
+
def tcfg
|
12
|
+
unless @resolved_config
|
13
|
+
resolved_config = ActiveSupport::HashWithIndifferentAccess.new
|
14
|
+
|
15
|
+
#tier 1 code defaults
|
16
|
+
resolved_config.merge! tier_code_defaults
|
17
|
+
|
18
|
+
#tier 2, the main config file
|
19
|
+
resolved_config.merge! tier_config_file
|
20
|
+
|
21
|
+
#tier 3, the main config file
|
22
|
+
resolved_config.merge! tier_secret_config_file
|
23
|
+
|
24
|
+
#tier 4, environment overrides
|
25
|
+
resolved_config.merge! tier_environment_overrides
|
26
|
+
|
27
|
+
#tier 5, environment variable overrides
|
28
|
+
resolved_config.each_pair do |k, v|
|
29
|
+
env_var_name = "TCFG_#{k}"
|
30
|
+
resolved_config[k] = ENV.fetch(env_var_name, v)
|
31
|
+
end
|
32
|
+
@resolved_config = resolved_config
|
33
|
+
end
|
34
|
+
return @resolved_config
|
35
|
+
end
|
36
|
+
|
37
|
+
def tcfg_config_file filename
|
38
|
+
confirm_config_file_existence filename
|
39
|
+
tcfg_reset
|
40
|
+
@tcfg_config_filename = filename
|
41
|
+
end
|
42
|
+
|
43
|
+
def tcfg_secret_config_file filename
|
44
|
+
confirm_config_file_existence filename
|
45
|
+
tcfg_reset
|
46
|
+
@tcfg_secret_config_filename = filename
|
47
|
+
end
|
48
|
+
|
49
|
+
def tcfg_set key, value
|
50
|
+
tier_code_defaults[key] = value
|
51
|
+
tcfg_reset
|
52
|
+
return value
|
53
|
+
end
|
54
|
+
|
55
|
+
def tcfg_get key
|
56
|
+
tier_code_defaults[key]
|
57
|
+
end
|
58
|
+
|
59
|
+
def tcfg_reset
|
60
|
+
@resolved_config = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
#define how we handle state for each of the tiers
|
66
|
+
def tier_code_defaults
|
67
|
+
@tcfg_code_defaults ||= ActiveSupport::HashWithIndifferentAccess.new
|
68
|
+
end
|
69
|
+
|
70
|
+
def tier_config_file
|
71
|
+
@tcfg_config_filename ||= DEFAULT_CONFIG_FILE
|
72
|
+
tcfg_load_optional_config_file @tcfg_config_filename
|
73
|
+
end
|
74
|
+
|
75
|
+
def tier_secret_config_file
|
76
|
+
if @tcfg_secret_config_filename
|
77
|
+
tcfg_load_optional_config_file @tcfg_secret_config_filename
|
78
|
+
elsif @tcfg_config_filename
|
79
|
+
ext = File.extname @tcfg_config_filename
|
80
|
+
base = File.basename @tcfg_config_filename, ext
|
81
|
+
dir = File.dirname @tcfg_config_filename
|
82
|
+
possible_secret_filename = dir + '/' + base + '.secret' + ext
|
83
|
+
tcfg_load_optional_config_file possible_secret_filename
|
84
|
+
else
|
85
|
+
{}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def tier_environment_overrides
|
90
|
+
tenv = ENV['TCFG_ENVIRONMENT']
|
91
|
+
return {} unless @tcfg_environments_config and tenv
|
92
|
+
unless @tcfg_environments_config.has_key? tenv
|
93
|
+
raise TCFG::NoSuchEnvironmentError.new "No such environment in configuration '#{tenv}'"
|
94
|
+
end
|
95
|
+
@tcfg_environments_config[tenv].merge({'TCFG_ENVIRONMENT' => tenv})
|
96
|
+
end
|
97
|
+
|
98
|
+
def tcfg_load_optional_config_file filename
|
99
|
+
@tcfg_environments_config ||= ActiveSupport::HashWithIndifferentAccess.new
|
100
|
+
if File.exist? filename
|
101
|
+
file_contents = YAML.load_file filename
|
102
|
+
hashed = ActiveSupport::HashWithIndifferentAccess.new file_contents
|
103
|
+
environments = hashed.delete :tcfg_environments
|
104
|
+
@tcfg_environments_config.deep_merge!(environments) if environments
|
105
|
+
hashed
|
106
|
+
else
|
107
|
+
{}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def confirm_config_file_existence filename
|
112
|
+
unless File.exist? filename
|
113
|
+
raise TCFG::NoSuchConfigFileError.new "No such config file '#{filename}'"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
#custom exceptions
|
120
|
+
class NoSuchEnvironmentError < StandardError; end
|
121
|
+
class NoSuchConfigFileError < StandardError; end
|
122
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tcfg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- robert schultheis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jeweler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
description: A tiered approach to configuration which allows for full control of your
|
56
|
+
test suite through environment variables
|
57
|
+
email: robert.schultheis@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- LICENSE.txt
|
62
|
+
- README.md
|
63
|
+
files:
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- VERSION
|
70
|
+
- lib/tcfg.rb
|
71
|
+
- lib/tcfg/tcfg_base.rb
|
72
|
+
- lib/tcfg/tcfg_helper.rb
|
73
|
+
- lib/tcfg/tcfg_module.rb
|
74
|
+
homepage: http://github.com/rschultheis/tcfg
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.0
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Test suite configuration for the real world
|
98
|
+
test_files: []
|