generator_spec 0.9.4 → 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 +5 -5
- data/.travis.yml +2 -9
- data/Gemfile +1 -1
- data/README.md +5 -3
- data/lib/generator_spec/matcher.rb +43 -11
- data/lib/generator_spec/version.rb +1 -1
- data/spec/generator_spec/matcher_spec.rb +43 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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/.travis.yml
CHANGED
data/Gemfile
CHANGED
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
|
@@ -2,11 +2,17 @@ module GeneratorSpec
|
|
2
2
|
module Matcher
|
3
3
|
# Taken (with permission) from beard by Yahuda Katz
|
4
4
|
# https://github.com/carlhuda/beard
|
5
|
-
|
5
|
+
|
6
6
|
class File
|
7
|
+
|
8
|
+
def description
|
9
|
+
'file attributes and content'
|
10
|
+
end
|
11
|
+
|
7
12
|
def initialize(name, &block)
|
8
13
|
@contents = []
|
9
14
|
@name = name
|
15
|
+
@negative_contents = []
|
10
16
|
|
11
17
|
if block_given?
|
12
18
|
instance_eval(&block)
|
@@ -17,6 +23,10 @@ module GeneratorSpec
|
|
17
23
|
@contents << text
|
18
24
|
end
|
19
25
|
|
26
|
+
def does_not_contain(text)
|
27
|
+
@negative_contents << text
|
28
|
+
end
|
29
|
+
|
20
30
|
def matches?(root)
|
21
31
|
unless root.join(@name).exist?
|
22
32
|
throw :failure, root.join(@name)
|
@@ -24,9 +34,9 @@ module GeneratorSpec
|
|
24
34
|
|
25
35
|
check_contents(root.join(@name))
|
26
36
|
end
|
27
|
-
|
37
|
+
|
28
38
|
protected
|
29
|
-
|
39
|
+
|
30
40
|
def check_contents(file)
|
31
41
|
contents = ::File.read(file)
|
32
42
|
|
@@ -35,22 +45,32 @@ module GeneratorSpec
|
|
35
45
|
throw :failure, [file, string, contents]
|
36
46
|
end
|
37
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
|
38
54
|
end
|
39
55
|
end
|
40
|
-
|
56
|
+
|
41
57
|
class Migration < File
|
58
|
+
def description
|
59
|
+
'valid migration file'
|
60
|
+
end
|
61
|
+
|
42
62
|
def matches?(root)
|
43
63
|
file_name = migration_file_name(root, @name)
|
44
|
-
|
64
|
+
|
45
65
|
unless file_name && file_name.exist?
|
46
66
|
throw :failure, @name
|
47
67
|
end
|
48
|
-
|
68
|
+
|
49
69
|
check_contents(file_name)
|
50
70
|
end
|
51
|
-
|
71
|
+
|
52
72
|
protected
|
53
|
-
|
73
|
+
|
54
74
|
def migration_file_name(root, name) #:nodoc:
|
55
75
|
directory, file_name = ::File.dirname(root.join(name)), ::File.basename(name).sub(/\.rb$/, '')
|
56
76
|
migration = Dir.glob("#{directory}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
@@ -61,6 +81,10 @@ module GeneratorSpec
|
|
61
81
|
class Directory
|
62
82
|
attr_reader :tree
|
63
83
|
|
84
|
+
def description
|
85
|
+
'has directory structure'
|
86
|
+
end
|
87
|
+
|
64
88
|
def initialize(root = nil, &block)
|
65
89
|
@tree = {}
|
66
90
|
@negative_tree = []
|
@@ -83,7 +107,7 @@ module GeneratorSpec
|
|
83
107
|
def location(name)
|
84
108
|
[@root, name].compact.join("/")
|
85
109
|
end
|
86
|
-
|
110
|
+
|
87
111
|
def migration(name, &block)
|
88
112
|
@tree[name] = Migration.new(location(name), &block)
|
89
113
|
end
|
@@ -110,9 +134,17 @@ module GeneratorSpec
|
|
110
134
|
end
|
111
135
|
|
112
136
|
class Root < Directory
|
137
|
+
def description
|
138
|
+
'have specified directory structure'
|
139
|
+
end
|
140
|
+
|
113
141
|
def failure_message
|
114
142
|
if @failure.is_a?(Array) && @failure[0] == :not
|
115
|
-
|
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
|
116
148
|
elsif @failure.is_a?(Array)
|
117
149
|
"Structure should have #{@failure[0]} with #{@failure[1]}. It had:\n#{@failure[2]}"
|
118
150
|
else
|
@@ -136,4 +168,4 @@ module GeneratorSpec
|
|
136
168
|
Root.new(&block)
|
137
169
|
end
|
138
170
|
end
|
139
|
-
end
|
171
|
+
end
|
@@ -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
|
@@ -72,6 +72,7 @@ module GeneratorSpec
|
|
72
72
|
let(:location) { TMP_ROOT.join('test_file') }
|
73
73
|
|
74
74
|
context 'with no contains' do
|
75
|
+
|
75
76
|
it 'doesnt throw if the file exists' do
|
76
77
|
write_file(location, '')
|
77
78
|
expect {
|
@@ -84,6 +85,7 @@ module GeneratorSpec
|
|
84
85
|
file.matches?(TMP_ROOT)
|
85
86
|
}.to throw_symbol(:failure)
|
86
87
|
end
|
88
|
+
|
87
89
|
end
|
88
90
|
|
89
91
|
context 'with contains' do
|
@@ -105,6 +107,26 @@ module GeneratorSpec
|
|
105
107
|
}.to throw_symbol(:failure)
|
106
108
|
end
|
107
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
|
108
130
|
end
|
109
131
|
end
|
110
132
|
|
@@ -151,6 +173,26 @@ module GeneratorSpec
|
|
151
173
|
}.to throw_symbol(:failure)
|
152
174
|
end
|
153
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
|
154
196
|
end
|
155
197
|
end
|
156
198
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: generator_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Hodgkiss
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,7 +86,7 @@ homepage: https://github.com/stevehodgkiss/generator_spec
|
|
86
86
|
licenses:
|
87
87
|
- MIT
|
88
88
|
metadata: {}
|
89
|
-
post_install_message:
|
89
|
+
post_install_message:
|
90
90
|
rdoc_options: []
|
91
91
|
require_paths:
|
92
92
|
- lib
|
@@ -101,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
|
105
|
-
|
106
|
-
signing_key:
|
104
|
+
rubygems_version: 3.4.10
|
105
|
+
signing_key:
|
107
106
|
specification_version: 4
|
108
107
|
summary: Test Rails generators with RSpec
|
109
108
|
test_files:
|