jumanjiman_spec_helper 0.0.2 → 0.1.0

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.
data/CONTRIBUTING.md CHANGED
@@ -5,6 +5,7 @@
5
5
  3. Commit your changes (`git commit -am 'Add some feature'`)
6
6
  4. Push to the branch (`git push origin my-new-feature`)
7
7
  5. Create new Pull Request
8
+ 6. Check https://travis-ci.org/jumanjiman/jumanjiman_spec_helper/pull_requests
8
9
 
9
10
 
10
11
  ## Contributor agreement
data/Gemfile CHANGED
@@ -3,3 +3,6 @@ source 'https://rubygems.org'
3
3
 
4
4
  # Specify your gem's dependencies in jumanjiman_spec_helper.gemspec
5
5
  gemspec
6
+
7
+ # Before extending this, make sure you read:
8
+ # http://guides.rubygems.org/patterns/
data/README.md CHANGED
@@ -22,15 +22,74 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ ### Use all or parts of the gem's functionality
26
+
27
+ This gem uses [Bundler](http://gembundler.com/) for setup.
28
+ The simplest way is to `require 'jumanjiman_spec_helper'`,
29
+ which includes *all* functionality.
30
+
31
+ The other way is to include just the specific functionality
32
+ you want or need. The sections below assume you want to use
33
+ targeted functionality. Each example demonstrates how to include
34
+ and activate the specific functionality for each example.
35
+
36
+ ### Bundler
37
+
38
+ This gem can wrap bundler functionality. If you want your
39
+ `Rakefile` to bundle gem dependencies, the easiest way is to
40
+ add at the top of your `Rakefile`:
41
+
42
+ ```ruby
43
+ require 'bundler/setup'
44
+ require 'jumanjiman_spec_helper/bundle'
45
+ # lazy-load default gem environment
46
+ JumanjimanSpecHelper::Bundle.setup
47
+ ```
48
+
49
+ With the above code in place, it will suggest the correct bundler
50
+ commands whenever gem dependencies need to be updated according
51
+ to the Gemfile or gemspec in your project. The default action
52
+ shown above is to use `Bundler.setup :default`, which locks
53
+ dependencies and load paths, but delays loading any given gem
54
+ until it is actually required. This speeds startup time.
55
+ I call this *lazy-loading*.
56
+
57
+ An alternative is to *early-load* all gems at startup time.
58
+ To early-load your gems, use:
59
+
60
+ ```ruby
61
+ require 'bundler/setup'
62
+ require 'jumanjiman_spec_helper/bundle'
63
+ # early-load default gem environment
64
+ JumanjimanSpecHelper::Bundle.setup :default, true
65
+ ```
66
+
67
+ You can also specify different gem groups, such as:
68
+
69
+ ```ruby
70
+ require 'bundler/setup'
71
+ require 'jumanjiman_spec_helper/bundle'
72
+ # early-load development gem environment
73
+ JumanjimanSpecHelper::Bundle.setup :development, true
74
+ ```
75
+
25
76
  ### Shared contexts
26
77
 
27
78
  #### Environment variables
28
79
 
29
80
  Environment variables created in one rspec example can invalidate
30
81
  other examples, giving either false positives or false failures.
31
- This module cleans up your environment between examples.
82
+
83
+ The default rspec configuration shows three behaviors:
84
+
85
+ * Preserve environment variables that exist *before* rspec examples
86
+ * Clobber environment variables modified *within* rspec examples
87
+ * Preserve environment variables created *within* rspec examples
88
+
89
+ This module cleans up your environment between examples:
32
90
 
33
91
  * Preserve environment variables that exist *before* rspec examples
92
+ * Restore environment variables modified *within* rspec examples
34
93
  * Discard environment variables created *within* rspec examples
35
94
 
36
95
  Add to `spec/spec_helper.rb`:
@@ -43,5 +102,5 @@ RSpec.configure do |c|
43
102
  end
44
103
  ```
45
104
 
46
- That's it! Now environment variables will be automatically
105
+ That's it! Now environment variables are automatically
47
106
  cleaned up between rspec examples.
data/Rakefile CHANGED
@@ -1,13 +1,8 @@
1
1
  # vim: set ts=2 sw=2 ai et ruler:
2
2
 
3
- # use the local git version of library for dev
4
- lib = File.expand_path('../lib', __FILE__)
5
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
-
7
- # library of useful (to me) utils
8
- require 'jumanjiman_spec_helper'
9
-
10
3
  # lock dependencies and load paths, but lazy-load gems
4
+ require 'bundler/setup'
5
+ require 'jumanjiman_spec_helper/bundle'
11
6
  JumanjimanSpecHelper::Bundle.setup :development
12
7
 
13
8
  # bundle skeleton
@@ -23,7 +23,11 @@ Gem::Specification.new do |gem|
23
23
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
24
  gem.require_paths = ["lib"]
25
25
 
26
+ # == Dependencies ==
27
+ # http://guides.rubygems.org/patterns/
28
+ # http://docs.rubygems.org/read/chapter/20#dependencies
26
29
  # http://docs.rubygems.org/read/chapter/20#development_dependencies
30
+
27
31
  gem.add_development_dependency 'rake', '>= 10.0'
28
32
  gem.add_development_dependency 'rspec-core', '2.12.2'
29
33
  gem.add_development_dependency 'rspec', '2.12.0'
@@ -1,7 +1,7 @@
1
1
  # vim: set ts=2 sw=2 ai et ruler:
2
2
  require "jumanjiman_spec_helper/version"
3
+ require 'jumanjiman_spec_helper/bundle'
4
+ require 'jumanjiman_spec_helper/environment_context'
3
5
 
4
6
  module JumanjimanSpecHelper
5
- require 'jumanjiman_spec_helper/bundle'
6
- require 'jumanjiman_spec_helper/environment_context'
7
7
  end
@@ -1,10 +1,17 @@
1
1
  # vim: set ts=2 sw=2 ai et ruler:
2
+ dependencies = [
3
+ 'bundler',
4
+ 'yaml',
5
+ ]
6
+ begin
7
+ dependencies.each {|gem| require gem}
8
+ rescue
9
+ require 'rubygems' # ugh, support older distros
10
+ retry
11
+ end
12
+
2
13
  module JumanjimanSpecHelper
3
14
  module Bundle
4
- require 'rubygems' # ugh, support older distros
5
- require 'bundler'
6
- require 'yaml'
7
-
8
15
  # lock dependencies and setup load paths
9
16
  # http://myronmars.to/n/dev-blog/2012/12/5-reasons-to-avoid-bundler-require
10
17
  # http://anti-pattern.com/bundler-setup-vs-bundler-require
@@ -1,4 +1,4 @@
1
1
  # vim: set ts=2 sw=2 ai et ruler:
2
2
  module JumanjimanSpecHelper
3
- VERSION = '0.0.2'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -23,7 +23,7 @@ describe 'JumanjimanSpecHelper::EnvironmentContext' do
23
23
  end
24
24
 
25
25
  context 'when included' do
26
- it 'preserves environment variable created before example' do
26
+ it 'preserves pre-existing env var' do
27
27
  group = RSpec::Core::ExampleGroup.describe do
28
28
  include JumanjimanSpecHelper::EnvironmentContext
29
29
  end
@@ -31,7 +31,16 @@ describe 'JumanjimanSpecHelper::EnvironmentContext' do
31
31
  ENV[key1].should == value
32
32
  end
33
33
 
34
- it 'discards environment variable created within example' do
34
+ it 'restores pre-existing env var if changed within example' do
35
+ group = RSpec::Core::ExampleGroup.describe do
36
+ include JumanjimanSpecHelper::EnvironmentContext
37
+ it {ENV[key1] = value.reverse} # change env var in example
38
+ end
39
+ group.run(@reporter)
40
+ ENV[key1].should == value
41
+ end
42
+
43
+ it 'discards env var if created within example' do
35
44
  group = RSpec::Core::ExampleGroup.describe do
36
45
  include JumanjimanSpecHelper::EnvironmentContext
37
46
  it {ENV[key2] = value} # create env var in example
@@ -41,15 +50,23 @@ describe 'JumanjimanSpecHelper::EnvironmentContext' do
41
50
  end
42
51
  end
43
52
 
44
- context 'when not included' do
45
- it 'preserves environment variable created before example' do
53
+ context 'when not included (i.e., default rspec behavior)' do
54
+ it 'preserves pre-existing env var' do
46
55
  group = RSpec::Core::ExampleGroup.describe do
47
56
  end
48
57
  group.run(@reporter)
49
58
  ENV[key1].should == value
50
59
  end
51
60
 
52
- it 'preserves environment variable created within example' do
61
+ it 'clobbers env var if changed within example' do
62
+ group = RSpec::Core::ExampleGroup.describe do
63
+ it {ENV[key1] = value.reverse} # change env var in example
64
+ end
65
+ group.run(@reporter)
66
+ ENV[key1].should == value.reverse
67
+ end
68
+
69
+ it 'persists env var if created within example' do
53
70
  group = RSpec::Core::ExampleGroup.describe do
54
71
  it {ENV[key2] = value} # create env var in example
55
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jumanjiman_spec_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-12 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  segments:
161
161
  - 0
162
- hash: -4202932635494857772
162
+ hash: 1737154054071565292
163
163
  required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  none: false
165
165
  requirements:
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  segments:
170
170
  - 0
171
- hash: -4202932635494857772
171
+ hash: 1737154054071565292
172
172
  requirements: []
173
173
  rubyforge_project:
174
174
  rubygems_version: 1.8.25