hobbit-contrib 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2087ac52abe5bb2c5c4569bcf8283c11ab8bf211
4
- data.tar.gz: 1544e7a1465e520b9cd9390e922a02ea93e33348
3
+ metadata.gz: ba27dac2bea807bb25e736cc7c7434195f88d923
4
+ data.tar.gz: 9c04e21b41ebea5084eccb794d0a76c2f986e8bd
5
5
  SHA512:
6
- metadata.gz: 8f02bf743b5869c1d812ac4ea6063931d7c7165d725e1f9a778738c67689c548a456cd32dbffc955cbe42df2d9c4f5de5ba9f7cb734f07674e90d2e095b60c82
7
- data.tar.gz: 4737a3d1692bbc5b180d327142d818ae0383b9cfae21db88bbbb7c5707e43500eb2aeb76f25527cd7433a9995ed5defd0d1bc4c8614a98067447c1b34dfe39e0
6
+ metadata.gz: 250a1cc17556504c69ad5e0d43a751ae5a431bce48819d82bacccb2f5c5047fd3928f18c291c0e3c9f1ae9b753cf041f23e7737daa41d77c83a346ead1f98332
7
+ data.tar.gz: b50979f85f54764f2422419273407a46fec4f0ce9973a61ad4534e349f6c31ec407f1b11b6809042c8d062ed3a6260a052e66738f8cb7c07feb63879f6003547
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.4.2
2
+
3
+ * Make `environment`, `development?`, `production?` and `test?` available
4
+ in class context (in `Hobbit::Environment`).
5
+
1
6
  # 0.4.1
2
7
 
3
8
  * Fix `Hobbit::ErrorHandling`. Now, when an exception is raised, the `error`
data/README.md CHANGED
@@ -71,6 +71,8 @@ run App.new
71
71
  * `production?`: Returns true if the current environment is `:production`.
72
72
  * `test?`: Returns true if the current environment is `:test`.
73
73
 
74
+ **Note**: All methods are available at class and instance context.
75
+
74
76
  ### Hobbit::ErrorHandling
75
77
 
76
78
  This extension provides a way of handling errors raised by your application. To
@@ -1,5 +1,5 @@
1
1
  module Hobbit
2
2
  module Contrib
3
- VERSION = '0.4.1'
3
+ VERSION = '0.4.2'
4
4
  end
5
5
  end
@@ -1,5 +1,9 @@
1
1
  module Hobbit
2
2
  module Environment
3
+ def self.included(othermod)
4
+ othermod.extend self
5
+ end
6
+
3
7
  def environment
4
8
  ENV['RACK_ENV'].to_sym
5
9
  end
@@ -8,4 +12,4 @@ module Hobbit
8
12
  define_method("#{env}?") { environment == env.to_sym }
9
13
  end
10
14
  end
11
- end
15
+ end
@@ -9,19 +9,45 @@ describe Hobbit::Environment do
9
9
  end
10
10
  end
11
11
 
12
+ def with_env(environment)
13
+ env, ENV['RACK_ENV'] = ENV['RACK_ENV'], environment
14
+ yield
15
+ ENV['RACK_ENV'] = env
16
+ end
17
+
18
+ describe '::environment' do
19
+ it 'must return the current environment' do
20
+ with_env('development') do
21
+ app.to_app.class.environment.must_equal :development
22
+ end
23
+ end
24
+ end
25
+
12
26
  describe '#environment' do
13
27
  it 'must return the current environment' do
14
- env, ENV['RACK_ENV'] = ENV['RACK_ENV'], 'development'
15
- app.to_app.environment.must_equal :development
16
- ENV['RACK_ENV'] = env
28
+ with_env('development') do
29
+ app.to_app.environment.must_equal :development
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '::development?' do
35
+ it "must return true if ENV['RACK_ENV'] = :development" do
36
+ with_env('development') do
37
+ app.to_app.class.development?.must_equal true
38
+ end
39
+ end
40
+
41
+ it "must return false if ENV['RACK_ENV'] != :development" do
42
+ app.to_app.class.development?.must_equal false
17
43
  end
18
44
  end
19
45
 
20
46
  describe '#development?' do
21
47
  it "must return true if ENV['RACK_ENV'] = :development" do
22
- env, ENV['RACK_ENV'] = ENV['RACK_ENV'], 'development'
23
- app.to_app.development?.must_equal true
24
- ENV['RACK_ENV'] = env
48
+ with_env('development') do
49
+ app.to_app.development?.must_equal true
50
+ end
25
51
  end
26
52
 
27
53
  it "must return false if ENV['RACK_ENV'] != :development" do
@@ -29,11 +55,23 @@ describe Hobbit::Environment do
29
55
  end
30
56
  end
31
57
 
58
+ describe '::production?' do
59
+ it "must return true if ENV['RACK_ENV'] = :production" do
60
+ with_env('production') do
61
+ app.to_app.class.production?.must_equal true
62
+ end
63
+ end
64
+
65
+ it "must return false if ENV['RACK_ENV'] != :production" do
66
+ app.to_app.class.production?.must_equal false
67
+ end
68
+ end
69
+
32
70
  describe '#production?' do
33
71
  it "must return true if ENV['RACK_ENV'] = :production" do
34
- env, ENV['RACK_ENV'] = ENV['RACK_ENV'], 'production'
35
- app.to_app.production?.must_equal true
36
- ENV['RACK_ENV'] = env
72
+ with_env('production') do
73
+ app.to_app.production?.must_equal true
74
+ end
37
75
  end
38
76
 
39
77
  it "must return false if ENV['RACK_ENV'] != :production" do
@@ -41,15 +79,27 @@ describe Hobbit::Environment do
41
79
  end
42
80
  end
43
81
 
82
+ describe '::test?' do
83
+ it "must return true if ENV['RACK_ENV'] = :test" do
84
+ app.to_app.class.test?.must_equal true
85
+ end
86
+
87
+ it "must return false if ENV['RACK_ENV'] != :test" do
88
+ with_env('development') do
89
+ app.to_app.class.test?.must_equal false
90
+ end
91
+ end
92
+ end
93
+
44
94
  describe '#test?' do
45
95
  it "must return true if ENV['RACK_ENV'] = :test" do
46
96
  app.to_app.test?.must_equal true
47
97
  end
48
98
 
49
99
  it "must return false if ENV['RACK_ENV'] != :test" do
50
- env, ENV['RACK_ENV'] = ENV['RACK_ENV'], 'development'
51
- app.to_app.test?.must_equal false
52
- ENV['RACK_ENV'] = env
100
+ with_env('development') do
101
+ app.to_app.test?.must_equal false
102
+ end
53
103
  end
54
104
  end
55
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobbit-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Mac Adden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-08 00:00:00.000000000 Z
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler