Skip to content

Commit 750899c

Browse files
Merge pull request #50 from anitagraham/descriptions
Compatible with Ruby 3.2
2 parents f1fb8b4 + d7bcf99 commit 750899c

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source "http://rubygems.org"
22

33
platforms :rbx do
4-
gem 'rubysl', '~> 2.0'
4+
# gem 'rubysl', '~> 2.2'
55
gem 'rubinius-developer_tools'
66
end
77

lib/generator_spec/matcher.rb

+27-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ module GeneratorSpec
22
module Matcher
33
# Taken (with permission) from beard by Yahuda Katz
44
# https://github.com/carlhuda/beard
5-
5+
66
class File
7+
8+
def description
9+
'file attributes and content'
10+
end
11+
712
def initialize(name, &block)
813
@contents = []
914
@name = name
@@ -24,9 +29,9 @@ def matches?(root)
2429

2530
check_contents(root.join(@name))
2631
end
27-
32+
2833
protected
29-
34+
3035
def check_contents(file)
3136
contents = ::File.read(file)
3237

@@ -37,20 +42,24 @@ def check_contents(file)
3742
end
3843
end
3944
end
40-
45+
4146
class Migration < File
47+
def description
48+
'valid migration file'
49+
end
50+
4251
def matches?(root)
4352
file_name = migration_file_name(root, @name)
44-
53+
4554
unless file_name && file_name.exist?
4655
throw :failure, @name
4756
end
48-
57+
4958
check_contents(file_name)
5059
end
51-
60+
5261
protected
53-
62+
5463
def migration_file_name(root, name) #:nodoc:
5564
directory, file_name = ::File.dirname(root.join(name)), ::File.basename(name).sub(/\.rb$/, '')
5665
migration = Dir.glob("#{directory}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
@@ -61,6 +70,10 @@ def migration_file_name(root, name) #:nodoc:
6170
class Directory
6271
attr_reader :tree
6372

73+
def description
74+
'has directory structure'
75+
end
76+
6477
def initialize(root = nil, &block)
6578
@tree = {}
6679
@negative_tree = []
@@ -83,7 +96,7 @@ def no_file(name)
8396
def location(name)
8497
[@root, name].compact.join("/")
8598
end
86-
99+
87100
def migration(name, &block)
88101
@tree[name] = Migration.new(location(name), &block)
89102
end
@@ -110,6 +123,10 @@ def matches?(root)
110123
end
111124

112125
class Root < Directory
126+
def description
127+
'have specified directory structure'
128+
end
129+
113130
def failure_message
114131
if @failure.is_a?(Array) && @failure[0] == :not
115132
"Structure should not have had #{@failure[1]}, but it did"
@@ -136,4 +153,4 @@ def have_structure(&block)
136153
Root.new(&block)
137154
end
138155
end
139-
end
156+
end

lib/generator_spec/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module GeneratorSpec
2-
VERSION = '0.9.4'
2+
VERSION = '0.9.5'
33
end

spec/generator_spec/matcher_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22
require 'tmpdir'
33

4-
TMP_ROOT = Pathname.new(Dir.tmpdir)
4+
TMP_ROOT = Pathname.new(Dir.tmpdir).join('generator')
55

66
describe TestGenerator, 'using custom matcher' do
77
include GeneratorSpec::TestCase
@@ -72,6 +72,7 @@ module Matcher
7272
let(:location) { TMP_ROOT.join('test_file') }
7373

7474
context 'with no contains' do
75+
7576
it 'doesnt throw if the file exists' do
7677
write_file(location, '')
7778
expect {
@@ -84,6 +85,7 @@ module Matcher
8485
file.matches?(TMP_ROOT)
8586
}.to throw_symbol(:failure)
8687
end
88+
8789
end
8890

8991
context 'with contains' do

0 commit comments

Comments
 (0)