generator_spec 0.9.5 → 0.10.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/generator_spec/matcher.rb +16 -1
- data/lib/generator_spec/version.rb +1 -1
- data/spec/generator_spec/matcher_spec.rb +41 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceeb0b383b8f1ef8d46905ff7845c3107ca106de596def8f51d75a33a985d1fb
|
4
|
+
data.tar.gz: 7b9aef2d85862a990be2270a75294403e1579dbe55fa2766788969e73adb0769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be6fba5bbfb8e534a19ed86c516d190efe91d01e5cdead0c0a9b19c219d6690b5cb18c008ff3853291e8632495dfd03cdb142bd626f85af11e9465bb12aec8fb
|
7
|
+
data.tar.gz: 3e4f9f7a012cd795b01e8cc5fd02b7d36c10f8ce49ce1886939403452f236b91f3c67c3f02313379ad353b2bfcaba5e546777ba0927ad24fc17866416d073071
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Spec (files in `spec/lib/generators` are recognized as generator type example gr
|
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
# spec/lib/generators/test/test_generator_spec.rb
|
19
|
-
|
19
|
+
|
20
20
|
require "generator_spec"
|
21
21
|
|
22
22
|
describe TestGenerator, type: :generator do
|
@@ -33,13 +33,13 @@ describe TestGenerator, type: :generator do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
```
|
36
|
-
|
36
|
+
|
37
37
|
An RSpec file matching DSL is also provided, taken with permission from [beard](https://github.com/carlhuda/beard/blob/master/spec/support/matcher.rb) by [carlhuda](https://github.com/carlhuda).
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
describe TestGenerator, "using custom matcher", type: :generator do
|
41
41
|
destination File.expand_path("../../tmp", __FILE__)
|
42
|
-
|
42
|
+
|
43
43
|
before do
|
44
44
|
prepare_destination
|
45
45
|
run_generator
|
@@ -52,6 +52,7 @@ describe TestGenerator, "using custom matcher", type: :generator do
|
|
52
52
|
directory "initializers" do
|
53
53
|
file "test.rb" do
|
54
54
|
contains "# Initializer"
|
55
|
+
does_not_contain "Something else"
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
@@ -60,6 +61,7 @@ describe TestGenerator, "using custom matcher", type: :generator do
|
|
60
61
|
file "123_create_tests.rb"
|
61
62
|
migration "create_tests" do
|
62
63
|
contains "class TestMigration"
|
64
|
+
does_not_contain "Something else"
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
@@ -12,6 +12,7 @@ module GeneratorSpec
|
|
12
12
|
def initialize(name, &block)
|
13
13
|
@contents = []
|
14
14
|
@name = name
|
15
|
+
@negative_contents = []
|
15
16
|
|
16
17
|
if block_given?
|
17
18
|
instance_eval(&block)
|
@@ -22,6 +23,10 @@ module GeneratorSpec
|
|
22
23
|
@contents << text
|
23
24
|
end
|
24
25
|
|
26
|
+
def does_not_contain(text)
|
27
|
+
@negative_contents << text
|
28
|
+
end
|
29
|
+
|
25
30
|
def matches?(root)
|
26
31
|
unless root.join(@name).exist?
|
27
32
|
throw :failure, root.join(@name)
|
@@ -40,6 +45,12 @@ module GeneratorSpec
|
|
40
45
|
throw :failure, [file, string, contents]
|
41
46
|
end
|
42
47
|
end
|
48
|
+
|
49
|
+
@negative_contents.each do |string|
|
50
|
+
if contents.include?(string)
|
51
|
+
throw :failure, [:not, file, string, contents]
|
52
|
+
end
|
53
|
+
end
|
43
54
|
end
|
44
55
|
end
|
45
56
|
|
@@ -129,7 +140,11 @@ module GeneratorSpec
|
|
129
140
|
|
130
141
|
def failure_message
|
131
142
|
if @failure.is_a?(Array) && @failure[0] == :not
|
132
|
-
|
143
|
+
if @failure.length > 2
|
144
|
+
"Structure should have #{@failure[1]} without #{@failure[2]}. It had:\n#{@failure[3]}"
|
145
|
+
else
|
146
|
+
"Structure should not have had #{@failure[1]}, but it did"
|
147
|
+
end
|
133
148
|
elsif @failure.is_a?(Array)
|
134
149
|
"Structure should have #{@failure[0]} with #{@failure[1]}. It had:\n#{@failure[2]}"
|
135
150
|
else
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
|
-
TMP_ROOT = Pathname.new(Dir.
|
4
|
+
TMP_ROOT = Pathname.new(Dir.mktmpdir('generator_spec'))
|
5
5
|
|
6
6
|
describe TestGenerator, 'using custom matcher' do
|
7
7
|
include GeneratorSpec::TestCase
|
@@ -107,6 +107,26 @@ module GeneratorSpec
|
|
107
107
|
}.to throw_symbol(:failure)
|
108
108
|
end
|
109
109
|
end
|
110
|
+
|
111
|
+
context 'with does_not_contain' do
|
112
|
+
before do
|
113
|
+
write_file(location, 'class CreatePosts')
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'doesnt throw if the contents dont include the string' do
|
117
|
+
file.does_not_contain 'PostsMigration'
|
118
|
+
expect {
|
119
|
+
file.matches?(TMP_ROOT)
|
120
|
+
}.to_not throw_symbol
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'throws :failure if the contents include the string' do
|
124
|
+
file.does_not_contain 'CreatePosts'
|
125
|
+
expect {
|
126
|
+
file.matches?(TMP_ROOT)
|
127
|
+
}.to throw_symbol(:failure)
|
128
|
+
end
|
129
|
+
end
|
110
130
|
end
|
111
131
|
end
|
112
132
|
|
@@ -153,6 +173,26 @@ module GeneratorSpec
|
|
153
173
|
}.to throw_symbol(:failure)
|
154
174
|
end
|
155
175
|
end
|
176
|
+
|
177
|
+
context 'with does_not_contain' do
|
178
|
+
before do
|
179
|
+
write_file(location, 'class CreatePosts')
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'doesnt throw if the migration doesnt include the given content' do
|
183
|
+
migration.does_not_contain('CreateNotes')
|
184
|
+
expect {
|
185
|
+
migration.matches?(TMP_ROOT)
|
186
|
+
}.to_not throw_symbol
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'throws failure if the migration includes the given content' do
|
190
|
+
migration.does_not_contain('CreatePosts')
|
191
|
+
expect {
|
192
|
+
migration.matches?(TMP_ROOT)
|
193
|
+
}.to throw_symbol(:failure)
|
194
|
+
end
|
195
|
+
end
|
156
196
|
end
|
157
197
|
end
|
158
198
|
|