generator_spec 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f5f55ee0550c4513b26c1c9f37887564dc0742a9
4
- data.tar.gz: 1941a360c254f91d1334bb029400577a4105d431
2
+ SHA256:
3
+ metadata.gz: ceeb0b383b8f1ef8d46905ff7845c3107ca106de596def8f51d75a33a985d1fb
4
+ data.tar.gz: 7b9aef2d85862a990be2270a75294403e1579dbe55fa2766788969e73adb0769
5
5
  SHA512:
6
- metadata.gz: c987a55fd84da2dd427184688e3acc495dfe0d356e6e796ddfbb6c9c9511daa2b4e33cb56b07edef3042de01516575b6ccdf4ed3a7a788e8ccc133ea7abf2545
7
- data.tar.gz: e6d89ce7a9f778c785152e067d6e0d1ed3f726612c8deaa2971caa1768082ec6a8961cbc9b9946ff0207c32a2995d52dcc69c6c275a26eb93b8ec64b7ab204a6
6
+ metadata.gz: be6fba5bbfb8e534a19ed86c516d190efe91d01e5cdead0c0a9b19c219d6690b5cb18c008ff3853291e8632495dfd03cdb142bd626f85af11e9465bb12aec8fb
7
+ data.tar.gz: 3e4f9f7a012cd795b01e8cc5fd02b7d36c10f8ce49ce1886939403452f236b91f3c67c3f02313379ad353b2bfcaba5e546777ba0927ad24fc17866416d073071
data/.travis.yml CHANGED
@@ -1,11 +1,4 @@
1
1
  language: ruby
2
- sudo: false
3
- cache: bundler
4
2
  rvm:
5
- - 2.1
6
- - 2.0.0
7
- - jruby
8
- - rbx-2
9
- matrix:
10
- allow_failures:
11
- - rvm: jruby
3
+ - 2.4
4
+ - 2.3
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  platforms :rbx do
4
- gem 'rubysl', '~> 2.0'
4
+ # gem 'rubysl', '~> 2.2'
5
5
  gem 'rubinius-developer_tools'
6
6
  end
7
7
 
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
- "Structure should not have had #{@failure[1]}, but it did"
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,3 +1,3 @@
1
1
  module GeneratorSpec
2
- VERSION = '0.9.4'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'tmpdir'
3
3
 
4
- TMP_ROOT = Pathname.new(Dir.tmpdir)
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.9.4
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: 2017-05-18 00:00:00.000000000 Z
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
- rubyforge_project: generator_spec
105
- rubygems_version: 2.6.11
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: