subelsky_power_tools 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- subelsky_power_tools (1.0.2)
4
+ subelsky_power_tools (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -3,12 +3,22 @@ require "subelsky_power_tools"
3
3
  module SubelskyPowerTools::Environment
4
4
  extend self
5
5
 
6
+ def extract!(*keys)
7
+ get_keys(keys,true)
8
+ end
9
+
6
10
  def extract(*keys)
11
+ get_keys(keys,false)
12
+ end
13
+
14
+ private
15
+
16
+ def get_keys(keys,raise_error_if_blank)
7
17
  keys.map! { |k| k.upcase.to_s }
8
18
  msg = "Must specify #{keys.join(", ")}"
9
19
 
10
20
  keys.inject([]) do |total,key|
11
- fail msg if ENV[key].to_s.strip.empty?
21
+ fail msg if raise_error_if_blank && ENV[key].to_s.strip.empty?
12
22
  total << ENV[key]
13
23
  end
14
24
  end
@@ -1,3 +1,3 @@
1
1
  module SubelskyPowerTools
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -2,31 +2,59 @@ require "spec_helper"
2
2
  require "subelsky_power_tools/environment"
3
3
 
4
4
  describe SubelskyPowerTools::Environment do
5
- def conduct_test(val1 = "shaz",val2 = "bot")
6
- ENV['_SPT_EE_TEST_VALUE1'] = val1
7
- ENV['_SPT_EE_TEST_VALUE2'] = val2
8
- SubelskyPowerTools::Environment.extract(:'_spt_ee_test_value1',:'_spt_ee_test_value2')
9
- end
5
+ context "extraction of required environment variables" do
6
+ def conduct_test(val1 = "shaz",val2 = "bot")
7
+ ENV['_SPT_EE_TEST_VALUE1'] = val1
8
+ ENV['_SPT_EE_TEST_VALUE2'] = val2
9
+ SubelskyPowerTools::Environment.extract!(:'_spt_ee_test_value1',:'_spt_ee_test_value2')
10
+ end
10
11
 
11
- it "succeeds if all specified variables are non-blank" do
12
- expect { conduct_test }.not_to raise_error
13
- end
12
+ it "succeeds if all specified variables are non-blank" do
13
+ expect { conduct_test }.not_to raise_error
14
+ end
14
15
 
15
- it "fails the program if any specified variable is blank" do
16
- expect { conduct_test(" ","bot") }.to raise_error(RuntimeError)
17
- end
16
+ it "raises error if any specified variable is blank" do
17
+ expect { conduct_test(" ","bot") }.to raise_error(RuntimeError)
18
+ end
18
19
 
19
- it "fails the program if any specified variable is zero-width" do
20
- expect { conduct_test("shaz","") }.to raise_error(RuntimeError)
21
- end
20
+ it "raises error if any specified variable is zero-width" do
21
+ expect { conduct_test("shaz","") }.to raise_error(RuntimeError)
22
+ end
23
+
24
+ it "raises error if any specified variable is nil" do
25
+ expect { conduct_test("",nil) }.to raise_error(RuntimeError)
26
+ end
22
27
 
23
- it "fails the program if any specified variable is nil" do
24
- expect { conduct_test("",nil) }.to raise_error(RuntimeError)
28
+ it "returns the value of the extracted variables" do
29
+ val1, val2 = conduct_test("alpha","beta")
30
+ val1.should == "alpha"
31
+ val2.should == "beta"
32
+ end
25
33
  end
26
34
 
27
- it "returns the value of the extracted variables" do
28
- val1, val2 = conduct_test("alpha","beta")
29
- val1.should == "alpha"
30
- val2.should == "beta"
35
+ context "extraction of optional environment variables" do
36
+ def conduct_test(val1 = "shaz",val2 = "bot")
37
+ ENV['_SPT_EE_TEST_VALUE1'] = val1
38
+ ENV['_SPT_EE_TEST_VALUE2'] = val2
39
+ SubelskyPowerTools::Environment.extract(:'_spt_ee_test_value1',:'_spt_ee_test_value2')
40
+ end
41
+
42
+ it "succeeds if any specified variable is blank" do
43
+ expect { conduct_test(" ","bot") }.not_to raise_error
44
+ end
45
+
46
+ it "succeeds if any specified variable is zero-width" do
47
+ expect { conduct_test("shaz","") }.not_to raise_error
48
+ end
49
+
50
+ it "suceeds if any specified variable is nil" do
51
+ expect { conduct_test("",nil) }.not_to raise_error
52
+ end
53
+
54
+ it "returns the value of the extracted variables" do
55
+ val1, val2 = conduct_test(nil,"beta")
56
+ val1.should == nil
57
+ val2.should == "beta"
58
+ end
31
59
  end
32
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subelsky_power_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-14 00:00:00.000000000 -04:00
12
+ date: 2011-08-21 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &2160525580 !ruby/object:Gem::Requirement
17
+ requirement: &2164636140 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2160525580
25
+ version_requirements: *2164636140
26
26
  description: ! "This is a collection of Ruby extensions and utilities I've been carting
27
27
  around from project to project. \nMany are taken from the Facets project (I just
28
28
  don't want to include that whole gem in my codebases).\n"