ammeter 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,13 +8,14 @@ Feature: generator spec
8
8
  """
9
9
  class AwesomeGenerator < Rails::Generators::NamedBase
10
10
  source_root File.expand_path('../templates', __FILE__)
11
+ class_option :super, :type => :boolean, :default => false
11
12
 
12
13
  def create_awesomeness
13
- template 'awesome.html', File.join('public', name, 'awesome.html')
14
+ template 'awesome.html', File.join('public', name, "#{"super_" if options[:super]}awesome.html")
14
15
  end
15
16
 
16
17
  def create_lameness
17
- template 'lame.html', File.join('public', name, 'lame.html')
18
+ template 'lame.html', File.join('public', name, "#{"super_" if options[:super]}lame.html")
18
19
  end
19
20
  end
20
21
  """
@@ -36,41 +37,142 @@ Feature: generator spec
36
37
  describe AwesomeGenerator do
37
38
  destination File.expand_path("../../tmp", __FILE__)
38
39
 
39
- before do
40
- run_generator %w(my_dir)
40
+ before { run_generator %w(my_dir) }
41
+ describe 'public/my_dir/awesome.html' do
42
+ subject { file('public/my_dir/awesome.html') }
43
+ it { should exist }
44
+ it { should contain 'This is an awesome file' }
45
+ it { should_not contain 'This text is not in the file' }
46
+ end
47
+ describe 'public/my_dir/lame.html' do
48
+ subject { file('public/my_dir/lame.html') }
49
+ it { should exist }
50
+ it { should contain 'This is a lame file' }
51
+ it { should_not contain 'This text is not in the file' }
41
52
  end
42
- it 'should copy the awesome file into public' do
43
- file('public/my_dir/awesome.html').should exist
53
+ end
54
+ """
55
+ When I run `rake spec`
56
+ Then the output should contain "6 examples, 0 failures"
57
+
58
+ Scenario: A spec that runs one task in the generator
59
+ Given a file named "spec/generators/another_awesome_generator_spec.rb" with:
60
+ """
61
+ require "spec_helper"
62
+ require 'generators/awesome/awesome_generator'
63
+
64
+ describe AwesomeGenerator do
65
+ destination File.expand_path("../../tmp", __FILE__)
66
+ arguments %w(another_dir)
67
+
68
+ before { invoke_task :create_awesomeness }
69
+ describe 'public/another_dir/awesome.html' do
70
+ subject { file('public/another_dir/awesome.html') }
71
+ it { should exist }
72
+ it { should contain 'This is an awesome file' }
73
+ it { should_not contain 'This text is not in the file' }
44
74
  end
45
- it 'should copy the lame file into public' do
46
- file('public/my_dir/lame.html').should exist
75
+ describe 'public/another_dir/lame.html' do
76
+ subject { file('public/another_dir/lame.html') }
77
+ it { should_not exist }
47
78
  end
48
79
  end
49
80
  """
50
81
  When I run `rake spec`
51
- Then the output should contain "2 examples, 0 failures"
82
+ Then the output should contain "4 examples, 0 failures"
83
+
84
+ Scenario: A spec with some failures shows good error messages
85
+ Given a file named "spec/generators/awesome_generator_spec.rb" with:
86
+ """
87
+ require "spec_helper"
88
+ require 'generators/awesome/awesome_generator'
89
+
90
+ describe AwesomeGenerator do
91
+ destination File.expand_path("../../tmp", __FILE__)
52
92
 
