generator-spec 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.markdown +144 -0
  5. data/Rakefile +48 -0
  6. data/VERSION +1 -0
  7. data/generator-spec.gemspec +106 -0
  8. data/lib/generators/demo/demo_generator.rb +91 -0
  9. data/lib/rspec_for_generators.rb +11 -0
  10. data/lib/rspec_for_generators/fixtures/routes.rb +2 -0
  11. data/lib/rspec_for_generators/generator_spec_helper.rb +95 -0
  12. data/lib/rspec_for_generators/main.rb +18 -0
  13. data/lib/rspec_for_generators/matchers/content/have_block.rb +47 -0
  14. data/lib/rspec_for_generators/matchers/content/have_call.rb +42 -0
  15. data/lib/rspec_for_generators/matchers/content/have_class.rb +32 -0
  16. data/lib/rspec_for_generators/matchers/content/have_method.rb +41 -0
  17. data/lib/rspec_for_generators/matchers/content/have_module.rb +32 -0
  18. data/lib/rspec_for_generators/matchers/content/include_module.rb +32 -0
  19. data/lib/rspec_for_generators/matchers/content/inherit_from.rb +31 -0
  20. data/lib/rspec_for_generators/matchers/file/generate_directory.rb +71 -0
  21. data/lib/rspec_for_generators/matchers/file/generate_file.rb +71 -0
  22. data/lib/rspec_for_generators/matchers/file/generate_migration.rb +50 -0
  23. data/lib/rspec_for_generators/matchers/helpers/content.rb +18 -0
  24. data/lib/rspec_for_generators/matchers/helpers/file.rb +26 -0
  25. data/lib/rspec_for_generators/matchers/helpers/migration.rb +102 -0
  26. data/lib/rspec_for_generators/matchers/migration/have_column.rb +13 -0
  27. data/lib/rspec_for_generators/matchers/migration/have_index.rb +9 -0
  28. data/lib/rspec_for_generators/matchers/migration/have_migration.rb +5 -0
  29. data/lib/rspec_for_generators/matchers/migration/have_table.rb +18 -0
  30. data/lib/rspec_for_generators/matchers/migration/have_tbl_column.rb +25 -0
  31. data/lib/rspec_for_generators/matchers/migration/have_up_down.rb +13 -0
  32. data/lib/rspec_for_generators/rails_helpers/all.rb +6 -0
  33. data/lib/rspec_for_generators/rails_helpers/rails_app.rb +53 -0
  34. data/lib/rspec_for_generators/rails_helpers/rails_controller.rb +36 -0
  35. data/lib/rspec_for_generators/rails_helpers/rails_helper.rb +36 -0
  36. data/lib/rspec_for_generators/rails_helpers/rails_mailer.rb +29 -0
  37. data/lib/rspec_for_generators/rails_helpers/rails_model.rb +27 -0
  38. data/lib/rspec_for_generators/rails_helpers/rails_orm.rb +77 -0
  39. data/lib/rspec_for_generators/rails_helpers/rails_view.rb +29 -0
  40. data/lib/rspec_for_generators/rails_spec_helper.rb +35 -0
  41. data/lib/rspec_for_generators/rspec_test_case.rb +26 -0
  42. data/rspec_for_generators.gemspec +96 -0
  43. data/spec/rspec_for_generators/rspec_for_generators_spec.rb +41 -0
  44. data/spec/spec.opts +1 -0
  45. data/spec/spec_helper.rb +6 -0
  46. data/wiki/Custom Rails 3 Generators.textile +110 -0
  47. data/wiki/rails_view_helpers.textile +167 -0
  48. metadata +205 -0
