generator_spec 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -50,6 +50,9 @@ An RSpec file matching DSL is also provided, taken with permission from [beard](
50
50
  directory "db" do
51
51
  directory "migrate" do
52
52
  file "123_create_tests.rb"
53
+ migration "create_tests" do
54
+ contains "class TestMigration"
55
+ end
53
56
  end
54
57
  end
55
58
  }
@@ -23,15 +23,41 @@ module GeneratorSpec
23
23
  throw :failure, root.join(@name)
24
24
  end
25
25
 
26
- contents = ::File.read(root.join(@name))
26
+ check_contents(root.join(@name))
27
+ end
28
+
29
+ protected
30
+
31
+ def check_contents(file)
32
+ contents = ::File.read(file)
27
33
 
28
34
  @contents.each do |string|
29
35
  unless contents.include?(string)
30
- throw :failure, [root.join(@name), string, contents]
36
+ throw :failure, [file, string, contents]
31
37
  end
32
38
  end
33
39
  end
34
40
  end
41
+
42
+ class Migration < File
43
+ def matches?(root)
44
+ file_name = migration_file_name(root, @name)
45
+
46
+ unless file_name && file_name.exist?
47
+ throw :failure, file_name
48
+ end
49
+
50
+ check_contents(file_name)
51
+ end
52
+
53
+ protected
54
+
55
+ def migration_file_name(root, name) #:nodoc:
56
+ directory, file_name = ::File.dirname(root.join(name)), ::File.basename(name).sub(/\.rb$/, '')
57
+ migration = Dir.glob("#{directory}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
58
+ Pathname.new(migration) if migration
59
+ end
60
+ end
35
61
 
36
62
  class Directory
37
63
  attr_reader :tree
@@ -58,6 +84,10 @@ module GeneratorSpec
58
84
  def location(name)
59
85
  [@root, name].compact.join("/")
60
86
  end
87
+
88
+ def migration(name, &block)
89
+ @tree[name] = Migration.new(location(name), &block)
90
+ end
61
91
 
62
92
  def matches?(root)
63
93
  @tree.each do |file, value|
@@ -1,3 +1,3 @@
1
1
  module GeneratorSpec
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -23,6 +23,9 @@ describe TestGenerator, "using custom matcher" do
23
23
  directory "db" do
24
24
  directory "migrate" do
25
25
  file "123_create_tests.rb"
26
+ migration "create_tests" do
27
+ contains "class TestMigration"
28
+ end
26
29
  end
27
30
  end
28
31
  }
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generator_spec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
5
+ version: 0.0.3
11
6
  platform: ruby
12
7
  authors:
13
8
  - Steve Hodgkiss
@@ -26,10 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
24
  version: "3.0"
34
25
  type: :runtime
35
26
  version_requirements: *id001
@@ -41,9 +32,6 @@ dependencies:
41
32
  requirements:
42
33
  - - ">="
43
34
  - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
35
  version: "0"
48
36
  type: :runtime
49
37
  version_requirements: *id002
@@ -88,23 +76,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
76
  requirements:
89
77
  - - ">="
90
78
  - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
79
  version: "0"
95
80
  required_rubygems_version: !ruby/object:Gem::Requirement
96
81
  none: false
97
82
  requirements:
98
83
  - - ">="
99
84
  - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
85
  version: "0"
104
86
  requirements: []
105
87
 
106
88
  rubyforge_project: generator_spec
107
- rubygems_version: 1.5.3
89
+ rubygems_version: 1.5.2
108
90
  signing_key:
109
91
  specification_version: 3
110
92
  summary: Test Rails generators with RSpec