generator-spec 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.5
@@ -0,0 +1,134 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{generator-spec}
8
+ s.version = "0.4.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = %q{2010-08-10}
13
+ s.description = %q{RSpec 2 library to assist in writing generator specs}
14
+ s.email = %q{kmandrup@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "generator-spec.gemspec",
28
+ "lib/generator_spec.rb",
29
+ "lib/generator_spec/extensions/core_ext.rb",
30
+ "lib/generator_spec/helpers/configure_rails.rb",
31
+ "lib/generator_spec/helpers/generator_helper.rb",
32
+ "lib/generator_spec/helpers/migration_helper.rb",
33
+ "lib/generator_spec/main.rb",
34
+ "lib/generator_spec/matchers/content/content_matcher.rb",
35
+ "lib/generator_spec/matchers/content/have_block.rb",
36
+ "lib/generator_spec/matchers/content/have_call.rb",
37
+ "lib/generator_spec/matchers/content/have_calls.rb",
38
+ "lib/generator_spec/matchers/content/have_class.rb",
39
+ "lib/generator_spec/matchers/content/have_method.rb",
40
+ "lib/generator_spec/matchers/content/have_module.rb",
41
+ "lib/generator_spec/matchers/content/have_region.rb",
42
+ "lib/generator_spec/matchers/content/have_subclass.rb",
43
+ "lib/generator_spec/matchers/content/include_module.rb",
44
+ "lib/generator_spec/matchers/content/inherit_from.rb",
45
+ "lib/generator_spec/matchers/file/generate_directory.rb",
46
+ "lib/generator_spec/matchers/file/generate_file.rb",
47
+ "lib/generator_spec/matchers/file/generate_migration.rb",
48
+ "lib/generator_spec/matchers/helpers/content.rb",
49
+ "lib/generator_spec/matchers/helpers/file.rb",
50
+ "lib/generator_spec/matchers/helpers/migration.rb",
51
+ "lib/generator_spec/matchers/migration/have_column.rb",
52
+ "lib/generator_spec/matchers/migration/have_index.rb",
53
+ "lib/generator_spec/matchers/migration/have_table.rb",
54
+ "lib/generator_spec/matchers/migration/have_tbl_column.rb",
55
+ "lib/generator_spec/matchers/migration/have_up_down.rb",
56
+ "lib/generator_spec/rails_helpers/rails_app.rb",
57
+ "lib/generator_spec/rails_helpers/rails_controller.rb",
58
+ "lib/generator_spec/rails_helpers/rails_helper.rb",
59
+ "lib/generator_spec/rails_helpers/rails_mailer.rb",
60
+ "lib/generator_spec/rails_helpers/rails_migration.rb",
61
+ "lib/generator_spec/rails_helpers/rails_model.rb",
62
+ "lib/generator_spec/rails_helpers/rails_observer.rb",
63
+ "lib/generator_spec/rails_helpers/rails_orm.rb",
64
+ "lib/generator_spec/rails_helpers/rails_view.rb",
65
+ "lib/generator_spec/require_generator.rb",
66
+ "lib/generator_spec/rspec_generator/configure.rb",
67
+ "lib/generator_spec/rspec_generator/generator_util.rb",
68
+ "lib/generator_spec/rspec_generator/routes.rb",
69
+ "lib/generator_spec/rspec_generator/test_case.rb",
70
+ "lib/generators/controller/controller_generator.rb",
71
+ "lib/generators/helper/helper_generator.rb",
72
+ "lib/generators/migration/migration_generator.rb",
73
+ "lib/generators/migration/templates/create_users.erb",
74
+ "lib/generators/model/model_generator.rb",
75
+ "lib/generators/observer/observer_generator.rb",
76
+ "lib/generators/view/view_generator.rb",
77
+ "rspec_for_generators.gemspec",
78
+ "spec/generator_spec/controller_generator_spec.rb",
79
+ "spec/generator_spec/helper_generator_spec.rb",
80
+ "spec/generator_spec/migration_generator_spec.rb",
81
+ "spec/generator_spec/model_generator_spec.rb",
82
+ "spec/generator_spec/observer_generator_spec.rb",
83
+ "spec/generator_spec/view_generator_spec.rb",
84
+ "spec/spec_helper.rb",
85
+ "wiki/Custom Rails 3 Generators.textile",
86
+ "wiki/content_matchers.textile",
87
+ "wiki/file_matchers.textile",
88
+ "wiki/migration_matchers.textile",
89
+ "wiki/rails_helpers.textile"
90
+ ]
91
+ s.homepage = %q{http://github.com/kristianmandrup/rspec_for_generators}
92
+ s.rdoc_options = ["--charset=UTF-8"]
93
+ s.require_paths = ["lib"]
94
+ s.rubygems_version = %q{1.3.7}
95
+ s.summary = %q{RSpec 2 library for writing generator specs}
96
+ s.test_files = [
97
+ "spec/generator_spec/controller_generator_spec.rb",
98
+ "spec/generator_spec/helper_generator_spec.rb",
99
+ "spec/generator_spec/migration_generator_spec.rb",
100
+ "spec/generator_spec/model_generator_spec.rb",
101
+ "spec/generator_spec/observer_generator_spec.rb",
102
+ "spec/generator_spec/view_generator_spec.rb",
103
+ "spec/spec_helper.rb"
104
+ ]
105
+
106
+ if s.respond_to? :specification_version then
107
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
108
+ s.specification_version = 3
109
+
110
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
111
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta19"])
112
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
113
+ s.add_runtime_dependency(%q<rake>, [">= 0.8.7"])
114
+ s.add_runtime_dependency(%q<rails>, [">= 3.0.0.rc"])
115
+ s.add_runtime_dependency(%q<test-unit>, [">= 2.0.9"])
116
+ s.add_runtime_dependency(%q<require_all>, [">= 1.1.0"])
117
+ else
118
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta19"])
119
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
120
+ s.add_dependency(%q<rake>, [">= 0.8.7"])
121
+ s.add_dependency(%q<rails>, [">= 3.0.0.rc"])
122
+ s.add_dependency(%q<test-unit>, [">= 2.0.9"])
123
+ s.add_dependency(%q<require_all>, [">= 1.1.0"])
124
+ end
125
+ else
126
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta19"])
127
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
128
+ s.add_dependency(%q<rake>, [">= 0.8.7"])
129
+ s.add_dependency(%q<rails>, [">= 3.0.0.rc"])
130
+ s.add_dependency(%q<test-unit>, [">= 2.0.9"])
131
+ s.add_dependency(%q<require_all>, [">= 1.1.0"])
132
+ end
133
+ end
134
+
@@ -27,5 +27,28 @@ end
27
27
  class TestApp < Rails::Application
28
28
  end
29
29
 
30
- Rails.application = TestApp
30
+ Rails.application = TestApp
31
+
32
+ # !!!!!!!!!!!!!!!!!!!!!!
33
+ module Rails
34
+ def self.logger
35
+ logger_type = RSpec::Generator.logger
36
+ case logger_type
37
+ when Hash
38
+ file = logger_type[:file]
39
+ when :stdout
40
+ return Logger.new(STDOUT)
41
+ when :file
42
+ file = File.expand_path "#{Rails.application.config.root_dir}/../rails_generator.log"
43
+ else
44
+ return Logger.new(STDOUT)
45
+ end
46
+ if file != @logger_file
47
+ @logger_file = file
48
+ @logger = Logger.new(file) if file
49
+ else
50
+ @logger ||= Logger.new(file) if file
51
+ end
52
+ end
53
+ end
31
54
 
@@ -0,0 +1,11 @@
1
+ module Rails::Generators
2
+ module BasicHelper
3
+ def info msg
4
+ if self.class != @info_class
5
+ @info_class = self.class
6
+ Rails.logger.info "[#{@info_class}]"
7
+ end
8
+ Rails.logger.info "#{msg}" if RSpec::Generator.debug?
9
+ end
10
+ end
11
+ end
@@ -1,43 +1,64 @@
1
- module Rails
2
- module Generators
3
- module MigrationHelper
4
- include Rails::Generators::Migration
5
-
6
- module ClassMethods
7
- def migration_lookup_at(dirname) #:nodoc:
8
- Dir.glob("#{dirname}/[0-9]*_*.rb")
9
- end
10
-
11
- def migration_exists?(dirname, file_name) #:nodoc:
12
- migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
13
- end
14
-
15
- def current_migration_number(dirname) #:nodoc:
16
- migration_lookup_at(dirname).collect do |file|
17
- File.basename(file).split("_").first.to_i
18
- end.max.to_i
19
- end
20
-
21
- def next_migration_number(dirname) #:nodoc:
22
- orm = Rails.configuration.generators.options[:rails][:orm]
23
- require "rails/generators/#{orm}"
24
- "#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname)
25
- rescue
26
- raise NotImplementedError
27
- end
28
- end
29
-
30
- def self.included(base) #:nodoc:
31
- base.extend ClassMethods
1
+ module Rails::Generators
2
+ module MigrationHelper
3
+ include Rails::Generators::Migration
4
+ include Rails::Generators::BasicHelper
5
+
6
+ module ClassMethods
7
+ def migration_lookup_at(dirname) #:nodoc:
8
+ Dir.glob("#{dirname}/[0-9]*_*.rb")
32
9
  end
33
10
 
34
- def info msg
35
- Rails.logger.info msg
11
+ def migration_exists?(dirname, file_name) #:nodoc:
12
+ migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
13
+ end
14
+ alias_method :first_migration_file, :migration_exists?
15
+
16
+ def latest_migration_file(dirname, file_name) #:nodoc:
17
+ migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).sort.last
18
+ end
19
+
20
+
21
+ def current_migration_number(dirname) #:nodoc:
22
+ migration_lookup_at(dirname).collect do |file|
23
+ File.basename(file).split("_").first.to_i
24
+ end.max.to_i
36
25
  end