@@ -0,0 +1,167 @@
1
+ The Rails 3 spec helpers can be used to setup the temporary Rails 3 app used for the specs.
2
+ Use the `create` methods to setup an application layout of expected files expected/required by the generator to test it.
3
+
4
+ The `remove` methods can be used to cleanup before or after a test run, f.ex using the RSpec `before(:each)` and `after(:each)` blocks.
5
+
6
+ h3. View helpers
7
+
8
+ * create_view name, content
9
+ * create_view name, &block
10
+ * remove_view name
11
+ * remove_views *names
12
+
13
+ h3. Model helpers
14
+
15
+ * create_model name, content
16
+ * create_model name, &block
17
+ * remove_model name
18
+ * remove_models *names
19
+
20
+ h3. Controller helpers
21
+
22
+ * create_controller name, content
23
+ * create_controller name, &block
24
+ * remove_controller name
25
+ * remove_controller *names
26
+
27
+ h3. Mailer helpers
28
+
29
+ * create_mailer name, content
30
+ * create_mailer name, &block
31
+ * remove_mailer name
32
+ * remove_mailers *names
33
+
34
+ h3. Helper helpers
35
+
36
+ * create_helper name, content
37
+ * create_helper name, &block
38
+ * remove_helper name
39
+ * remove_helpers *names
40
+
41
+ --
42
+
43
+ The RSpec 2 generator matchers are used to match on file content that are the result of running the generator under test.
44
+ These matchers can be used to test if the resulting file contains content/ruby code as expected (or specified).
45
+
46
+ * generate_file name, type:Symbol, &block
47
+ * generate_dir name, type:Symbol, &block
48
+ * generate_migration name, &block
49
+
50
+ * have_class name, &block
51
+ * have_module name, &block
52
+ * have_method name, &block, type:Symbol (:class)
53
+ * include_module name, &block
54
+ * inherit_from name, &block
55
+
56
+ *generate_file* can take any of the symbols below as a type argument and perform matchings on
57
+ that file in the appropriate location in the Rails 3 app.
58
+
59
+ * :model, :controller, :view, :helper, :observer, :migration
60
+ * :javascript, :stylesheet, :initializer, :locale
61
+
62
+ h3. Example use of matchers
63
+
64
+ <pre>
65
+ g.should generate_file name, :model do |content|
66
+ content.should have_class name do |klass|
67
+ klass.should include_module 'Canable::Ables'
68
+ end
69
+ end
70
+ </pre>
71
+
72
+ h2. Migration file
73
+
74
+ There are a bunch of ways to match the layout of a generated migration file as the following demonstrates.
75
+
76
+ * Matchers
77
+ * Helper methods
78
+
79
+ h3. Matchers
80
+
81
+ Example use
82
+ <pre>
83
+ g.should have_migration(:create_users) do |content|
84
+ content.should have_up do |up|
85
+ up.should create_table(:users) do |table|
86
+ table.should add_column(:name, :string)
87
+ end
88
+ end
89
+ end
90
+ </pre>
91
+
92
+ Migration file matcher
93
+
94
+ * have_migration name, &block
95
+
96
+ Up and Down method matchers
97
+
98
+ * have_up, &block
99
+ * have_down, &block
100
+
101
+ Table matchers
102
+
103
+ * have_create_table name, &block
104
+ * have_change_table name, &block
105
+ * have_drop_table name
106
+ * have_rename_table name, new_name
107
+
108
+ Column matchers
109
+
110
+ * have_remove_column name
111
+ * have_add_column name, type='string'
112
+ * have_change_column name, type='string'
113
+ * have_add_tbl_column tbl_name, name, type='string'
114
+
115
+ Table column matchers
116
+
117
+ * have_change_tbl_column tbl_name, name, type='string'
118
+ * have_rename_tbl_column tbl_name, new_name
119
+ * have_remove_tbl_column tbl_name, name
120
+
121
+ h3. Helper methods
122
+
123
+ Example use
124
+ <pre>
125
+ g.migration :create_users do |content|
126
+ file_content.up do |up|
127
+ up.creates_table :users do |table|
128
+ table.adds_column :name, :string
129
+ end
130
+ end
131
+ end
132
+ </pre>
133
+
134
+
135
+ Check named migration file exists and yields content of file
136
+ * migration file_name, &block
137
+
138
+ Checks class method 'up' exists and yields content of method
139
+ * up &block
140
+
141
+ Checks class method 'down' exists and yields content of method
142
+ * down &block
143
+
144
+ Check specific block exists and yields content of block
145
+
146
+ * creates_table name, &block
147
+ * changes_table name, &block
148
+
149
+ Test specific migration statements exist within table block
150
+
151
+ * drops_table name
152
+ * renames_table name
153
+ * removes_column name
154
+ * adds_column name, type='string'
155
+ * changes_column name, type='string'
156
+
157
+ Test that migration statements exist that apply to a specific table
158
+
159
+ * adds_tbl_column tbl_name, name, type='string'
160
+ * changes_tbl_column tbl_name, name, type='string'
161
+ * renames_tbl_column tbl_name, new_name
162
+ * removes_tbl_column tbl_name, name
163
+
164
+ Check Index statements
165
+
166
+ * adds_tbl_index tbl_name, name
167
+ * removes_tbl_index tbl_name, name
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: generator-spec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 3
9
+ version: 0.3.3
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-04 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta19
33
+ version: 2.0.0.beta19
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 2
46
+ - 0
47
+ - 0
48
+ - beta
49
+ - 19
50
+ version: 2.0.0.beta.19
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ - 8
64
+ - 7
65
+ version: 0.8.7
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: rails
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 3
78
+ - 0
79
+ - 0
80
+ - rc
81
+ version: 3.0.0.rc
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: test-unit
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 2
94
+ - 0
95
+ - 9
96
+ version: 2.0.9
97
+ type: :runtime
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: require_all
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 1
109
+ - 1
110
+ - 0
111
+ version: 1.1.0
112
+ type: :runtime
113
+ version_requirements: *id006
114
+ description: RSpec 2 library to assist in writing generator specs
115
+ email: kmandrup@gmail.com
116
+ executables: []
117
+
118
+ extensions: []
119
+
120
+ extra_rdoc_files:
121
+ - LICENSE
122
+ - README.markdown
123
+ files:
124
+ - .document
125
+ - .gitignore
126
+ - LICENSE
127
+ - README.markdown
128
+ - Rakefile
129
+ - VERSION
130
+ - generator-spec.gemspec
131
+ - lib/generators/demo/demo_generator.rb
132
+ - lib/rspec_for_generators.rb
133
+ - lib/rspec_for_generators/fixtures/routes.rb
134
+ - lib/rspec_for_generators/generator_spec_helper.rb
135
+ - lib/rspec_for_generators/main.rb
136
+ - lib/rspec_for_generators/matchers/content/have_block.rb
137
+ - lib/rspec_for_generators/matchers/content/have_call.rb
138
+ - lib/rspec_for_generators/matchers/content/have_class.rb
139
+ - lib/rspec_for_generators/matchers/content/have_method.rb
140
+ - lib/rspec_for_generators/matchers/content/have_module.rb
141
+ - lib/rspec_for_generators/matchers/content/include_module.rb
142
+ - lib/rspec_for_generators/matchers/content/inherit_from.rb
143
+ - lib/rspec_for_generators/matchers/file/generate_directory.rb
144
+ - lib/rspec_for_generators/matchers/file/generate_file.rb
145
+ - lib/rspec_for_generators/matchers/file/generate_migration.rb
146
+ - lib/rspec_for_generators/matchers/helpers/content.rb
147
+ - lib/rspec_for_generators/matchers/helpers/file.rb
148
+ - lib/rspec_for_generators/matchers/helpers/migration.rb
149
+ - lib/rspec_for_generators/matchers/migration/have_column.rb
150
+ - lib/rspec_for_generators/matchers/migration/have_index.rb
151
+ - lib/rspec_for_generators/matchers/migration/have_migration.rb
152
+ - lib/rspec_for_generators/matchers/migration/have_table.rb
153
+ - lib/rspec_for_generators/matchers/migration/have_tbl_column.rb
154
+ - lib/rspec_for_generators/matchers/migration/have_up_down.rb
155
+ - lib/rspec_for_generators/rails_helpers/all.rb
156
+ - lib/rspec_for_generators/rails_helpers/rails_app.rb
157
+ - lib/rspec_for_generators/rails_helpers/rails_controller.rb
158
+ - lib/rspec_for_generators/rails_helpers/rails_helper.rb
159
+ - lib/rspec_for_generators/rails_helpers/rails_mailer.rb
160
+ - lib/rspec_for_generators/rails_helpers/rails_model.rb
161
+ - lib/rspec_for_generators/rails_helpers/rails_orm.rb
162
+ - lib/rspec_for_generators/rails_helpers/rails_view.rb
163
+ - lib/rspec_for_generators/rails_spec_helper.rb
164
+ - lib/rspec_for_generators/rspec_test_case.rb
165
+ - rspec_for_generators.gemspec
166
+ - spec/rspec_for_generators/rspec_for_generators_spec.rb
167
+ - spec/spec.opts
168
+ - spec/spec_helper.rb
169
+ - wiki/Custom Rails 3 Generators.textile
170
+ - wiki/rails_view_helpers.textile
171
+ has_rdoc: true
172
+ homepage: http://github.com/kristianmandrup/rspec_for_generators
173
+ licenses: []
174
+
175
+ post_install_message:
176
+ rdoc_options:
177
+ - --charset=UTF-8
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ segments:
186
+ - 0
187
+ version: "0"
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ segments:
194
+ - 0
195
+ version: "0"
196
+ requirements: []
197
+
198
+ rubyforge_project:
199
+ rubygems_version: 1.3.7
200
+ signing_key:
201
+ specification_version: 3
202
+ summary: RSpec 2 library for writing generator specs
203
+ test_files:
204
+ - spec/rspec_for_generators/rspec_for_generators_spec.rb
205
+ - spec/spec_helper.rb