@@ -2,8 +2,13 @@ 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
@@ -24,9 +29,9 @@ def matches?(root)
24
29
25
30
check_contents ( root . join ( @name ) )
26
31
end
27
-
32
+
28
33
protected
29
-
34
+
30
35
def check_contents ( file )
31
36
contents = ::File . read ( file )
32
37
@@ -37,20 +42,24 @@ def check_contents(file)
37
42
end
38
43
end
39
44
end
40
-
45
+
41
46
class Migration < File
47
+ def description
48
+ 'valid migration file'
49
+ end
50
+
42
51
def matches? ( root )
43
52
file_name = migration_file_name ( root , @name )
44
-
53
+
45
54
unless file_name && file_name . exist?
46
55
throw :failure , @name
47
56
end
48
-
57
+
49
58
check_contents ( file_name )
50
59
end
51
-
60
+
52
61
protected
53
-
62
+
54
63
def migration_file_name ( root , name ) #:nodoc:
55
64
directory , file_name = ::File . dirname ( root . join ( name ) ) , ::File . basename ( name ) . sub ( /\. rb$/ , '' )
56
65
migration = Dir . glob ( "#{ directory } /[0-9]*_*.rb" ) . grep ( /\d +_#{ file_name } .rb$/ ) . first
@@ -61,6 +70,10 @@ def migration_file_name(root, name) #:nodoc:
61
70
class Directory
62
71
attr_reader :tree
63
72
73
+ def description
74
+ 'has directory structure'
75
+ end
76
+
64
77
def initialize ( root = nil , &block )
65
78
@tree = { }
66
79
@negative_tree = [ ]
@@ -83,7 +96,7 @@ def no_file(name)
83
96
def location ( name )
84
97
[ @root , name ] . compact . join ( "/" )
85
98
end
86
-
99
+
87
100
def migration ( name , &block )
88
101
@tree [ name ] = Migration . new ( location ( name ) , &block )
89
102
end
@@ -110,6 +123,10 @@ def matches?(root)
110
123
end
111
124
112
125
class Root < Directory
126
+ def description
127
+ 'have specified directory structure'
128
+ end
129
+
113
130
def failure_message
114
131
if @failure . is_a? ( Array ) && @failure [ 0 ] == :not
115
132
"Structure should not have had #{ @failure [ 1 ] } , but it did"
@@ -136,4 +153,4 @@ def have_structure(&block)
136
153
Root . new ( &block )
137
154
end
138
155
end
139
- end
156
+ end
0 commit comments