generator_spec 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +2 -2
- data/lib/generator_spec/test_case.rb +12 -14
- data/lib/generator_spec/version.rb +1 -1
- data/spec/generator_spec/matcher_spec.rb +107 -95
- data/spec/generator_spec/test_case_spec.rb +21 -21
- data/spec/spec_helper.rb +1 -1
- metadata +7 -9
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'rspec/rails'
|
2
|
+
require 'rails/generators/test_case'
|
3
|
+
require 'generator_spec/matcher'
|
4
4
|
|
5
5
|
module GeneratorSpec
|
6
6
|
module TestCase
|
@@ -34,17 +34,15 @@ module GeneratorSpec
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
super
|
47
|
-
end
|
37
|
+
def method_missing(method_sym, *arguments, &block)
|
38
|
+
self.test_case_instance.send(method_sym, *arguments, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def respond_to?(method_sym, include_private = false)
|
42
|
+
if self.test_case_instance.respond_to?(method_sym)
|
43
|
+
true
|
44
|
+
else
|
45
|
+
super
|
48
46
|
end
|
49
47
|
end
|
50
48
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe TestGenerator,
|
3
|
+
describe TestGenerator, 'using custom matcher' do
|
4
4
|
include GeneratorSpec::TestCase
|
5
|
-
destination File.expand_path(
|
5
|
+
destination File.expand_path('../../tmp', __FILE__)
|
6
6
|
arguments %w(test --test)
|
7
7
|
|
8
8
|
before do
|
@@ -12,67 +12,79 @@ describe TestGenerator, "using custom matcher" do
|
|
12
12
|
|
13
13
|
specify do
|
14
14
|
destination_root.should have_structure {
|
15
|
-
no_file
|
16
|
-
directory
|
17
|
-
directory
|
18
|
-
file
|
19
|
-
contains
|
15
|
+
no_file 'test.rb'
|
16
|
+
directory 'config' do
|
17
|
+
directory 'initializers' do
|
18
|
+
file 'test.rb' do
|
19
|
+
contains '# Initializer'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
directory
|
24
|
-
directory
|
25
|
-
file
|
26
|
-
migration
|
27
|
-
contains
|
23
|
+
directory 'db' do
|
24
|
+
directory 'migrate' do
|
25
|
+
file '123_create_tests.rb'
|
26
|
+
migration 'create_tests' do
|
27
|
+
contains 'class TestMigration'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
}
|
32
32
|
end
|
33
|
+
|
34
|
+
it 'fails when it doesnt match' do
|
35
|
+
expect {
|
36
|
+
destination_root.should have_structure {
|
37
|
+
directory 'db' do
|
38
|
+
directory 'migrate' do
|
39
|
+
no_file '123_create_tests.rb'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
}
|
43
|
+
}.to raise_error
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
|
-
TMP_ROOT = Pathname.new(File.expand_path(
|
47
|
+
TMP_ROOT = Pathname.new(File.expand_path('../../tmp'))
|
36
48
|
|
37
49
|
module GeneratorSpec::Matcher
|
38
50
|
describe File do
|
39
|
-
describe
|
51
|
+
describe '#matches?' do
|
40
52
|
include FakeFS::SpecHelpers
|
41
53
|
|
42
54
|
before do
|
43
|
-
@file = File.new(
|
44
|
-
@location = TMP_ROOT.join(
|
55
|
+
@file = File.new('test_file')
|
56
|
+
@location = TMP_ROOT.join('test_file')
|
45
57
|
end
|
46
58
|
|
47
|
-
context
|
48
|
-
it
|
49
|
-
write_file(@location,
|
59
|
+
context 'with no contains' do
|
60
|
+
it 'doesnt throw if the file exists' do
|
61
|
+
write_file(@location, '')
|
50
62
|
expect {
|
51
63
|
@file.matches?(TMP_ROOT)
|
52
64
|
}.to_not throw_symbol
|
53
65
|
end
|
54
66
|
|
55
|
-
it
|
67
|
+
it 'throws :failure if it doesnt exist' do
|
56
68
|
expect {
|
57
69
|
@file.matches?(TMP_ROOT)
|
58
70
|
}.to throw_symbol(:failure)
|
59
71
|
end
|
60
72
|
end
|
61
73
|
|
62
|
-
context
|
74
|
+
context 'with contains' do
|
63
75
|
before do
|
64
|
-
write_file(@location,
|
76
|
+
write_file(@location, 'class CreatePosts')
|
65
77
|
end
|
66
78
|
|
67
|
-
it
|
68
|
-
@file.contains
|
79
|
+
it 'doesnt throw if the content includes the string' do
|
80
|
+
@file.contains 'CreatePosts'
|
69
81
|
expect {
|
70
82
|
@file.matches?(TMP_ROOT)
|
71
83
|
}.to_not throw_symbol
|
72
84
|
end
|
73
85
|
|
74
|
-
it
|
75
|
-
@file.contains
|
86
|
+
it 'throws :failure if the contents dont include the string' do
|
87
|
+
@file.contains 'PostsMigration'
|
76
88
|
expect {
|
77
89
|
@file.matches?(TMP_ROOT)
|
78
90
|
}.to throw_symbol(:failure)
|
@@ -84,41 +96,41 @@ module GeneratorSpec::Matcher
|
|
84
96
|
describe Migration do
|
85
97
|
include FakeFS::SpecHelpers
|
86
98
|
|
87
|
-
describe
|
99
|
+
describe '#matches?' do
|
88
100
|
before do
|
89
|
-
@migration = Migration.new(
|
90
|
-
@location = TMP_ROOT.join(
|
101
|
+
@migration = Migration.new('create_posts')
|
102
|
+
@location = TMP_ROOT.join('123456_create_posts.rb')
|
91
103
|
end
|
92
104
|
|
93
|
-
context
|
94
|
-
it
|
95
|
-
write_file(@location,
|
105
|
+
context 'with no contains' do
|
106
|
+
it 'doesnt throw if the migration exists' do
|
107
|
+
write_file(@location, 'class CreatePosts')
|
96
108
|
expect {
|
97
109
|
@migration.matches?(TMP_ROOT)
|
98
110
|
}.to_not throw_symbol
|
99
111
|
end
|
100
112
|
|
101
|
-
it
|
113
|
+
it 'throws :failure if it doesnt exist' do
|
102
114
|
expect {
|
103
115
|
@migration.matches?(TMP_ROOT)
|
104
116
|
}.to throw_symbol(:failure)
|
105
117
|
end
|
106
118
|
end
|
107
119
|
|
108
|
-
context
|
120
|
+
context 'with contains' do
|
109
121
|
before do
|
110
|
-
write_file(@location,
|
122
|
+
write_file(@location, 'class CreatePosts')
|
111
123
|
end
|
112
124
|
|
113
|
-
it
|
114
|
-
@migration.contains(
|
125
|
+
it 'doesnt throw if the migration includes the given content' do
|
126
|
+
@migration.contains('CreatePosts')
|
115
127
|
expect {
|
116
128
|
@migration.matches?(TMP_ROOT)
|
117
129
|
}.to_not throw_symbol
|
118
130
|
end
|
119
131
|
|
120
|
-
it
|
121
|
-
@migration.contains(
|
132
|
+
it 'throws failure if the migration doesnt include the given content' do
|
133
|
+
@migration.contains('CreateNotes')
|
122
134
|
expect {
|
123
135
|
@migration.matches?(TMP_ROOT)
|
124
136
|
}.to throw_symbol(:failure)
|
@@ -130,116 +142,116 @@ module GeneratorSpec::Matcher
|
|
130
142
|
describe Directory do
|
131
143
|
include FakeFS::SpecHelpers
|
132
144
|
|
133
|
-
describe
|
134
|
-
it
|
135
|
-
Directory.new(
|
145
|
+
describe '#location' do
|
146
|
+
it 'equals the full path' do
|
147
|
+
Directory.new('test').location('test_2').should eq('test/test_2')
|
136
148
|
end
|
137
149
|
end
|
138
150
|
|
139
|
-
describe
|
140
|
-
context
|
141
|
-
it
|
142
|
-
dir = Directory.new
|
143
|
-
directory
|
151
|
+
describe '#directory' do
|
152
|
+
context 'without a block' do
|
153
|
+
it 'adds a directory name to the tree' do
|
154
|
+
dir = Directory.new 'test' do
|
155
|
+
directory 'dir'
|
144
156
|
end
|
145
|
-
dir.tree[
|
157
|
+
dir.tree['dir'].should eq(false)
|
146
158
|
end
|
147
159
|
end
|
148
160
|
|
149
|
-
context
|
150
|
-
it
|
151
|
-
dir = Directory.new
|
152
|
-
directory
|
153
|
-
directory
|
161
|
+
context 'with a block' do
|
162
|
+
it 'add a directory object to the tree' do
|
163
|
+
dir = Directory.new 'test' do
|
164
|
+
directory 'dir' do
|
165
|
+
directory 'test_2'
|
154
166
|
end
|
155
167
|
end
|
156
|
-
dir.tree[
|
157
|
-
dir.tree[
|
168
|
+
dir.tree['dir'].should be_an_instance_of(Directory)
|
169
|
+
dir.tree['dir'].tree['test_2'].should eq(false)
|
158
170
|
end
|
159
171
|
end
|
160
172
|
end
|
161
173
|
|
162
|
-
describe
|
163
|
-
it
|
164
|
-
dir = Directory.new
|
165
|
-
file
|
174
|
+
describe '#file' do
|
175
|
+
it 'adds it to the tree' do
|
176
|
+
dir = Directory.new 'test' do
|
177
|
+
file 'test_file'
|
166
178
|
end
|
167
|
-
dir.tree[
|
179
|
+
dir.tree['test_file'].should be_an_instance_of(File)
|
168
180
|
end
|
169
181
|
end
|
170
182
|
|
171
|
-
describe
|
172
|
-
it
|
173
|
-
dir = Directory.new
|
174
|
-
migration
|
183
|
+
describe '#file' do
|
184
|
+
it 'adds it to the tree' do
|
185
|
+
dir = Directory.new 'test' do
|
186
|
+
migration 'test_file'
|
175
187
|
end
|
176
|
-
dir.tree[
|
177
|
-
dir.tree[
|
188
|
+
dir.tree['test_file'].should be_an_instance_of(Migration)
|
189
|
+
dir.tree['test_file'].instance_variable_get('@name').should eq('test/test_file')
|
178
190
|
end
|
179
191
|
end
|
180
192
|
|
181
|
-
describe
|
182
|
-
context
|
193
|
+
describe '#matches?' do
|
194
|
+
context 'with a directory name' do
|
183
195
|
before do
|
184
|
-
@dir = Directory.new
|
185
|
-
directory
|
196
|
+
@dir = Directory.new 'test' do
|
197
|
+
directory 'test_2'
|
186
198
|
end
|
187
199
|
end
|
188
200
|
|
189
|
-
it
|
190
|
-
write_directory(TMP_ROOT.join(
|
201
|
+
it 'doesnt throw if the directory exists' do
|
202
|
+
write_directory(TMP_ROOT.join('test/test_2'))
|
191
203
|
expect {
|
192
204
|
@dir.matches?(TMP_ROOT)
|
193
205
|
}.to_not throw_symbol
|
194
206
|
end
|
195
207
|
|
196
|
-
it
|
208
|
+
it 'throws :failure if it doesnt exist' do
|
197
209
|
expect {
|
198
210
|
@dir.matches?(TMP_ROOT)
|
199
211
|
}.to throw_symbol(:failure)
|
200
212
|
end
|
201
213
|
end
|
202
214
|
|
203
|
-
context
|
215
|
+
context 'with a directory object' do
|
204
216
|
before do
|
205
|
-
@dir = Directory.new
|
206
|
-
directory
|
207
|
-
file
|
217
|
+
@dir = Directory.new 'test' do
|
218
|
+
directory 'test_2' do
|
219
|
+
file 'test_file'
|
208
220
|
end
|
209
221
|
end
|
210
|
-
write_directory(TMP_ROOT.join(
|
222
|
+
write_directory(TMP_ROOT.join('test/test_2'))
|
211
223
|
end
|
212
224
|
|
213
|
-
it
|
214
|
-
write_file(TMP_ROOT.join(
|
225
|
+
it 'doesnt throw if the file exists' do
|
226
|
+
write_file(TMP_ROOT.join('test/test_2/test_file'), '')
|
215
227
|
expect {
|
216
228
|
@dir.matches?(TMP_ROOT)
|
217
229
|
}.to_not throw_symbol
|
218
230
|
end
|
219
231
|
|
220
|
-
it
|
232
|
+
it 'throws :failure if it doesnt exist' do
|
221
233
|
expect {
|
222
234
|
@dir.matches?(TMP_ROOT)
|
223
235
|
}.to throw_symbol(:failure)
|
224
236
|
end
|
225
237
|
end
|
226
238
|
|
227
|
-
context
|
239
|
+
context '#no_file' do
|
228
240
|
before do
|
229
|
-
@dir = Directory.new
|
230
|
-
no_file
|
241
|
+
@dir = Directory.new 'test' do
|
242
|
+
no_file 'test_file'
|
231
243
|
end
|
232
|
-
write_directory(TMP_ROOT.join(
|
244
|
+
write_directory(TMP_ROOT.join('test'))
|
233
245
|
end
|
234
246
|
|
235
|
-
it
|
247
|
+
it 'doesnt throw if the file exist' do
|
236
248
|
expect {
|
237
249
|
@dir.matches?(TMP_ROOT)
|
238
250
|
}.to_not throw_symbol
|
239
251
|
end
|
240
252
|
|
241
|
-
it
|
242
|
-
write_file(TMP_ROOT.join(
|
253
|
+
it 'throws if the file exists' do
|
254
|
+
write_file(TMP_ROOT.join('test/test_file'), '')
|
243
255
|
expect {
|
244
256
|
@dir.matches?(TMP_ROOT)
|
245
257
|
}.to throw_symbol(:failure)
|
@@ -252,19 +264,19 @@ module GeneratorSpec::Matcher
|
|
252
264
|
describe Root do
|
253
265
|
include FakeFS::SpecHelpers
|
254
266
|
|
255
|
-
describe
|
267
|
+
describe '#matches?' do
|
256
268
|
before do
|
257
|
-
@root = Root.new
|
258
|
-
directory
|
269
|
+
@root = Root.new 'test' do
|
270
|
+
directory 'test_dir'
|
259
271
|
end
|
260
272
|
end
|
261
273
|
|
262
|
-
it
|
263
|
-
write_directory(TMP_ROOT.join(
|
274
|
+
it 'returns true on no failures' do
|
275
|
+
write_directory(TMP_ROOT.join('test/test_dir'))
|
264
276
|
@root.matches?(TMP_ROOT).should be_true
|
265
277
|
end
|
266
278
|
|
267
|
-
it
|
279
|
+
it 'returns false on failures' do
|
268
280
|
@root.matches?(TMP_ROOT).should be_false
|
269
281
|
end
|
270
282
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
class TestClass
|
4
4
|
|
@@ -13,20 +13,20 @@ describe GeneratorSpec::TestCase do
|
|
13
13
|
@klass.test_case_instance = mock
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
@klass.test_case_instance.should_receive(:assert_file).with(
|
18
|
-
@klass.new.assert_file(
|
16
|
+
it 'passes unknown messages on to test_case_instance' do
|
17
|
+
@klass.test_case_instance.should_receive(:assert_file).with('test')
|
18
|
+
@klass.new.assert_file('test')
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'handles respond_to accordingly' do
|
22
22
|
@klass.test_case_instance.should_receive(:respond_to?).with(:assert_no_file).and_return(true)
|
23
23
|
@klass.new.respond_to?(:assert_no_file).should be_true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe TestGenerator,
|
27
|
+
describe TestGenerator, 'using normal assert methods' do
|
28
28
|
include GeneratorSpec::TestCase
|
29
|
-
destination File.expand_path(
|
29
|
+
destination File.expand_path('../../tmp', __FILE__)
|
30
30
|
arguments %w(test --test)
|
31
31
|
|
32
32
|
before(:all) do
|
@@ -34,37 +34,37 @@ describe TestGenerator, "using normal assert methods" do
|
|
34
34
|
run_generator
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
assert_file
|
37
|
+
it 'creates a test initializer' do
|
38
|
+
assert_file 'config/initializers/test.rb', '# Initializer'
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
assert_migration
|
41
|
+
it 'creates a migration' do
|
42
|
+
assert_migration 'db/migrate/create_tests.rb'
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
assert_no_file
|
45
|
+
it 'removes files' do
|
46
|
+
assert_no_file '.gitignore'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe TestGenerator,
|
50
|
+
describe TestGenerator, 'with contexts' do
|
51
51
|
include GeneratorSpec::TestCase
|
52
|
-
destination File.expand_path(
|
52
|
+
destination File.expand_path('../../tmp', __FILE__)
|
53
53
|
before { prepare_destination }
|
54
54
|
|
55
|
-
context
|
55
|
+
context 'with --test flag' do
|
56
56
|
before { run_generator %w(test --test) }
|
57
57
|
|
58
|
-
it
|
59
|
-
assert_file
|
58
|
+
it 'creates a test initializer' do
|
59
|
+
assert_file 'config/initializers/test.rb', '# Initializer'
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
context
|
63
|
+
context 'without any flags' do
|
64
64
|
before { run_generator %w(test) }
|
65
65
|
|
66
|
-
it
|
67
|
-
assert_no_file
|
66
|
+
it 'doesn\'t create a test initializer' do
|
67
|
+
assert_no_file 'config/initializers/test.rb'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rspec/rails'
|
|
4
4
|
require 'generator_spec/test_case'
|
5
5
|
require 'fakefs/spec_helpers'
|
6
6
|
|
7
|
-
Dir[Pathname.new(File.expand_path(
|
7
|
+
Dir[Pathname.new(File.expand_path('../', __FILE__)).join('support/**/*.rb')].each {|f| require f}
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
config.include Helpers::FileSystem
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: generator_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-01-28 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rails
|
17
|
-
requirement: &
|
16
|
+
requirement: &70134539407120 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -25,10 +24,10 @@ dependencies:
|
|
25
24
|
version: '4.0'
|
26
25
|
type: :runtime
|
27
26
|
prerelease: false
|
28
|
-
version_requirements: *
|
27
|
+
version_requirements: *70134539407120
|
29
28
|
- !ruby/object:Gem::Dependency
|
30
29
|
name: rspec-rails
|
31
|
-
requirement: &
|
30
|
+
requirement: &70134539406440 !ruby/object:Gem::Requirement
|
32
31
|
none: false
|
33
32
|
requirements:
|
34
33
|
- - ! '>='
|
@@ -36,7 +35,7 @@ dependencies:
|
|
36
35
|
version: '0'
|
37
36
|
type: :runtime
|
38
37
|
prerelease: false
|
39
|
-
version_requirements: *
|
38
|
+
version_requirements: *70134539406440
|
40
39
|
description: Test Rails generators with RSpec
|
41
40
|
email:
|
42
41
|
- steve@hodgkiss.me.uk
|
@@ -63,7 +62,6 @@ files:
|
|
63
62
|
- spec/support/test_generator/templates/initializer.rb
|
64
63
|
- spec/support/test_generator/templates/migration.rb
|
65
64
|
- spec/support/test_generator/test_generator.rb
|
66
|
-
has_rdoc: true
|
67
65
|
homepage: https://github.com/stevehodgkiss/generator_spec
|
68
66
|
licenses: []
|
69
67
|
post_install_message:
|
@@ -84,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
82
|
version: '0'
|
85
83
|
requirements: []
|
86
84
|
rubyforge_project: generator_spec
|
87
|
-
rubygems_version: 1.6
|
85
|
+
rubygems_version: 1.8.6
|
88
86
|
signing_key:
|
89
87
|
specification_version: 3
|
90
88
|
summary: Test Rails generators with RSpec
|