37
-
38
- def migration(options)
39
- migration_template "create_users.erb", "db/migrations/#{name}"
26
+
27
+ def next_migration_number(dirname) #:nodoc:
28
+ orm = Rails.configuration.generators.options[:rails][:orm]
29
+ require "rails/generators/#{orm}"
30
+ "#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname)
31
+ rescue
32
+ raise NotImplementedError
40
33
  end
34
+ end
35
+
36
+ def self.included(base) #:nodoc:
37
+ base.extend ClassMethods
38
+ end
39
+
40
+ def reverse_migration! migration_path
41
+ reverse_migration_path = migration_path.gsub /^add_/, 'remove_'
42
+ reverse_migration_path = migration_path.gsub /^create_/, 'drop_'
43
+ FileUtils.mv(migration_path, reverse_migration_path) if migration_path != reverse_migration_path
44
+
45
+ file = File.new(reverse_migration_path)
46
+ # Change class name
47
+ gsub_file reverse_migration_path, /class Add/, 'class Remove'
48
+ gsub_file reverse_migration_path, /class Create/, 'class Drop'
49
+
50
+ # swap up and down methods
51
+ gsub_file reverse_migration_path, /up/, 'dwn'
52
+ gsub_file reverse_migration_path, /down/, 'up'
53
+ gsub_file reverse_migration_path, /dwn/, 'down'
54
+ end
55
+
56
+ def latest_migration_file
57
+ self.class.latest_migration_file
58
+ end
59
+
60
+ def migration(options)
61
+ migration_template "create_users.erb", "db/migrations/#{name}"
41
62
  end
