configurethis 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de51c7bf8ff307aa213f4f6431be1fdd79beb4c4
4
+ data.tar.gz: c12f30afd2ac5c311cb13d9974f1d1a3b2c28868
5
+ SHA512:
6
+ metadata.gz: ea2e4efb4bc08bccd90d4e529a3118731273df9599bea18f4a772b4412499f1dd15b0af26d794de8865f4385982c1b1d14ebc6f88217ce31a07c1ea3fdeb10cf
7
+ data.tar.gz: ae2b9a342b327bfd077e013ef825c36eba9d20f597123ac8155a5885c3d29ac812cf97f350efcb2d25952ddfc5e90b4b5f224b77ef1224b1c866427cbbe0a48c
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.org/mattsnyder/configurethis.png?branch=master)](https://travis-ci.org/mattsnyder/configurethis)
2
+ [![Code Climate](https://codeclimate.com/repos/5201505856b1022e8f000a78/badges/b728182dffefc2f344ab/gpa.png)](https://codeclimate.com/repos/5201505856b1022e8f000a78/feed)
2
3
  # Configurethis
3
4
  Clean up your configuration approach by using Configurethis. Configurethis allows you to access your config values using
4
5
  method names instead of string literals to identify which config value you want to retrieve.
@@ -71,7 +72,7 @@ Configurethis.root_path = File.join(Rails.root, "config")
71
72
 
72
73
  If your configuration is dependent on environment variables, you can specify it (Unfortunately at this time you need to do this once per each class that is environmentally dependent):
73
74
  ```ruby
74
- MyConfigurationClass.set_root = RAILS_ENV
75
+ MyConfigurationClass.set_root = Rails.env
75
76
  ```
76
77
 
77
78
  ### Creating a configuration
@@ -107,6 +108,26 @@ class IWantToBeDifferent
107
108
  end
108
109
  ```
109
110
 
111
+ ### Testing
112
+ While working with Configurethis in your specs/tests you can override the configuration
113
+ and avoid using the real configuration files to simulate behavior. This enables you to
114
+ avoid using messing stubbing hierarchies and keep your tests clean!
115
+
116
+ Just pass a hash representing your configuration to `#test_with`.
117
+
118
+ ```ruby
119
+ # my_configuration.rb
120
+ class BourbonConfig
121
+ extend Configurethis
122
+ end
123
+
124
+ # my_behavior_spec.rb
125
+ it "should do some drinking" do
126
+ BourbonConfiguration.test_with({"bourbons" => {"Woodford" => "awesome", "Buffalo Trace" => "ok"} })
127
+ expect( my_behavior.drink("Woodford") ).to eql("awesome") # => true
128
+ end
129
+ ```
130
+
110
131
  ## Contributing
111
132
 
112
133
  1. Fork it
@@ -1,5 +1,6 @@
1
1
  require "configurethis/version"
2
2
  require "configurethis/value_container"
3
+ require "configurethis/mock_configuration"
3
4
  require "configurethis/configuration"
4
5
  require "configurethis/configurethis_properties"
5
6
 
@@ -22,6 +23,17 @@ module Configurethis
22
23
  configuration.root = key.to_s
23
24
  end
24
25
 
26
+ # Meant for testing different scenarios
27
+ # and avoid using the real configuration
28
+ # values in your tests/specs.
29
+ #
30
+ # To use, pass a hash that represents the
31
+ # values you like so that it mirrors the yml files
32
+ # structure.
33
+ def test_with(values)
34
+ @configuration = MockConfiguration.new values
35
+ end
36
+
25
37
  def configure_this_with(path)
26
38
  @configuration_file = path
27
39
  end
@@ -0,0 +1,31 @@
1
+ module Configurethis
2
+ class MockConfiguration
3
+ attr_reader :path
4
+
5
+ def initialize(values)
6
+ @path = "<mocked_configuration>"
7
+ @mock_values = values
8
+ end
9
+
10
+ def root=(key)
11
+ @values = load_configuration.fetch(key)
12
+ rescue ::IndexError
13
+ raise "'#{key}' is not configured in #{path}"
14
+ end
15
+
16
+ def [](key)
17
+ @values ||= load_configuration
18
+ val = @values.fetch(key)
19
+ return ValueContainer.new(val, path) if val.is_a?(Hash)
20
+ val
21
+ rescue ::IndexError
22
+ raise "'#{key}' is not configured in #{path}"
23
+ end
24
+
25
+ def load_configuration
26
+ @mock_values
27
+ end
28
+
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Configurethis
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -50,6 +50,29 @@ describe Configurethis do
50
50
  end
51
51
  end
52
52
 
53
+ describe "providing test values to use" do
54
+ after(:each) { NestedConfig.reload_configuration }
55
+ Given (:config) { NestedConfig }
56
+
57
+ context "when no test values are passed" do
58
+ Given { config.test_with(Hash.new) }
59
+ Then { expect{ config.level1 }.to raise_error(RuntimeError, "'level1' is not configured in <mocked_configuration>") }
60
+ end
61
+
62
+ context "when values are passed" do
63
+ Given { config.test_with({ "level100" => "faked out!"}) }
64
+ Then { expect( config.level100 ).to eql( "faked out!" ) }
65
+
66
+ context "and root value is set" do
67
+ Given { config.test_with( {"qa" => { "alpha" => "a" }, "alpha" => "wrong one"} ) }
68
+ Given { config.set_root = "qa" }
69
+ Then { expect( config.alpha ).to eql( "a" ) }
70
+ end
71
+ end
72
+
73
+
74
+ end
75
+
53
76
  describe "using configured values" do
54
77
  Given { Configurethis.root_path = File.join(File.dirname(__FILE__), 'support/config') }
55
78
 
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configurethis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt Snyder
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-29 00:00:00.000000000 Z
11
+ date: 2013-08-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec-given
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
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
26
  version: 3.0.0
30
27
  description: Clean up your configuration approach by using Configurethis. Configurethis
@@ -47,6 +44,7 @@ files:
47
44
  - lib/configurethis.rb
48
45
  - lib/configurethis/configuration.rb
49
46
  - lib/configurethis/configurethis_properties.rb
47
+ - lib/configurethis/mock_configuration.rb
50
48
  - lib/configurethis/value_container.rb
51
49
  - lib/configurethis/version.rb
52
50
  - spec/configurethis/configurethis_spec.rb
@@ -67,27 +65,26 @@ homepage: https://github.com/mattsnyder/configurethis
67
65
  licenses:
68
66
  - MIT
69
67
  - GPL-2
68
+ metadata: {}
70
69
  post_install_message:
71
70
  rdoc_options: []
72
71
  require_paths:
73
72
  - lib
74
73
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
74
  requirements:
77
- - - ! '>='
75
+ - - '>='
78
76
  - !ruby/object:Gem::Version
79
77
  version: '0'
80
78
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
79
  requirements:
83
- - - ! '>='
80
+ - - '>='
84
81
  - !ruby/object:Gem::Version
85
82
  version: '0'
86
83
  requirements: []
87
84
  rubyforge_project:
88
- rubygems_version: 1.8.25
85
+ rubygems_version: 2.0.6
89
86
  signing_key:
90
- specification_version: 3
87
+ specification_version: 4
91
88
  summary: Clean up your configuration approach by using Configurethis. Configurethis
92
89
  allows you to access your config values using method names instead of string literals
93
90
  to identify which config value you want to retrieve.