generator-spec 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/generator-spec.gemspec +2 -2
- data/lib/generators/migration/migration_generator.rb +1 -3
- data/lib/rspec_for_generators.rb +1 -0
- data/lib/rspec_for_generators/generator_spec_helper.rb +47 -10
- data/lib/rspec_for_generators/main.rb +1 -0
- data/lib/rspec_for_generators/matchers/content/have_block.rb +1 -1
- data/lib/rspec_for_generators/matchers/content/have_calls.rb +1 -1
- data/lib/rspec_for_generators/matchers/file/generate_directory.rb +11 -9
- data/lib/rspec_for_generators/matchers/file/generate_file.rb +10 -7
- data/lib/rspec_for_generators/matchers/file/generate_migration.rb +1 -1
- data/lib/rspec_for_generators/migration_helper.rb +34 -30
- data/spec/rspec_for_generators/helper_generator_spec.rb +4 -1
- data/spec/rspec_for_generators/migration_generator_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -6
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/generator-spec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{generator-spec}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-08}
|
13
13
|
s.description = %q{RSpec 2 library to assist in writing generator specs}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/rspec_for_generators.rb
CHANGED
@@ -2,21 +2,26 @@ require 'test/unit'
|
|
2
2
|
require 'rails/all'
|
3
3
|
require 'rails/generators'
|
4
4
|
require 'rails/generators/test_case'
|
5
|
-
|
6
5
|
require 'rspec_for_generators/rails_spec_helper'
|
7
6
|
|
8
7
|
# Call configure to load the settings from
|
9
8
|
# Rails.application.config.generators to Rails::Generators
|
10
9
|
|
11
10
|
# require the generators
|
12
|
-
def require_generators *generator_list
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def require_generators *generator_list
|
12
|
+
req = RSpec::Generator::Require
|
13
|
+
generator_list.each do |name, generators|
|
14
|
+
case name
|
15
|
+
when Hash
|
16
|
+
req.parse_generator_hash name
|
17
|
+
when Symbol
|
18
|
+
if !generators || generators.empty?
|
19
|
+
req.require_generator! name
|
20
|
+
else
|
21
|
+
req.parse_generator_list name, generators
|
22
|
+
end
|
23
|
+
else
|
24
|
+
raise ArgumentError, "required generator(s) must be stated either using a symbol or array of symbols"
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -24,8 +29,40 @@ alias :require_generator :require_generators
|
|
24
29
|
|
25
30
|
module RSpec
|
26
31
|
module Generator
|
32
|
+
module Require
|
33
|
+
class << self
|
34
|
+
def parse_generator_hash hash
|
35
|
+
parse_generator_list hash.keys.first, hash.values.flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_generator_list name, generators
|
39
|
+
if generators.empty?
|
40
|
+
require_generator! name
|
41
|
+
else
|
42
|
+
generators.each do |generator_name|
|
43
|
+
require_generator! name, generator_name
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def require_generator! name, generator=nil
|
49
|
+
file = (require_file_name name, generator)
|
50
|
+
puts "Loading generator: #{file}" if RSpec::Generator.debug?
|
51
|
+
require file
|
52
|
+
end
|
53
|
+
|
54
|
+
def require_file_name name, name_space=nil
|
55
|
+
File.join('generators', name.to_s, "#{name_space}", "#{name_space || name}_generator")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
27
60
|
class << self
|
28
|
-
attr_accessor :generator, :test_method_name, :remove_temp_dir
|
61
|
+
attr_accessor :generator, :test_method_name, :remove_temp_dir, :debug
|
62
|
+
|
63
|
+
def debug?
|
64
|
+
debug
|
65
|
+
end
|
29
66
|
|
30
67
|
def remove_rails_dir!
|
31
68
|
FileUtils.rm_rf ::TmpRails.root
|
@@ -6,35 +6,37 @@
|
|
6
6
|
|
7
7
|
module RSpec::FileMatchers
|
8
8
|
class GenerateDir
|
9
|
+
attr_accessor :relative_path
|
9
10
|
|
10
11
|
def initialize(relative_path, type = nil)
|
11
|
-
@relative_path = relative_rails_dir
|
12
|
+
@relative_path = relative_rails_dir(relative_path, type)
|
12
13
|
end
|
13
14
|
|
14
15
|
def matches?(generator, &block)
|
15
|
-
|
16
|
-
|
17
|
-
if block &&
|
18
|
-
read = File.read(
|
16
|
+
file = File.expand_path(relative_path, generator.class.destination_root)
|
17
|
+
file_exists = File.exists?(expected)
|
18
|
+
if block && file_exists
|
19
|
+
read = File.read(file)
|
19
20
|
ruby_content = read.extend(RSpec::RubyContent::Helpers)
|
20
21
|
yield ruby_content
|
21
22
|
else
|
22
|
-
|
23
|
+
file_exists
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def failure_message
|
27
|
-
"Expected file #{
|
28
|
+
"Expected file #{relative_path} to have been generated, but it was not"
|
28
29
|
end
|
29
30
|
|
30
31
|
def negative_failure_message
|
31
|
-
"Did not expected file #{
|
32
|
+
"Did not expected file #{relative_path} to have been generated, but it was"
|
32
33
|
end
|
33
34
|
|
34
35
|
protected
|
35
36
|
|
36
37
|
def relative_rails_dir path, type = nil
|
37
|
-
|
38
|
+
path = path.to_s
|
39
|
+
return File.join(::Rails.root, base_dir(type), folder(type), "#{path}") if type
|
38
40
|
File.join(::Rails.root, path)
|
39
41
|
end
|
40
42
|
|
@@ -7,33 +7,36 @@
|
|
7
7
|
module RSpec::FileMatchers
|
8
8
|
class GenerateFile
|
9
9
|
|
10
|
+
attr_accessor :relative_path
|
11
|
+
|
10
12
|
def initialize(relative_path, type = nil)
|
11
13
|
@relative_path = relative_rails_file(relative_path, type)
|
12
14
|
end
|
13
15
|
|
14
16
|
def matches?(generator, &block)
|
15
|
-
|
16
|
-
|
17
|
-
if block &&
|
18
|
-
read = File.read(
|
17
|
+
file = File.expand_path(relative_path, generator.class.destination_root)
|
18
|
+
file_exists = File.exists?(file)
|
19
|
+
if block && file_exists
|
20
|
+
read = File.read(file)
|
19
21
|
ruby_content = read.extend(RSpec::RubyContent::Helpers)
|
20
22
|
yield ruby_content
|
21
23
|
else
|
22
|
-
|
24
|
+
file_exists
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
def failure_message
|
27
|
-
"Expected file #{
|
29
|
+
"Expected file #{relative_path} to have been generated, but it was not"
|
28
30
|
end
|
29
31
|
|
30
32
|
def negative_failure_message
|
31
|
-
"Did not expected file #{
|
33
|
+
"Did not expected file #{relative_path} to have been generated, but it was"
|
32
34
|
end
|
33
35
|
|
34
36
|
protected
|
35
37
|
|
36
38
|
def relative_rails_file path, type = nil
|
39
|
+
path = path.to_s
|
37
40
|
f_name = file_name(path, type)
|
38
41
|
return File.join(::Rails.root, base_dir(type), folder(type), f_name) if type
|
39
42
|
File.join(::Rails.root, path)
|
@@ -1,39 +1,43 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
module MigrationHelper
|
4
|
+
include Rails::Generators::Migration
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
module ClassMethods
|
7
|
+
def migration_lookup_at(dirname) #:nodoc:
|
8
|
+
Dir.glob("#{dirname}/[0-9]*_*.rb")
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
def migration_exists?(dirname, file_name) #:nodoc:
|
12
|
+
migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def self.included(base) #:nodoc:
|
31
|
+
base.extend ClassMethods
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def info msg
|
35
|
+
Rails.logger.info msg
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
def migration(options)
|
39
|
+
migration_template "create_users.erb", "db/migrations/#{name}"
|
40
|
+
end
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
@@ -16,9 +16,9 @@ describe 'migration_generator' do
|
|
16
16
|
|
17
17
|
it "should generate create_user migration" do
|
18
18
|
with_generator do |g|
|
19
|
-
name =
|
20
|
-
remove_migration
|
21
|
-
g.run_generator [name]
|
19
|
+
name = :create_users
|
20
|
+
remove_migration :create_users
|
21
|
+
g.run_generator [name.to_s]
|
22
22
|
g.should generate_migration name do |content|
|
23
23
|
content.should have_migration name do |klass|
|
24
24
|
klass.should have_up do |up|
|
data/spec/spec_helper.rb
CHANGED
@@ -5,12 +5,6 @@ require 'rspec_for_generators'
|
|
5
5
|
RSpec::Generator.remove_temp_dir = true
|
6
6
|
RSpec::Generator.configure_root_dir __FILE__
|
7
7
|
|
8
|
-
# RSpec::Core::ExampleGroup
|
9
|
-
|
10
|
-
# RSpec.configure do |c|
|
11
|
-
# c.extend RSpec::Generator
|
12
|
-
# end
|
13
|
-
|
14
8
|
module Rails
|
15
9
|
def self.logger
|
16
10
|
@logger ||= Logger.new(STDOUT)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
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-
|
17
|
+
date: 2010-08-08 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|