42
63
  end
43
- end
64
+ end
@@ -3,6 +3,12 @@ module RSpec
3
3
  end
4
4
  end
5
5
 
6
+ module Rails
7
+ module Generators
8
+ end
9
+ end
10
+
11
+
6
12
  module RSpec
7
13
  module RubyContentMatchers
8
14
  end
@@ -28,6 +28,18 @@ module RSpec::Generator
28
28
  RSpec::Generator::Require.lib = path
29
29
  end
30
30
 
31
+ def logger= type
32
+ case type
33
+ when Symbol
34
+ raise ArgumentError, "Unknown logger type #{type}" if ![:stdout, :file].include?(type)
35
+ RSpec::Generator.logger = type
36
+ when Hash
37
+ RSpec::Generator.logger = type
38
+ else
39
+ raise ArgumentError, "Unknown logger type #{type.inspect}, must be set as Symbol :stdout, :file or Hash (for advanced configuration)"
40
+ end
41
+ end
42
+
31
43
  protected
32
44
 
33
45
  def configure_root_dir path, options = {}
@@ -5,17 +5,21 @@ require 'generator_spec/rspec_generator/configure'
5
5
 
6
6
  module RSpec::Generator
7
7
  class << self
8
- attr_accessor :generator, :test_method_name, :remove_temp_dir, :debug
8
+ attr_accessor :generator, :test_method_name, :remove_temp_dir, :debug, :logger
9
9
 
