testbeds 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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/testbeds
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ before_script:
2
+ # only if you don't commit the testbeds to git
3
+ - generate-testbeds
4
+
5
+ script: "rake testbeds:current:rspec"
6
+
7
+ gemfiles:
8
+ - path/to/gemfiles/rails-3.2
9
+ - path/to/gemfiles/rails-4.0
data/Bedfile ADDED
@@ -0,0 +1,15 @@
1
+ store_in "spec/testbeds"
2
+
3
+ testbeds do
4
+ gemfiles 'gemfiles/rails-3.2',
5
+ 'gemfiles/rails-4.0'
6
+
7
+ init do
8
+ run "rails", "new", name, "--skip-bundle", "--skip-gemfile"
9
+ chdir name
10
+ run "rails", "g", "rspec:install"
11
+ end
12
+
13
+ rakefile '<%= name %>/Rakefile'
14
+ depend_on '<%= name %>/config/application.rb'
15
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in testbeds.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Colin MacKenzie IV
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # Testbeds
2
+
3
+ It's not very easy to test your gem in many different environments. Take
4
+ for example Rails: how can you know that your gem, tested in a Rails 3.2 app,
5
+ will work in Rails 4.0, without regenerating the entire app? And after doing
6
+ so, how will you ensure backward compatibility to 3.2 going forward?
7
+
8
+ Those are the sorts of problems this gem is meant to help with.
9
+
10
+ ## 1. Pull in the gem (duh)
11
+
12
+ First, add this gem to your project's list of development dependencies:
13
+
14
+ # in my-gem.gemspec
15
+ gem.add_development_dependency 'testbeds'
16
+
17
+ Then install it, of course.
18
+
19
+ ## 2. Create Gemfiles (yes, more than one)
20
+
21
+ Add a Gemfile for each testbed you intend to implement. For example, you
22
+ might have a file in `gemfiles/rails-3.2` describing your dependencies for
23
+ testing within Rails 3.2, and another in `gemfiles/rails-4.0` which could
24
+ have a completely different set of dependencies.
25
+
26
+ ## 3. The Bedfile
27
+
28
+ Then, create a `Bedfile` and use the handy-dandy DSL to build up your
29
+ testbeds. Here's an example `Bedfile`:
30
+
31
+ # store testbeds in spec/testbeds/*
32
+ store_in "spec/testbeds"
33
+
34
+ testbeds do
35
+ # create 2 testbeds, one for Rails 3.2 and the other for Rails 4.0
36
+ gemfiles 'gemfiles/rails-3.2',
37
+ 'gemfiles/rails-4.0'
38
+
39
+ init do
40
+ # when generating each testbed, first generate a Rails app...
41
+ run "rails", "new", name, "--skip-bundle", "--skip-gemfile"
42
+ chdir name
43
+
44
+ # ...and then run the rspec-rails installer.
45
+ run "rails", "g", "rspec:install"
46
+ end
47
+
48
+ # Load this Rakefile. More on this later.
49
+ rakefile '<%= name %>/Rakefile'
50
+
51
+ # Load this file as a dependency whenever code is executed in
52
+ # the context of this testbed. More on this later.
53
+ depend_on '<%= name %>/config/application.rb'
54
+ end
55
+
56
+ There are only a few methods to be aware of:
57
+
58
+ * `store_in` - sets the destination directory which will serve as the
59
+ root of all of your testbeds. This is where the projects will be
60
+ generated.
61
+
62
+ * `testbeds do ... end` - Sets up one or more testbeds. You can call this
63
+ method more than once, with different setup code for each invocation,
64
+ or you can just call this method once.
65
+
66
+ * `gemfiles` - Takes a list of paths to Gemfiles, relative to the
67
+ `Bedfile`. Each Gemfile represents a testbed. All of the other set-up
68
+ in this `testbeds do ... end` block will be duplicated once for each
69
+ Gemfile.
70
+
71
+ * `init do ... end` - Runs the given block when a testbed is being
72
+ generated. This allows you to take whatever steps would be normally
73
+ taken by a user of your gem within the target environment. In the
74
+ above example, we generate a Rails application and then run the
75
+ rspec-rails installer, but this is only an example.
76
+
77
+ * `rakefile` - Takes a path relative to `store_in` for loading Rake tasks.
78
+ In your main `Rakefile`, you can just `require 'testbeds/rake'`. See
79
+ the `Rake` section, below.
80
+
81
+ * `depend_on` - Specifies the files within the testbed(s) which must be
82
+ loaded whenever the testbed is being used. See the `Rake` section, below.
83
+
84
+ ## 4. Generating Testbeds
85
+
86
+ When you're ready to build your testbeds, run the `generate-testbeds` script
87
+ that ships with this gem. It will remove everything in the `store_in`
88
+ directory (so watch out!) and then start generating testbeds from scratch.
89
+ We purposely wipe out the previous state here, because we want to be able to
90
+ build up each testbed from a clean slate. In fact, you could opt not to even
91
+ commit the `store_in` directory to Git. (I haven't decided yet whether to
92
+ consider adding `store_in` to `.gitignore` a best practice, so consider it
93
+ a matter of opinion.)
94
+
95
+ At each stage of testbed generation, the command that is about to be executed
96
+ is printed to the screen for your reference. This way, if it fails, you will
97
+ know exactly at what point the failure occurred.
98
+
99
+ Here's an example of what testbed generation looks like:
100
+
101
+ colin in testbeds $ generate-testbeds
102
+
103
+ rm -rf /Users/colin/projects/gems/testbeds/spec/testbeds
104
+ mkdir -p /Users/colin/projects/gems/testbeds/spec/testbeds
105
+ export BUNDLE_GEMFILE="/Users/colin/projects/gems/testbeds/gemfiles/rails-3.2"
106
+ bundle install
107
+ bundle exec rails new rails-3.2 --skip-bundle --skip-gemfile
108
+ bundle exec rails g rspec:install
109
+
110
+ export BUNDLE_GEMFILE="/Users/colin/projects/gems/testbeds/gemfiles/rails-4.0"
111
+ bundle install
112
+ bundle exec rails new rails-4.0 --skip-bundle --skip-gemfile
113
+ bundle exec rails g rspec:install
114
+
115
+
116
+ ### Note about `BUNDLE_GEMFILE`
117
+
118
+ As you can see, `BUNDLE_GEMFILE` is exported at each stage. This gem relies
119
+ heavily on Bundler in this way. I think it's probably a bad idea to execute
120
+ `bundle execute generate-testbeds`, as this will create an environment that
121
+ conflicts with the testbed environments. I'm not sure what to expect in such
122
+ a state. You have been warned -- but I'll still accept pull requests if it
123
+ leads to fixable bugs.
124
+
125
+ ## 5. Rake
126
+
127
+ Instead of trying to guess at a once-size-fits-all set of Rake tasks, I
128
+ decided after some deliberation that this gem should instead focus on
129
+ augmenting tasks written _by you_. So it's not a one-line drop-in sort of
130
+ thing. Instead it provides you the tools you need to run a Rake task
131
+ in one or more testbeds of your choosing.
132
+
133
+ Here's a typical `Rakefile` that makes use of this gem:
134
+
135
+ # in Rakefile
136
+ require 'testbeds/rake'
137
+ require 'rspec/core/rake_task'
138
+
139
+ # each_testbed yields a testbed itself, and also creates the corresponding
140
+ # Rake namespace for the testbed.
141
+ each_testbed do |testbed| # namespace 'testbed:rails-3.2'
142
+
143
+ # create a namespaced rspec task for each testbed
144
+ desc "run rspec tests in #{testbed.name}"
145
+ task :rspec do
146
+ ENV['BUNDLE_GEMFILE'] = testbed.gemfile
147
+
148
+ # so here we'll create an RSpec task at runtime, and then invoke
149
+ # it right away. You don't have to do it this way, but I chose to,
150
+ # in order to silence some RSpec cruft at the command line.
151
+ RSpec::Core::RakeTask.new("_rspec") do |t|
152
+ opts = testbed.dependencies.collect { |dep| ['-r', dep] }.flatten
153
+ t.rspec_opts = opts
154
+ end
155
+
156
+ Rake::Task["_rspec"].invoke
157
+ end
158
+
159
+ end
160
+
161
+ desc 'run rspec tests in each testbed consecutively'
162
+ task :rspec do
163
+ each_testbed do |testbed|
164
+ raise unless system "rake #{testbed.namespace}:rspec"
165
+ end
166
+ end
167
+
168
+ When you have a `Rakefile` like this, running `rake --tasks` will show
169
+ about what you'd expect:
170
+
171
+ rake build # Build testbeds-0.0.1.gem into the pkg directory.
172
+ rake install # Build and install testbeds-0.0.1.gem into system gems.
173
+ rake release # Create tag v0.0.1 and build and push testbeds-0.0.1.gem to Rubygems
174
+ rake rspec # run rspec tests in each testbed consecutively
175
+ rake testbed:rails-3.2:rspec # run rspec tests in rails-3.2
176
+ rake testbed:rails-4.0:rspec # run rspec tests in rails-4.0
177
+
178
+ As you can see, we've namespaced each `rspec` task into its own testbed
179
+ namespace. This allows us to run the specs under, say, just the `rails-3.2`
180
+ testbed, ignoring for the moment the same specs under `rails-4.0`. We also
181
+ have the no-namespace `rake rspec` task, which will iterate through each
182
+ testbed and execute its specs consecutively. If any one of these fails,
183
+ the whole process will be aborted.
184
+
185
+ ### Testbed Rake Tasks
186
+
187
+ There's one more thing you can do that is really cool, but not so obvious.
188
+ If you export the environment variable `BUNDLE_GEMFILE` pointing to one of
189
+ your testbed Gemfiles, then you get:
190
+
191
+ $ BUNDLE_GEMFILE=gemfiles/rails-3.2 rake -T
192
+
193
+ rake build # Build testbeds-0.0.1.gem into the pkg directory.
194
+ rake install # Build and install testbeds-0.0.1.gem into system gems.
195
+ rake release # Create tag v0.0.1 and build and push testbeds-0.0.1.gem to Rubygems
196
+ rake rspec # run rspec tests in each testbed consecutively
197
+ rake testbed:current:about # List versions of all Rails frameworks and the environment
198
+ rake testbed:current:assets:clean # Remove compiled assets
199
+ rake testbed:current:assets:precompile # Compile all the assets named in config.assets.precompile
200
+ rake testbed:current:db:create # Create the database from config/database.yml for the current Rails.env (use db:create:a...
201
+ rake testbed:current:db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
202
+ rake testbed:current:db:fixtures:load # Load fixtures into the current environment's database.
203
+ rake testbed:current:db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
204
+ < snip, long list >
205
+ rake testbed:current:tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
206
+ rake testbed:rails-3.2:rspec # run rspec tests in rails-3.2
207
+ rake testbed:rails-4.0:rspec # run rspec tests in rails-4.0
208
+
209
+ As you can see, this syntax creates another namespace, `testbed:current`,
210
+ which contains the Rake tasks loaded for this testbed. This gives you a
211
+ convenient handle for e.g. running migrations and the like without having
212
+ to move from testbed to testbed.
213
+
214
+ ## 6. Travis
215
+
216
+ You test on travis-ci.org, right? Yes, of course you do, and you want to run
217
+ your tests on each testbed, every time you commit. Here's how:
218
+
219
+ # in .travis.yml
220
+ before_script:
221
+ # only if you don't commit the testbeds to git
222
+ - generate-testbeds
223
+
224
+ script: "rake testbeds:current:rspec"
225
+
226
+ gemfile:
227
+ - path/to/gemfiles/rails-3.2
228
+ - path/to/gemfiles/rails-4.0
229
+
230
+
231
+ ## Contributing
232
+
233
+ 1. Fork it
234
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
235
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
236
+ 4. Push to the branch (`git push origin my-new-feature`)
237
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ # in Rakefile
4
+ require 'testbeds/rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ each_testbed do |testbed| # namespace 'testbed:rails-3.2'
8
+ desc "run rspec tests in #{testbed.name}"
9
+ task :rspec do
10
+ ENV['BUNDLE_GEMFILE'] = testbed.gemfile
11
+ RSpec::Core::RakeTask.new("_rspec") do |t|
12
+ opts = testbed.dependencies.collect { |dep| ['-r', dep] }.flatten
13
+ t.rspec_opts = opts
14
+ end
15
+ Rake::Task["_rspec"].invoke
16
+ end
17
+ end
18
+
19
+ desc 'run rspec tests in each testbed consecutively'
20
+ task :rspec do
21
+ each_testbed do |testbed|
22
+ raise unless system "rake #{testbed.namespace}:rspec"
23
+ end
24
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../lib/testbeds', File.dirname(__FILE__))
4
+ require 'fileutils'
5
+
6
+ include FileUtils
7
+
8
+ def run *command
9
+ puts "bundle exec #{command.join(' ')}"
10
+ if ENV["VERBOSE"]
11
+ if command.length == 1
12
+ result = system "bundle exec #{command}"
13
+ else
14
+ result = system "bundle", "exec", *command.collect { |c| c.to_s }
15
+ end
16
+ raise "Command failed" unless result
17
+ else
18
+ output = `bundle exec #{command.join(' ')}`
19
+ raise "Command failed\n\n#{output}" unless $?.success?
20
+ end
21
+ end
22
+
23
+ if testbed = Testbeds.current
24
+ testbed_directory = testbed.store_in.to_s
25
+
26
+ chdir testbed_directory
27
+
28
+ puts 'bundle install'
29
+ if ENV['VERBOSE']
30
+ unless system 'bundle install'
31
+ raise "Couldn't install bundle for testbed #{testbed.name}"
32
+ end
33
+ else
34
+ output = `bundle install`
35
+ unless $?.success?
36
+ raise "Couldn't install bundle for testbed #{testbed.name}\n\n#{output}"
37
+ end
38
+ end
39
+
40
+ testbed.run_init_script
41
+ else
42
+ cleared = {}
43
+ Testbeds.each do |testbed|
44
+ testbed_directory = testbed.store_in.to_s
45
+
46
+ unless cleared[testbed_directory]
47
+ if File.directory?(testbed_directory)
48
+ puts "rm -rf #{testbed_directory}"
49
+ rm_rf testbed_directory
50
+ cleared[testbed_directory] = 1
51
+ end
52
+
53
+ puts "mkdir -p #{testbed_directory}"
54
+ mkdir_p testbed_directory
55
+ end
56
+
57
+ puts "export BUNDLE_GEMFILE=#{testbed.gemfile.to_s.inspect}"
58
+ ENV['BUNDLE_GEMFILE'] = testbed.gemfile
59
+ raise "Testbed #{testbed.name} generation failed" unless system $0
60
+ puts
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 3.2'
4
+ gem 'rspec-rails'
@@ -0,0 +1,98 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.0)
5
+ actionpack (= 3.2.0)
6
+ mail (~> 2.4.0)
7
+ actionpack (3.2.0)
8
+ activemodel (= 3.2.0)
9
+ activesupport (= 3.2.0)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.0)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.1)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.2)
17
+ activemodel (3.2.0)
18
+ activesupport (= 3.2.0)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.0)
21
+ activemodel (= 3.2.0)
22
+ activesupport (= 3.2.0)
23
+ arel (~> 3.0.0)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.0)
26
+ activemodel (= 3.2.0)
27
+ activesupport (= 3.2.0)
28
+ activesupport (3.2.0)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.4)
33
+ diff-lcs (1.2.4)
34
+ erubis (2.7.0)
35
+ hike (1.2.1)
36
+ i18n (0.6.1)
37
+ journey (1.0.4)
38
+ json (1.7.5)
39
+ mail (2.4.4)
40
+ i18n (>= 0.4.0)
41
+ mime-types (~> 1.16)
42
+ treetop (~> 1.4.8)
43
+ mime-types (1.22)
44
+ multi_json (1.7.2)
45
+ polyglot (0.3.3)
46
+ rack (1.4.1)
47
+ rack-cache (1.2)
48
+ rack (>= 0.4)
49
+ rack-ssl (1.3.2)
50
+ rack
51
+ rack-test (0.6.2)
52
+ rack (>= 1.0)
53
+ rails (3.2.0)
54
+ actionmailer (= 3.2.0)
55
+ actionpack (= 3.2.0)
56
+ activerecord (= 3.2.0)
57
+ activeresource (= 3.2.0)
58
+ activesupport (= 3.2.0)
59
+ bundler (~> 1.0)
60
+ railties (= 3.2.0)
61
+ railties (3.2.0)
62
+ actionpack (= 3.2.0)
63
+ activesupport (= 3.2.0)
64
+ rack-ssl (~> 1.3.2)
65
+ rake (>= 0.8.7)
66
+ rdoc (~> 3.4)
67
+ thor (~> 0.14.6)
68
+ rake (10.0.4)
69
+ rdoc (3.12)
70
+ json (~> 1.4)
71
+ rspec-core (2.13.1)
72
+ rspec-expectations (2.13.0)
73
+ diff-lcs (>= 1.1.3, < 2.0)
74
+ rspec-mocks (2.13.1)
75
+ rspec-rails (2.13.1)
76
+ actionpack (>= 3.0)
77
+ activesupport (>= 3.0)
78
+ railties (>= 3.0)
79
+ rspec-core (~> 2.13.0)
80
+ rspec-expectations (~> 2.13.0)
81
+ rspec-mocks (~> 2.13.0)
82
+ sprockets (2.1.3)
83
+ hike (~> 1.2)
84
+ rack (~> 1.0)
85
+ tilt (~> 1.1, != 1.3.0)
86
+ thor (0.14.6)
87
+ tilt (1.3.6)
88
+ treetop (1.4.12)
89
+ polyglot
90
+ polyglot (>= 0.3.1)
91
+ tzinfo (0.3.37)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ rails (~> 3.2)
98
+ rspec-rails
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 4.0.0.beta1'
4
+ gem 'coffee-rails', '~> 4.0.0.beta1'
5
+ gem 'sass-rails', '~> 4.0.0.beta1'
6
+ gem 'turbolinks'
7
+ gem 'rspec-rails'
@@ -0,0 +1,114 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (4.0.0.rc1)
5
+ actionpack (= 4.0.0.rc1)
6
+ mail (~> 2.5.3)
7
+ actionpack (4.0.0.rc1)
8
+ activesupport (= 4.0.0.rc1)
9
+ builder (~> 3.1.0)
10
+ erubis (~> 2.7.0)
11
+ rack (~> 1.5.2)
12
+ rack-test (~> 0.6.2)
13
+ activemodel (4.0.0.rc1)
14
+ activesupport (= 4.0.0.rc1)
15
+ builder (~> 3.1.0)
16
+ activerecord (4.0.0.rc1)
17
+ activemodel (= 4.0.0.rc1)
18
+ activerecord-deprecated_finders (~> 1.0.2)
19
+ activesupport (= 4.0.0.rc1)
20
+ arel (~> 4.0.0)
21
+ activerecord-deprecated_finders (1.0.2)
22
+ activesupport (4.0.0.rc1)
23
+ i18n (~> 0.6, >= 0.6.4)
24
+ minitest (~> 4.2)
25
+ multi_json (~> 1.3)
26
+ thread_safe (~> 0.1)
27
+ tzinfo (~> 0.3.37)
28
+ arel (4.0.0)
29
+ atomic (1.1.8)
30
+ builder (3.1.4)
31
+ coffee-rails (4.0.0)
32
+ coffee-script (>= 2.2.0)
33
+ railties (>= 4.0.0.beta, < 5.0)
34
+ coffee-script (2.2.0)
35
+ coffee-script-source
36
+ execjs
37
+ coffee-script-source (1.6.2)
38
+ diff-lcs (1.2.4)
39
+ erubis (2.7.0)
40
+ execjs (1.4.0)
41
+ multi_json (~> 1.0)
42
+ hike (1.2.2)
43
+ i18n (0.6.4)
44
+ mail (2.5.3)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.23)
49
+ minitest (4.7.4)
50
+ multi_json (1.7.2)
51
+ polyglot (0.3.3)
52
+ rack (1.5.2)
53
+ rack-test (0.6.2)
54
+ rack (>= 1.0)
55
+ rails (4.0.0.rc1)
56
+ actionmailer (= 4.0.0.rc1)
57
+ actionpack (= 4.0.0.rc1)
58
+ activerecord (= 4.0.0.rc1)
59
+ activesupport (= 4.0.0.rc1)
60
+ bundler (>= 1.3.0, < 2.0)
61
+ railties (= 4.0.0.rc1)
62
+ sprockets-rails (~> 2.0.0.rc4)
63
+ railties (4.0.0.rc1)
64
+ actionpack (= 4.0.0.rc1)
65
+ activesupport (= 4.0.0.rc1)
66
+ rake (>= 0.8.7)
67
+ thor (>= 0.18.1, < 2.0)
68
+ rake (10.0.4)
69
+ rspec-core (2.13.1)
70
+ rspec-expectations (2.13.0)
71
+ diff-lcs (>= 1.1.3, < 2.0)
72
+ rspec-mocks (2.13.1)
73
+ rspec-rails (2.13.1)
74
+ actionpack (>= 3.0)
75
+ activesupport (>= 3.0)
76
+ railties (>= 3.0)
77
+ rspec-core (~> 2.13.0)
78
+ rspec-expectations (~> 2.13.0)
79
+ rspec-mocks (~> 2.13.0)
80
+ sass (3.2.8)
81
+ sass-rails (4.0.0.rc1)
82
+ railties (>= 4.0.0.beta, < 5.0)
83
+ sass (>= 3.1.10)
84
+ sprockets-rails (~> 2.0.0.rc0)
85
+ tilt (~> 1.3)
86
+ sprockets (2.9.3)
87
+ hike (~> 1.2)
88
+ multi_json (~> 1.0)
89
+ rack (~> 1.0)
90
+ tilt (~> 1.1, != 1.3.0)
91
+ sprockets-rails (2.0.0.rc4)
92
+ actionpack (>= 3.0)
93
+ activesupport (>= 3.0)
94
+ sprockets (~> 2.8)
95
+ thor (0.18.1)
96
+ thread_safe (0.1.0)
97
+ atomic
98
+ tilt (1.4.0)
99
+ treetop (1.4.12)
100
+ polyglot
101
+ polyglot (>= 0.3.1)
102
+ turbolinks (1.1.1)
103
+ coffee-rails
104
+ tzinfo (0.3.37)
105
+
106
+ PLATFORMS
107
+ ruby
108
+
109
+ DEPENDENCIES
110
+ coffee-rails (~> 4.0.0.beta1)
111
+ rails (~> 4.0.0.beta1)
112
+ rspec-rails
113
+ sass-rails (~> 4.0.0.beta1)
114
+ turbolinks
@@ -0,0 +1,33 @@
1
+ require 'erb'
2
+
3
+ module Testbeds
4
+ class Bed
5
+ attr_reader :gemfile, :dependencies, :rakefile, :store_in
6
+
7
+ def namespace
8
+ "testbed:#{name}"
9
+ end
10
+
11
+ def template str
12
+ ERB.new(str).result(binding)
13
+ end
14
+
15
+ def name
16
+ @name ||= Pathname.new File.basename(gemfile)
17
+ end
18
+
19
+ def run_init_script
20
+ instance_eval &@init_script if @init_script
21
+ end
22
+
23
+ def initialize gemfile, dependencies, rakefile, init_script, store_in
24
+ @store_in = Pathname.new File.expand_path(store_in)
25
+ @gemfile = File.expand_path gemfile
26
+ @rakefile = @store_in.join template(rakefile)
27
+ @init_script = init_script
28
+ @dependencies = dependencies.collect do |dep|
29
+ @store_in.join template(dep)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ module Testbeds
2
+ class Index
3
+ class Testbed
4
+ def initialize store_in, &block
5
+ @gemfiles = []
6
+ @dependencies = []
7
+ @rakefile = "Rakefile"
8
+ @init_script = nil
9
+ @store_in = store_in
10
+ instance_eval &block
11
+ end
12
+
13
+ def gemfiles *gemfiles
14
+ @gemfiles.concat gemfiles.flatten
15
+ end
16
+
17
+ def init &block
18
+ @init_script = block
19
+ end
20
+
21
+ def rakefile template
22
+ @rakefile = template
23
+ end
24
+
25
+ def depend_on *deps
26
+ @dependencies.concat deps.flatten
27
+ end
28
+
29
+ def flatten
30
+ gemfiles.collect do |gemfile|
31
+ Testbeds::Bed.new gemfile, @dependencies, @rakefile, @init_script, @store_in
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ module Testbeds
2
+ class Index
3
+ attr_reader :beds
4
+
5
+ def find_index_file base_path = Pathname.new('.')
6
+ path = File.expand_path(base_path.join('Bedfile'))
7
+ return path if File.file?(path)
8
+ # if we hit root, there is no Bedfile
9
+ return nil if path =~ /:\\Bedfile/ or path =~ /^\/Bedfile/
10
+ find_index_file base_path.join('..')
11
+ end
12
+
13
+ def initialize
14
+ @store_in = "testbeds"
15
+ @beds = []
16
+ raise "no Bedfile found" unless file = find_index_file
17
+ src = File.read file
18
+ eval src, binding, file
19
+ end
20
+
21
+ def testbeds &block
22
+ @beds.concat Testbeds::Index::Testbed.new(@store_in, &block).flatten
23
+ end
24
+
25
+ alias_method :testbed, :testbeds
26
+
27
+ def store_in dest
28
+ @store_in = dest
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Testbeds
2
+ module Rake
3
+ module DSL
4
+ def each_testbed
5
+ if current = Testbeds.current
6
+ namespace 'testbed:current' do
7
+ yield current
8
+ end
9
+ end
10
+
11
+ Testbeds.each do |testbed|
12
+ namespace testbed.namespace do
13
+ yield testbed
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'testbeds'
2
+ require "testbeds/rake/dsl"
3
+ extend Testbeds::Rake::DSL
4
+ if testbed = Testbeds.current
5
+ namespace "testbed:current" do
6
+ load testbed.rakefile if File.file?(testbed.rakefile)
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Testbeds
2
+ VERSION = "0.0.1"
3
+ end
data/lib/testbeds.rb ADDED
@@ -0,0 +1,32 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'pathname'
4
+
5
+ require "testbeds/version"
6
+ require "testbeds/index"
7
+ require "testbeds/bed"
8
+ require "testbeds/index/testbed"
9
+
10
+ module Testbeds
11
+ module_function
12
+
13
+ def all
14
+ @testbeds ||= Testbeds::Index.new.beds
15
+ end
16
+
17
+ def each &block
18
+ all.each &block
19
+ end
20
+
21
+ def current
22
+ if current_gemfile = ENV['BUNDLE_GEMFILE']
23
+ all.each do |testbed|
24
+ if testbed.gemfile == File.expand_path(current_gemfile)
25
+ return testbed
26
+ end
27
+ end
28
+ end
29
+
30
+ nil
31
+ end
32
+ end
data/spec/test_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ # Dummy file to trick RSpec into actually running (and reporting 0 specs).
2
+ #
3
+ # I'm not clear on the best way to test this gem. For now, here is my
4
+ # process (and beware, it's not automated!):
5
+ #
6
+ # 1. Regenerate testbeds with `bin/generate-testbeds`.
7
+ #
8
+ # 2. Examine directory structure, particularly that `spec/testbeds`
9
+ # is created and that it contains one subdirectory for each gemfile.
10
+ #
11
+ # 3. Run `rake -T` and ensure that RSpec tests appear for each testbed.
12
+ #
13
+ # 4. Run `rake rspec` and ensure that RSpec runs twice. Examine the output
14
+ # to ensure that each execution of RSpec includes a different
15
+ # bootstrap to config/application.rb -- one for each testbed.
16
+ #
17
+ # I know that testing this way is a horrible, horrible idea, but I've come up
18
+ # short in thinking of better ways to do this. I'm accepting pull requests.
19
+ #
data/testbeds.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'testbeds/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "testbeds"
8
+ gem.version = Testbeds::VERSION
9
+ gem.authors = ["Colin MacKenzie IV"]
10
+ gem.email = ["sinisterchipmunk@gmail.com"]
11
+ gem.description = "Manage multiple testbed environments for your gems"
12
+ gem.summary = "Manage multiple testbed environments for your gems"
13
+ gem.homepage = "http://github.com/sinisterchipmunk/testbeds"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: testbeds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Colin MacKenzie IV
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Manage multiple testbed environments for your gems
15
+ email:
16
+ - sinisterchipmunk@gmail.com
17
+ executables:
18
+ - generate-testbeds
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .travis.yml
24
+ - Bedfile
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/generate-testbeds
30
+ - gemfiles/rails-3.2
31
+ - gemfiles/rails-3.2.lock
32
+ - gemfiles/rails-4.0
33
+ - gemfiles/rails-4.0.lock
34
+ - lib/testbeds.rb
35
+ - lib/testbeds/bed.rb
36
+ - lib/testbeds/index.rb
37
+ - lib/testbeds/index/testbed.rb
38
+ - lib/testbeds/rake.rb
39
+ - lib/testbeds/rake/dsl.rb
40
+ - lib/testbeds/version.rb
41
+ - spec/test_spec.rb
42
+ - testbeds.gemspec
43
+ homepage: http://github.com/sinisterchipmunk/testbeds
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.24
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Manage multiple testbed environments for your gems
67
+ test_files:
68
+ - spec/test_spec.rb