generator-spec 0.4.2 → 0.4.3
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/rspec_for_generators/matchers/content/include_module.rb +17 -0
- data/lib/rspec_for_generators/matchers/content/inherit_from.rb +6 -1
- data/lib/rspec_for_generators/rails_helpers/rails_model.rb +2 -2
- data/lib/rspec_for_generators/rails_helpers/rails_orm.rb +21 -19
- data/spec/rspec_for_generators/migration_generator_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
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.3"
|
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-09}
|
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 = [
|
@@ -32,4 +32,21 @@ module RSpec::RubyContentMatchers
|
|
32
32
|
def include_module(module_name)
|
33
33
|
IncludeModule.new(module_name)
|
34
34
|
end
|
35
|
+
|
36
|
+
def be_dm_resource
|
37
|
+
IncludeModule.new 'DataMapper::Resource'
|
38
|
+
end
|
39
|
+
|
40
|
+
def be_document(type, options=nil)
|
41
|
+
doc_type = options == :embedded ? 'EmbeddedDocument' : 'Document'
|
42
|
+
doc_orm = case type
|
43
|
+
when :mongo_mapper
|
44
|
+
'MongoMapper'
|
45
|
+
when :mongoid
|
46
|
+
'Mongoid'
|
47
|
+
else
|
48
|
+
raise ArgumentError, "Unknown document type #{type.inspect}"
|
49
|
+
end
|
50
|
+
IncludeModule.new "#{doc_orm}::#{doc_type}"
|
51
|
+
end
|
35
52
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module RSpec::Rails
|
2
2
|
module Model
|
3
|
-
def create_model name, &block
|
3
|
+
def create_model name, type=nil, &block
|
4
4
|
file = model_file_name(name)
|
5
5
|
unless File.exist?(file)
|
6
6
|
FileUtils.mkdir_p File.dirname(file)
|
7
7
|
File.open(file, 'w') do |f|
|
8
|
-
f.puts file_content(name)
|
8
|
+
f.puts file_content(name, type)
|
9
9
|
yield f if block_given?
|
10
10
|
end
|
11
11
|
end
|
@@ -7,10 +7,10 @@ module RSpec::Rails
|
|
7
7
|
|
8
8
|
protected
|
9
9
|
|
10
|
-
def clazz name
|
10
|
+
def clazz name
|
11
11
|
"class #{name.to_s.camelize}"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def file name
|
15
15
|
%Q{#{clazz name}
|
16
16
|
#{yield if block_given?}
|
@@ -26,9 +26,9 @@ module RSpec::Rails
|
|
26
26
|
end}
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
module ActiveRecord
|
31
|
-
include RSpec::Rails::Orm::Base
|
29
|
+
|
30
|
+
module ActiveRecord
|
31
|
+
include RSpec::Rails::Orm::Base
|
32
32
|
|
33
33
|
def file_content(name)
|
34
34
|
file_w_inherit(name) {'ActiveRecord::Base'}
|
@@ -36,12 +36,13 @@ module RSpec::Rails
|
|
36
36
|
end
|
37
37
|
|
38
38
|
module MongoMapper
|
39
|
-
|
40
|
-
|
41
|
-
def file_content name
|
42
|
-
|
39
|
+
include RSpec::Rails::Orm::Base
|
40
|
+
|
41
|
+
def file_content name, type = :document
|
42
|
+
type_content = type == :document ? 'MongoMapper::Document' : 'MongoMapper::EmbeddedDocument'
|
43
|
+
file_w_include(name) { type_content }
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def field name, type = nil
|
46
47
|
return "key :#{name}, #{type}" if type
|
47
48
|
"key :#{name}"
|
@@ -50,28 +51,29 @@ module RSpec::Rails
|
|
50
51
|
|
51
52
|
module Mongoid
|
52
53
|
include RSpec::Rails::Orm::Base
|
53
|
-
|
54
|
-
def file_content name
|
55
|
-
|
54
|
+
|
55
|
+
def file_content name, type = :document
|
56
|
+
type_content = type == :document ? 'Mongoid::Document' : 'Mongoid::EmbeddedDocument'
|
57
|
+
file_w_include(name) { type_content }
|
56
58
|
end
|
57
|
-
|
59
|
+
|
58
60
|
def field name, type = nil
|
59
61
|
return "field :#{name}, :type => #{type}" if type
|
60
62
|
"field :#{name}"
|
61
|
-
end
|
63
|
+
end
|
62
64
|
end
|
63
65
|
|
64
66
|
module DataMapper
|
65
67
|
include RSpec::Rails::Orm::Base
|
66
|
-
|
68
|
+
|
67
69
|
def file_content name
|
68
70
|
file_w_include(name) { 'DataMapper::Resource' }
|
69
71
|
end
|
70
|
-
|
72
|
+
|
71
73
|
def field name, type = nil
|
72
74
|
return "property :#{name}, #{type}" if type
|
73
75
|
"property :#{name}"
|
74
|
-
end
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
|
-
end
|
79
|
+
end
|
@@ -19,14 +19,14 @@ describe 'migration_generator' do
|
|
19
19
|
|
20
20
|
it "should generate create_user migration" do
|
21
21
|
with_generator do |g|
|
22
|
-
|
23
|
-
|
22
|
+
remove_migration :create_users
|
23
|
+
g.run_generator [:create_users].args
|
24
24
|
g.should generate_migration :create_users do |content|
|
25
25
|
content.should have_migration :create_users do |klass|
|
26
26
|
klass.should have_up do |up|
|
27
27
|
up.should have_create_table :users do |user_tbl|
|
28
28
|
user_tbl.should have_columns :name => :string, :age => :string
|
29
|
-
user_tbl.
|
29
|
+
user_tbl.should_not have_timestamps
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/spec/spec_helper.rb
CHANGED
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
|
+
- 3
|
9
|
+
version: 0.4.3
|
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-09 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|