10
10
  def debug?
11
11
  debug
12
12
  end
13
13
 
14
+ def info msg
15
+ Rails.logger.info(msg) if RSpec::Generator.debug?
16
+ end
17
+
14
18
  def remove_rails_dir!
15
19
  FileUtils.rm_rf ::TmpRails.root
16
20
  end
17
21
 
18
- def run_generator *args, &block
22
+ def run_generator *args, &block
19
23
  generator.run_generator *args
20
24
  if block
21
25
  block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self)
@@ -27,6 +31,8 @@ module RSpec::Generator
27
31
  end
28
32
 
29
33
  def setup_generator test_method_name=nil, &block
34
+ info "-----------------------------------------------------"
35
+ info "#{Time.now} -- setup generator: [#{test_method_name}]"
30
36
  clean! if test_method_name
31
37
  generator = get_generator(test_method_name).extend(RSpec::Generator::Helpers)
32
38
  if block
@@ -1,11 +1,14 @@
1
1
  class HelperGenerator < Rails::Generators::NamedBase
2
+ include Rails::Generators::BasicHelper
3
+
2
4
  desc "Adds method 'help_me' to a Helper"
3
5
 
4
6
  def self.source_root
5
7
  @source_root ||= File.expand_path("../templates", __FILE__)
6
8
  end
7
9
 
8
- def add_helper_method
10
+ def add_helper_method
11
+ info "add_helper_method: #{helper_file_name}"
9
12
  if File.exist?(helper_file_name)
10
13
  inject_into_file(helper_file_name, helper_method_code, :after => after_txt) if after_txt
11
14
  else
@@ -7,7 +7,8 @@ class MigrationGenerator < Rails::Generators::NamedBase
7
7
  @source_root ||= File.expand_path("../templates", __FILE__)
8
8
  end
9
9
 
10
- def create_migration
10
+ def create_migration
11
+ info "Create migration #{name}"
11
12
  migration "#{name} name:string age:integer admin:boolean"
12
13
  end
13
14
  end
@@ -1,8 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- RSpec::Generator.configure do |config|
4
- config.debug = true
5
- end
3
+ RSpec::Generator.debug = true
6
4
 
7
5
  require_generators :all
8
6
 
data/spec/spec_helper.rb CHANGED
@@ -3,22 +3,10 @@ require 'rspec/autorun'
3
3
  require 'generator_spec'
4
4
 
5
5
  RSpec::Generator.configure do |config|
6
- config.debug = false
6
+ config.debug = true
7
7
  config.remove_temp_dir = true
8
8
  config.default_rails_root(__FILE__)
9
9
  config.lib = File.dirname(__FILE__) + '/../lib'
10
+ # config.logger = :file # :stdout
10
11
  end
11
-
12
- # module Rails
13
- # def self.logger
14
- # @logger ||= Logger.new(STDOUT)
15
- # end
16
- # end
17
-
18
- # class Railtie < ::Rails::Railtie
19
- # # config.
20
- #
21
- # initializer "logger" do |app|
22
- # app.config.logger = Logger.new(STDOUT)
23
- # end
24
- # end
12
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 4
9
- version: 0.4.4
8
+ - 5
9
+ version: 0.4.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-09 00:00:00 +02:00
17
+ date: 2010-08-10 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -128,9 +128,11 @@ files:
128
128
  - README.markdown
129
129
  - Rakefile
130
130
  - VERSION
131
+ - generator-spec.gemspec
131
132
  - lib/generator_spec.rb
132
133
  - lib/generator_spec/extensions/core_ext.rb
133
134
  - lib/generator_spec/helpers/configure_rails.rb
135
+ - lib/generator_spec/helpers/generator_helper.rb
134
136
  - lib/generator_spec/helpers/migration_helper.rb
135
137
  - lib/generator_spec/main.rb
136
138
  - lib/generator_spec/matchers/content/content_matcher.rb