53
- Scenario: A spec that runs one task in the generator
54
- Given a file named "spec/generators/another_awesome_generator_spec.rb" with:
55
- """
56
- require "spec_helper"
57
- require 'generators/awesome/awesome_generator'
58
-
59
- describe AwesomeGenerator do
60
- destination File.expand_path("../../tmp", __FILE__)
61
- arguments %w(another_dir)
62
-
63
- before do
64
- invoke_task :create_awesomeness
65
- end
66
- it 'should copy the awesome file into public' do
67
- file('public/another_dir/awesome.html').should exist
68
- file('public/another_dir/awesome.html').should contain 'This is an awesome file'
69
- end
70
- it 'should not have copied the lame file into public' do
71
- file('public/another_dir/lame.html').should_not exist
72
- end
93
+ before { run_generator %w(my_dir) }
94
+ describe 'public/my_dir/awesome.html' do
95
+ subject { file('public/my_dir/awesome.html') }
96
+ it { should_not contain 'This is an awesome file' }
97
+ it { should contain 'This text is not in the file' }
98
+ it { should_not exist }
73
99
  end
74
- """
75
- When I run `rake spec`
76
- Then the output should contain "2 examples, 0 failures"
100
+ describe 'public/my_dir/non_existent.html' do
101
+ subject { file('public/my_dir/non_existent.html') }
102
+ it { should exist }
103
+ end
104
+ describe 'db/migrate/non_existent_migration.rb' do
105
+ subject { migration_file('db/migrate/non_existent_migration.rb') }
106
+ it { should exist }
107
+ end
108
+ end
109
+ """
110
+ When I run `rake spec`
111
+ Then the output should contain "5 examples, 5 failures"
112
+ And the output should contain:
113
+ """
114
+ /tmp/public/my_dir/awesome.html to not contain "This is an awesome file" but it did
115
+ """
116
+ And the output should contain:
117
+ """
118
+ /tmp/public/my_dir/awesome.html to contain "This text is not in the file" but it contained "This is an awesome file"
119
+ """
120
+ And the output should contain:
121
+ """
122
+ /tmp/public/my_dir/awesome.html" not to exist
123
+ """
124
+ And the output should contain:
125
+ """
126
+ /tmp/public/my_dir/non_existent.html" to exist
127
+ """
128
+ And the output should contain:
129
+ """
130
+ db/migrate/TIMESTAMP_non_existent_migration.rb" to exist
131
+ """
132
+
133
+ Scenario: Can specify arguments separately from running the generator
134
+ Given a file named "spec/generators/awesome_generator_spec.rb" with:
135
+ """
136
+ require "spec_helper"
137
+ require 'generators/awesome/awesome_generator'
138
+
139
+ describe AwesomeGenerator do
140
+ destination File.expand_path("../../tmp", __FILE__)
141
+ arguments %w(my_dir --super)
142
+
143
+ before { generator.invoke_all }
144
+ describe 'public/my_dir/super_awesome.html' do
145
+ subject { file('public/my_dir/super_awesome.html') }
146
+ it { should exist }
147
+ end
148
+ describe 'public/my_dir/super_lame.html' do
149
+ subject { file('public/my_dir/super_lame.html') }
150
+ it { should exist }
151
+ end
152
+ end
153
+ """
154
+ When I run `rake spec`
155
+ Then the output should contain "2 examples, 0 failures"
156
+
157
+ Scenario: A generator that creates a migration
158
+ Given a file named "spec/generators/a_migration_spec.rb" with:
159
+ """
160
+ require "spec_helper"
161
+ require 'rails/generators/active_record/migration/migration_generator'
162
+
163
+ describe ActiveRecord::Generators::MigrationGenerator do
164
+ destination File.expand_path("../../tmp", __FILE__)
165
+
166
+ before do
167
+ prepare_destination
168
+ run_generator %w(create_posts)
169
+ end
170
+ subject { migration_file('db/migrate/create_posts.rb') }
171
+ it { should exist }
172
+ it { should contain 'class CreatePosts < ActiveRecord::Migration' }
173
+ end
174
+ """
175
+ When I run `rake spec`
176
+ Then the output should contain "2 examples, 0 failures"
177
+
178
+
@@ -11,7 +11,7 @@ module Ammeter
11
11
  extend ActiveSupport::Concern
12
12
  include ::RSpec::Rails::RailsExampleGroup
13
13
 
14
- DELEGATED_METHODS = [:generator, :capture, :prepare_destination,
14
+ DELEGATED_METHODS = [:capture, :prepare_destination,
15
15
  :destination_root, :current_path, :generator_class]
16
16
  module ClassMethods
17
17
  mattr_accessor :test_unit_test_case_delegate
@@ -24,11 +24,18 @@ module Ammeter
24
24
  def initialize_delegate
25
25
  self.test_unit_test_case_delegate = ::Rails::Generators::TestCase.new 'pending'
26
26
  self.test_unit_test_case_delegate.class.tests(describes)
27
+ @generator = nil
28
+ end
29
+
30
+ def generator(given_args=self.default_arguments, config={})
31
+ @generator ||= begin
32
+ args, opts = Thor::Options.split(given_args)
33
+ self.test_unit_test_case_delegate.generator(args, opts, config)
34
+ end
27
35
  end
28
36
 
29
37
  def run_generator(given_args=self.default_arguments, config={})
30
- args, opts = Thor::Options.split(given_args)
31
- capture(:stdout) { generator(args, opts, config).invoke_all }
38
+ capture(:stdout) { generator(given_args, config).invoke_all }
32
39
  end
33
40
  end
34
41
 
@@ -39,7 +46,7 @@ module Ammeter
39
46
  end
40
47
 
41
48
  included do
42
- delegate :run_generator, :destination, :arguments, :to => :'self.class'
49
+ delegate :generator, :run_generator, :destination, :arguments, :to => :'self.class'
43
50
  DELEGATED_METHODS.each do |method|
44
51
  delegate method, :to => :'self.class'
45
52
  end
@@ -67,6 +74,12 @@ module Ammeter
67
74
  def file relative
68
75
  File.expand_path(relative, destination_root)
69
76
  end
77
+ def migration_file relative
78
+ file_path = file(relative)
79
+ migration_file = Dir.glob("#{File.dirname(file_path)}/[0-9]*_#{File.basename(file_path)}").first
80
+ migration_file = "#{File.dirname(file_path)}/TIMESTAMP_#{File.basename(file_path)}" if migration_file.nil?
81
+ migration_file
82
+ end
70
83
  end
71
84
  end
72
85
  end
@@ -13,7 +13,7 @@ RSpec::Matchers.define :contain do |expected_content|
13
13
  "expected the file #{file_path} to contain #{expected_content.inspect} but it contained #{@actual_contents.inspect}"
14
14
  end
15
15
 
16
- failure_message_for_should_not do |relative|
17
- "expected the file #{file_path} to not contain #{expected_content} but it did"
16
+ failure_message_for_should_not do |file_path|
17
+ "expected the file #{file_path} to not contain #{expected_content.inspect} but it did"
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module Ammeter
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -41,6 +41,33 @@ module Ammeter::RSpec::Rails
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ describe 'working with files' do
46
+ let(:path_to_gem_root_tmp) { File.expand_path(__FILE__ + '../../../../../../../../tmp') }
47
+ before do
48
+ group.destination path_to_gem_root_tmp
49
+ FileUtils.rm_rf path_to_gem_root_tmp
50
+ FileUtils.mkdir path_to_gem_root_tmp
51
+ end
52
+ it 'should use destination to find relative root file' do
53
+ group.file('app/model/post.rb').should == "#{path_to_gem_root_tmp}/app/model/post.rb"
54
+ end
55
+
56
+ describe 'migrations' do
57
+ before do
58
+ tmp_db_migrate = path_to_gem_root_tmp + '/db/migrate'
59
+ FileUtils.mkdir_p tmp_db_migrate
60
+ FileUtils.touch(tmp_db_migrate + '/20111010200000_create_comments.rb')
61
+ FileUtils.touch(tmp_db_migrate + '/20111010203337_create_posts.rb')
62
+ end
63
+ it 'should use destination to find relative root file' do
64
+ group.migration_file('db/migrate/create_posts.rb').should == "#{path_to_gem_root_tmp}/db/migrate/20111010203337_create_posts.rb"
65
+ end
66
+ it 'should stick "TIMESTAMP" in when migration does not exist' do
67
+ group.migration_file('db/migrate/migration_that_is_not_there.rb').should == "#{path_to_gem_root_tmp}/db/migrate/TIMESTAMP_migration_that_is_not_there.rb"
68
+ end
69
+ end
70
+ end
44
71
  end
45
72
  end
46
73
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ammeter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
5
+ version: 0.2.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Alex Rothenberg
@@ -15,211 +10,162 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-10-06 00:00:00 -04:00
13
+ date: 2011-10-13 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
22
- prerelease: false
17
+ name: railties
23
18
  requirement: &id001 !ruby/object:Gem::Requirement
24
19
  none: false
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
23
  version: "3.0"
33
24
  type: :runtime
34
- name: railties
25
+ prerelease: false
35
26
  version_requirements: *id001
36
27
  - !ruby/object:Gem::Dependency
37
- prerelease: false
28
+ name: activesupport
38
29
  requirement: &id002 !ruby/object:Gem::Requirement
39
30
  none: false
40
31
  requirements:
41
32
  - - ~>
42
33
  - !ruby/object:Gem::Version
43
- hash: 7
44
- segments:
45
- - 3
46
- - 0
47
34
  version: "3.0"
48
35
  type: :runtime
49
- name: activesupport
36
+ prerelease: false
50
37
  version_requirements: *id002
51
38
  - !ruby/object:Gem::Dependency
52
- prerelease: false
39
+ name: rspec
53
40
  requirement: &id003 !ruby/object:Gem::Requirement
54
41
  none: false
55
42
  requirements:
56
43
  - - ~>
57
44
  - !ruby/object:Gem::Version
58
- hash: 7
59
- segments:
60
- - 2
61
- - 2
62
45
  version: "2.2"
63
46
  type: :runtime
64
- name: rspec
47
+ prerelease: false
65
48
  version_requirements: *id003
66
49
  - !ruby/object:Gem::Dependency
67
- prerelease: false
50
+ name: rspec-rails
68
51
  requirement: &id004 !ruby/object:Gem::Requirement
69
52
  none: false
70
53
  requirements:
71
54
  - - ~>
72
55
  - !ruby/object:Gem::Version
73
- hash: 7
74
- segments:
75
- - 2
76
- - 2
77
56
  version: "2.2"
78
57
  type: :runtime
79
- name: rspec-rails
58
+ prerelease: false
80
59
  version_requirements: *id004
81
60
  - !ruby/object:Gem::Dependency
82
- prerelease: false
61
+ name: rails
83
62
  requirement: &id005 !ruby/object:Gem::Requirement
84
63
  none: false
85
64
  requirements:
86
65
  - - ~>
87
66
  - !ruby/object:Gem::Version
88
- hash: 5
89
- segments:
90
- - 3
91
- - 1
92
67
  version: "3.1"
93
68
  type: :development
94
- name: rails
69
+ prerelease: false
95
70
  version_requirements: *id005
96
71
  - !ruby/object:Gem::Dependency
97
- prerelease: false
72
+ name: uglifier
98
73
  requirement: &id006 !ruby/object:Gem::Requirement
99
74
  none: false
100
75
  requirements:
101
76
  - - ">="
102
77
  - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
78
  version: "0"
107
79
  type: :development
108
- name: uglifier
80
+ prerelease: false
109
81
  version_requirements: *id006
110
82
  - !ruby/object:Gem::Dependency
111
- prerelease: false
83
+ name: turn
112
84
  requirement: &id007 !ruby/object:Gem::Requirement
113
85
  none: false
114
86
  requirements:
115
87
  - - ">="
116
88
  - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
89
  version: "0"
121
90
  type: :development
122
- name: turn
91
+ prerelease: false
123
92
  version_requirements: *id007
124
93
  - !ruby/object:Gem::Dependency
125
- prerelease: false
94
+ name: rake
126
95
  requirement: &id008 !ruby/object:Gem::Requirement
127
96
  none: false
128
97
  requirements:
129
98
  - - ">="
130
99
  - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
100
  version: "0"
135
101
  type: :development
136
- name: rake
102
+ prerelease: false
137
103
  version_requirements: *id008
138
104
  - !ruby/object:Gem::Dependency
139
- prerelease: false
105
+ name: coffee-rails
140
106
  requirement: &id009 !ruby/object:Gem::Requirement
141
107
  none: false
142
108
  requirements:
143
109
  - - ">="
144
110
  - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
111
  version: "0"
149
112
  type: :development
150
- name: coffee-rails
113
+ prerelease: false
151
114
  version_requirements: *id009
152
115
  - !ruby/object:Gem::Dependency
153
- prerelease: false
116
+ name: sass-rails
154
117
  requirement: &id010 !ruby/object:Gem::Requirement
155
118
  none: false
156
119
  requirements:
157
120
  - - ">="
158
121
  - !ruby/object:Gem::Version
159
- hash: 3
160
- segments:
161
- - 0
162
122
  version: "0"
163
123
  type: :development
164
- name: sass-rails
124
+ prerelease: false
165
125
  version_requirements: *id010
166
126
  - !ruby/object:Gem::Dependency
167
- prerelease: false
127
+ name: jquery-rails
168
128
  requirement: &id011 !ruby/object:Gem::Requirement
169
129
  none: false
170
130
  requirements:
171
131
  - - ">="
172
132
  - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
175
- - 0
176
133
  version: "0"
177
134
  type: :development
178
- name: jquery-rails
135
+ prerelease: false
179
136
  version_requirements: *id011
180
137
  - !ruby/object:Gem::Dependency
181
- prerelease: false
138
+ name: cucumber
182
139
  requirement: &id012 !ruby/object:Gem::Requirement
183
140
  none: false
184
141
  requirements:
185
142
  - - ~>
186
143
  - !ruby/object:Gem::Version
187
- hash: 31
188
- segments:
189
- - 0
190
- - 10
191
144
  version: "0.10"
192
145
  type: :development
193
- name: cucumber
146
+ prerelease: false
194
147
  version_requirements: *id012
195
148
  - !ruby/object:Gem::Dependency
196
- prerelease: false
149
+ name: aruba
197
150
  requirement: &id013 !ruby/object:Gem::Requirement
198
151
  none: false
199
152
  requirements:
200
153
  - - ~>
201
154
  - !ruby/object:Gem::Version
202
- hash: 13
203
- segments:
204
- - 0
205
- - 3
206
155
  version: "0.3"
207
156
  type: :development
208
- name: aruba
157
+ prerelease: false
209
158
  version_requirements: *id013
210
159
  - !ruby/object:Gem::Dependency
211
- prerelease: false
160
+ name: sqlite3
212
161
  requirement: &id014 !ruby/object:Gem::Requirement
213
162
  none: false
214
163
  requirements:
215
164
  - - ~>
216
165
  - !ruby/object:Gem::Version
217
- hash: 1
218
- segments:
219
- - 1
220
166
  version: "1"
221
167
  type: :development
222
- name: sqlite3
168
+ prerelease: false
223
169
  version_requirements: *id014
224
170
  description: Write specs for your Rails 3 generators
225
171
  email:
@@ -273,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
273
219
  requirements:
274
220
  - - ">="
275
221
  - !ruby/object:Gem::Version
276
- hash: 3
222
+ hash: -856853819327253995
277
223
  segments:
278
224
  - 0
279
225
  version: "0"
@@ -282,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
228
  requirements:
283
229
  - - ">="
284
230
  - !ruby/object:Gem::Version
285
- hash: 3
231
+ hash: -856853819327253995
286
232
  segments:
287
233
  - 0
288
234
  version: "0"