ammeter 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/Gemfile +4 -0
- data/History.md +7 -0
- data/README.md +1 -1
- data/Rakefile +43 -11
- data/features/generator_in_a_gem.feature +82 -0
- data/features/generator_spec.feature +1 -0
- data/features/hooking_into_other_generators.feature +1 -0
- data/features/support/env.rb +20 -11
- data/features/templates/my_rails_gem/Gemfile +7 -0
- data/features/templates/my_rails_gem/Rakefile +9 -0
- data/features/templates/my_rails_gem/my_rails_gem.gemspec +20 -0
- data/features/templates/my_rails_gem/spec/spec_helper.rb +5 -0
- data/features/templates/my_railties_gem/Gemfile +7 -0
- data/features/templates/my_railties_gem/Rakefile +9 -0
- data/features/templates/my_railties_gem/my_railties_gem.gemspec +20 -0
- data/features/templates/my_railties_gem/spec/spec_helper.rb +5 -0
- data/lib/ammeter/init.rb +12 -1
- data/lib/ammeter/railtie.rb +1 -1
- data/lib/ammeter/version.rb +1 -1
- metadata +22 -4
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/History.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## Ammeter release history
|
2
2
|
|
3
|
+
### 0.2.7 / 2012-07-05
|
4
|
+
|
5
|
+
[full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.6...v0.2.7)
|
6
|
+
|
7
|
+
* Fixed issue #13 - Railtie initializer preventing devise from loading
|
8
|
+
* Fixed issue #12 - Only load_generators if we Rails is available. Regression introduced in 0.2.6
|
9
|
+
|
3
10
|
### 0.2.6 / 2012-06-28
|
4
11
|
|
5
12
|
[full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.5...v0.2.6)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Ammeter [![Build Status](https://secure.travis-ci.org/alexrothenberg/ammeter.png)](http://travis-ci.org/alexrothenberg/ammeter)
|
1
|
+
# Ammeter [![Build Status](https://secure.travis-ci.org/alexrothenberg/ammeter.png)](http://travis-ci.org/alexrothenberg/ammeter) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/alexrothenberg/ammeter)
|
2
2
|
|
3
3
|
A gem that makes it easy to write specs for your Rails 3 Generators.
|
4
4
|
|
data/Rakefile
CHANGED
@@ -18,31 +18,63 @@ end
|
|
18
18
|
|
19
19
|
Cucumber::Rake::Task.new(:cucumber)
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
task :ensure_bundler_11 do
|
22
|
+
raise 'Bundler 1.1 is a development dependency to build ammeter. Please upgrade bundler.' unless Bundler::VERSION >= '1.1'
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def create_gem(gem_name)
|
27
|
+
template_folder = "features/templates/#{gem_name}"
|
28
|
+
|
29
|
+
Dir.chdir("./tmp") do
|
30
|
+
sh "bundle gem #{gem_name}"
|
31
|
+
end
|
32
|
+
sh "cp '#{template_folder}/Gemfile' tmp/#{gem_name}"
|
33
|
+
sh "cp '#{template_folder}/#{gem_name}.gemspec' tmp/#{gem_name}"
|
34
|
+
sh "cp '#{template_folder}/Rakefile' tmp/#{gem_name}"
|
35
|
+
sh "mkdir tmp/#{gem_name}/spec"
|
36
|
+
sh "cp '#{template_folder}/spec/spec_helper.rb' tmp/#{gem_name}/spec"
|
37
|
+
Dir.chdir("./tmp/#{gem_name}") do
|
38
|
+
Bundler.clean_system 'bundle install'
|
25
39
|
end
|
26
40
|
end
|
41
|
+
|
27
42
|
namespace :generate do
|
28
43
|
desc "generate a fresh app with rspec installed"
|
29
|
-
task :app do |t|
|
30
|
-
raise 'Bundler 1.1 is a development dependency to build ammeter. Please upgrade bundler.' unless Bundler::VERSION >= '1.1'
|
31
|
-
|
44
|
+
task :app => :ensure_bundler_11 do |t|
|
32
45
|
sh "bundle exec rails new ./tmp/example_app -m 'features/templates/generate_example_app.rb' --skip-test-unit"
|
33
46
|
sh "cp 'features/templates/rspec.rake' ./tmp/example_app/lib/tasks"
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
Dir.chdir("./tmp/example_app/") do
|
48
|
+
Bundler.clean_system 'rake db:migrate'
|
49
|
+
Bundler.clean_system 'rails g rspec:install'
|
50
|
+
Bundler.clean_system 'bundle install'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "generate a fresh gem that depends on railties"
|
55
|
+
task :railties_gem => :ensure_bundler_11 do |t|
|
56
|
+
create_gem('my_railties_gem')
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "generate a fresh gem that depends on rails"
|
60
|
+
task :rails_gem => :ensure_bundler_11 do |t|
|
61
|
+
create_gem('my_rails_gem')
|
37
62
|
end
|
38
63
|
end
|
39
64
|
|
65
|
+
task :generate => [:'generate:app', :'generate:railties_gem', :'generate:rails_gem']
|
66
|
+
|
40
67
|
namespace :clobber do
|
41
68
|
desc "clobber the generated app"
|
42
69
|
task :app do
|
43
70
|
rm_rf "tmp/example_app"
|
44
71
|
end
|
72
|
+
task :gem do
|
73
|
+
rm_rf "tmp/my_railties_gem"
|
74
|
+
rm_rf "tmp/my_rails_gem"
|
75
|
+
end
|
45
76
|
end
|
77
|
+
task :clobber => [:'clobber:app', :'clobber:gem']
|
46
78
|
|
47
|
-
task :ci => [:spec, :
|
79
|
+
task :ci => [:spec, :clobber, :generate, :cucumber]
|
48
80
|
task :default => :ci
|
@@ -0,0 +1,82 @@
|
|
1
|
+
Feature: Gems can contain generators
|
2
|
+
|
3
|
+
Within a Gem Rails may often not be loaded (but railties is)
|
4
|
+
We should still be able to write a spec for these generators
|
5
|
+
|
6
|
+
@railties_gem
|
7
|
+
Scenario: A generator with "railties" dependency
|
8
|
+
Given a file named "lib/generators/awesome/awesome_generator.rb" with:
|
9
|
+
"""
|
10
|
+
class AwesomeGenerator < Rails::Generators::NamedBase
|
11
|
+
source_root File.expand_path('../templates', __FILE__)
|
12
|
+
class_option :super, :type => :boolean, :default => false
|
13
|
+
|
14
|
+
def create_awesomeness
|
15
|
+
template 'awesome.html', File.join('public', name, "#{"super_" if options[:super]}awesome.html")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
And a file named "lib/generators/awesome/templates/awesome.html" with:
|
20
|
+
"""
|
21
|
+
This is an awesome file
|
22
|
+
"""
|
23
|
+
And a file named "spec/generators/awesome_generator_spec.rb" with:
|
24
|
+
"""
|
25
|
+
require "spec_helper"
|
26
|
+
require 'generators/awesome/awesome_generator'
|
27
|
+
|
28
|
+
describe AwesomeGenerator do
|
29
|
+
before { run_generator %w(my_dir) }
|
30
|
+
describe 'public/my_dir/awesome.html' do
|
31
|
+
subject { file('public/my_dir/awesome.html') }
|
32
|
+
it { should exist }
|
33
|
+
it { should contain 'This is an awesome file' }
|
34
|
+
it { should_not contain 'This text is not in the file' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
"""
|
38
|
+
When I run `rake spec --trace`
|
39
|
+
Then the output should contain "3 examples, 0 failures"
|
40
|
+
|
41
|
+
@rails_gem
|
42
|
+
Scenario: A generator that uses "hook_for"
|
43
|
+
Given a file named "lib/generators/resourceful/resourceful_generator.rb" with:
|
44
|
+
"""
|
45
|
+
class ResourcefulGenerator < Rails::Generators::NamedBase
|
46
|
+
source_root File.expand_path('../templates', __FILE__)
|
47
|
+
class_option :super, :type => :boolean, :default => false
|
48
|
+
|
49
|
+
hook_for :orm, :in => :rails, :as => :model, :required => true
|
50
|
+
|
51
|
+
def create_resourceful_controller
|
52
|
+
template 'controller.rb', File.join('app/controllers', "#{plural_file_name}_controller.rb")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
"""
|
56
|
+
And a file named "lib/generators/resourceful/templates/controller.rb" with:
|
57
|
+
"""
|
58
|
+
class <%= class_name.pluralize %>Controller < ResourcefulController
|
59
|
+
end
|
60
|
+
"""
|
61
|
+
And a file named "spec/generators/resourceful_generator_spec.rb" with:
|
62
|
+
"""
|
63
|
+
require "spec_helper"
|
64
|
+
require 'generators/resourceful/resourceful_generator'
|
65
|
+
|
66
|
+
describe ResourcefulGenerator do
|
67
|
+
before { run_generator %w(post) }
|
68
|
+
describe 'app/controller/posts_controller.rb' do
|
69
|
+
subject { file('app/controllers/posts_controller.rb') }
|
70
|
+
it { should exist }
|
71
|
+
it { should contain 'class PostsController < ResourcefulController' }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'app/models/post.rb' do
|
75
|
+
subject { file('app/models/post.rb') }
|
76
|
+
it { should exist }
|
77
|
+
it { should contain 'class Post < ActiveRecord::Base' }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
"""
|
81
|
+
When I run `rake spec`
|
82
|
+
Then the output should contain "4 examples, 0 failures"
|
data/features/support/env.rb
CHANGED
@@ -4,32 +4,41 @@ Before do
|
|
4
4
|
@aruba_timeout_seconds = 10
|
5
5
|
end
|
6
6
|
|
7
|
-
def aruba_path(file_or_dir)
|
8
|
-
File.expand_path("../../../#{file_or_dir.sub(
|
7
|
+
def aruba_path(file_or_dir, source_foldername)
|
8
|
+
File.expand_path("../../../#{file_or_dir.sub(source_foldername,'aruba')}", __FILE__)
|
9
9
|
end
|
10
10
|
|
11
11
|
def example_app_path(file_or_dir)
|
12
12
|
File.expand_path("../../../#{file_or_dir}", __FILE__)
|
13
13
|
end
|
14
14
|
|
15
|
-
def write_symlink(file_or_dir)
|
15
|
+
def write_symlink(file_or_dir, source_foldername)
|
16
16
|
source = example_app_path(file_or_dir)
|
17
|
-
target = aruba_path(file_or_dir)
|
17
|
+
target = aruba_path(file_or_dir, source_foldername)
|
18
18
|
system "ln -s #{source} #{target}"
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
def copy_to_aruba_from(gem_or_app_name)
|
22
22
|
steps %Q{
|
23
23
|
Given a directory named "spec"
|
24
24
|
}
|
25
25
|
|
26
|
-
Dir[
|
27
|
-
if !(file_or_dir =~
|
28
|
-
write_symlink(file_or_dir)
|
26
|
+
Dir["tmp/#{gem_or_app_name}/*"].each do |file_or_dir|
|
27
|
+
if !(file_or_dir =~ /\/spec$/)
|
28
|
+
write_symlink(file_or_dir, gem_or_app_name)
|
29
29
|
end
|
30
30
|
end
|
31
|
+
write_symlink("tmp/#{gem_or_app_name}/spec/spec_helper.rb", gem_or_app_name)
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
Before '@example_app' do
|
35
|
+
copy_to_aruba_from('example_app')
|
36
|
+
end
|
37
|
+
|
38
|
+
Before '@railties_gem' do
|
39
|
+
copy_to_aruba_from('my_railties_gem')
|
40
|
+
end
|
41
|
+
|
42
|
+
Before '@rails_gem' do
|
43
|
+
copy_to_aruba_from('my_rails_gem')
|
35
44
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/my_rails_gem/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alex Rothenberg"]
|
6
|
+
gem.email = ["alex@alexrothenberg.com"]
|
7
|
+
gem.description = %q{TODO: Write a gem description}
|
8
|
+
gem.summary = %q{TODO: Write a gem summary}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "my_rails_gem"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = MyRailsGem::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'rails', '>= 3.1'
|
19
|
+
gem.add_development_dependency 'rspec-rails', '>= 2.2'
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/my_railties_gem/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alex Rothenberg"]
|
6
|
+
gem.email = ["alex@alexrothenberg.com"]
|
7
|
+
gem.description = %q{TODO: Write a gem description}
|
8
|
+
gem.summary = %q{TODO: Write a gem summary}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "my_railties_gem"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = MyRailtiesGem::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'railties', '>= 3.1'
|
19
|
+
gem.add_development_dependency 'rspec-rails', '>= 2.2'
|
20
|
+
end
|
data/lib/ammeter/init.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
require 'ammeter/rspec/generator/example.rb'
|
2
2
|
require 'ammeter/rspec/generator/matchers.rb'
|
3
3
|
|
4
|
-
Rails.application.
|
4
|
+
if Rails.application.nil?
|
5
|
+
# We are in a gem so create test Rails app
|
6
|
+
module Ammeter
|
7
|
+
module TestApp
|
8
|
+
class Application < Rails::Application
|
9
|
+
config.root = File.dirname(__FILE__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails.application.load_generators
|
data/lib/ammeter/railtie.rb
CHANGED
data/lib/ammeter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ammeter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
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: 2012-
|
12
|
+
date: 2012-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -234,10 +234,19 @@ files:
|
|
234
234
|
- README.md
|
235
235
|
- Rakefile
|
236
236
|
- ammeter.gemspec
|
237
|
+
- features/generator_in_a_gem.feature
|
237
238
|
- features/generator_spec.feature
|
238
239
|
- features/hooking_into_other_generators.feature
|
239
240
|
- features/support/env.rb
|
240
241
|
- features/templates/generate_example_app.rb
|
242
|
+
- features/templates/my_rails_gem/Gemfile
|
243
|
+
- features/templates/my_rails_gem/Rakefile
|
244
|
+
- features/templates/my_rails_gem/my_rails_gem.gemspec
|
245
|
+
- features/templates/my_rails_gem/spec/spec_helper.rb
|
246
|
+
- features/templates/my_railties_gem/Gemfile
|
247
|
+
- features/templates/my_railties_gem/Rakefile
|
248
|
+
- features/templates/my_railties_gem/my_railties_gem.gemspec
|
249
|
+
- features/templates/my_railties_gem/spec/spec_helper.rb
|
241
250
|
- features/templates/rspec.rake
|
242
251
|
- lib/.DS_Store
|
243
252
|
- lib/ammeter.rb
|
@@ -270,7 +279,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
270
279
|
version: '0'
|
271
280
|
segments:
|
272
281
|
- 0
|
273
|
-
hash:
|
282
|
+
hash: 714039448379092360
|
274
283
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
275
284
|
none: false
|
276
285
|
requirements:
|
@@ -279,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
288
|
version: '0'
|
280
289
|
segments:
|
281
290
|
- 0
|
282
|
-
hash:
|
291
|
+
hash: 714039448379092360
|
283
292
|
requirements: []
|
284
293
|
rubyforge_project:
|
285
294
|
rubygems_version: 1.8.24
|
@@ -287,10 +296,19 @@ signing_key:
|
|
287
296
|
specification_version: 3
|
288
297
|
summary: Write specs for your Rails 3+ generators
|
289
298
|
test_files:
|
299
|
+
- features/generator_in_a_gem.feature
|
290
300
|
- features/generator_spec.feature
|
291
301
|
- features/hooking_into_other_generators.feature
|
292
302
|
- features/support/env.rb
|
293
303
|
- features/templates/generate_example_app.rb
|
304
|
+
- features/templates/my_rails_gem/Gemfile
|
305
|
+
- features/templates/my_rails_gem/Rakefile
|
306
|
+
- features/templates/my_rails_gem/my_rails_gem.gemspec
|
307
|
+
- features/templates/my_rails_gem/spec/spec_helper.rb
|
308
|
+
- features/templates/my_railties_gem/Gemfile
|
309
|
+
- features/templates/my_railties_gem/Rakefile
|
310
|
+
- features/templates/my_railties_gem/my_railties_gem.gemspec
|
311
|
+
- features/templates/my_railties_gem/spec/spec_helper.rb
|
294
312
|
- features/templates/rspec.rake
|
295
313
|
- spec/ammeter/rspec/generator/example/generator_example_group_spec.rb
|
296
314
|
- spec/ammeter/rspec/generator/matchers/be_a_migration_spec.rb
|