ammeter 1.1.0 → 1.1.1
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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ca6302a39acf11feaf4ba8a22bcba28402d841c
|
4
|
+
data.tar.gz: 03c39f82a6bf5cdf102dfe20adec75e092bf5bc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f76eddb2fda86bc36f0ab60cf5eea848f9b2cfb5ab5673d699e3f398127599f4783ec35f8aefb773004161bc01abbe1c686f3f181da815ab88889e03e0be5c1
|
7
|
+
data.tar.gz: ce477ea8f9e05a7c111c85d9cf3f5a22b2743782edf333f90474e85cb52883beb076e2db13d8154cbe3879362331d626de7ada71774e27b4ad6a90fca9585e37
|
@@ -10,13 +10,14 @@ Feature: generator spec
|
|
10
10
|
class AwesomeGenerator < Rails::Generators::NamedBase
|
11
11
|
source_root File.expand_path('../templates', __FILE__)
|
12
12
|
class_option :super, :type => :boolean, :default => false
|
13
|
+
class_option :someone, :type => :string
|
13
14
|
|
14
15
|
def create_awesomeness
|
15
16
|
template 'awesome.html', File.join('public', name, "#{"super_" if options[:super]}awesome.html")
|
16
17
|
end
|
17
18
|
|
18
19
|
def create_lameness
|
19
|
-
template 'lame.html', File.join('public', name, "#{"super_" if options[:super]}lame.html")
|
20
|
+
template 'lame.html.erb', File.join('public', name, "#{"super_" if options[:super]}lame.html")
|
20
21
|
end
|
21
22
|
end
|
22
23
|
"""
|
@@ -24,9 +25,9 @@ Feature: generator spec
|
|
24
25
|
"""
|
25
26
|
This is an awesome file
|
26
27
|
"""
|
27
|
-
And a file named "lib/generators/awesome/templates/lame.html" with:
|
28
|
+
And a file named "lib/generators/awesome/templates/lame.html.erb" with:
|
28
29
|
"""
|
29
|
-
|
30
|
+
<%= options[:someone] %> is lame
|
30
31
|
"""
|
31
32
|
|
32
33
|
Scenario: A spec that runs the entire generator
|
@@ -36,23 +37,35 @@ Feature: generator spec
|
|
36
37
|
require 'generators/awesome/awesome_generator'
|
37
38
|
|
38
39
|
describe AwesomeGenerator do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
describe 'invoke' do
|
41
|
+
before { run_generator %w(my_dir --someone Alex) }
|
42
|
+
describe 'public/my_dir/awesome.html' do
|
43
|
+
subject { file('public/my_dir/awesome.html') }
|
44
|
+
it { expect(subject).to exist }
|
45
|
+
it { expect(subject).to contain 'This is an awesome file' }
|
46
|
+
it { expect(subject).to_not contain 'This text is not in the file' }
|
47
|
+
end
|
48
|
+
describe 'public/my_dir/lame.html' do
|
49
|
+
subject { file('public/my_dir/lame.html') }
|
50
|
+
it { expect(subject).to exist }
|
51
|
+
it { expect(subject).to contain 'Alex is lame' }
|
52
|
+
it { expect(subject).to_not contain 'This text is not in the file' }
|
53
|
+
end
|
45
54
|
end
|
46
|
-
describe '
|
47
|
-
subject { file('public/my_dir/
|
48
|
-
it
|
49
|
-
|
50
|
-
|
55
|
+
describe 'revoke' do
|
56
|
+
subject { file('public/my_dir/awesome.html') }
|
57
|
+
it 'can run a reverse migration' do
|
58
|
+
FileUtils.mkdir_p(File.dirname(subject))
|
59
|
+
File.write(subject, "test file")
|
60
|
+
expect(subject).to exist
|
61
|
+
run_generator %w(my_dir --someone Alex), behavior: :revoke
|
62
|
+
expect(subject).not_to exist
|
63
|
+
end
|
51
64
|
end
|
52
65
|
end
|
53
66
|
"""
|
54
67
|
When I run `rake spec`
|
55
|
-
Then the output should contain "
|
68
|
+
Then the output should contain "7 examples, 0 failures"
|
56
69
|
|
57
70
|
Scenario: A spec that runs one task in the generator
|
58
71
|
Given a file named "spec/generators/another_awesome_generator_spec.rb" with:
|
data/lib/ammeter/init.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Ammeter
|
2
|
+
class OutputCapturer
|
3
|
+
# Is this thread safe!?!?
|
4
|
+
# This won't work with sub-processes
|
5
|
+
def self.capture(io, &block)
|
6
|
+
case io
|
7
|
+
when :stdout
|
8
|
+
capture_stdout(&block)
|
9
|
+
when :stderr
|
10
|
+
capture_stderr(&block)
|
11
|
+
else
|
12
|
+
raise "Unknown IO #{io}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.capture_stdout(&block)
|
17
|
+
captured_stream = StringIO.new
|
18
|
+
|
19
|
+
orginal_io, $stdout = $stdout, captured_stream
|
20
|
+
|
21
|
+
block.call
|
22
|
+
|
23
|
+
captured_stream.string
|
24
|
+
ensure
|
25
|
+
$stdout = orginal_io
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.capture_stderr(&block)
|
29
|
+
captured_stream = StringIO.new
|
30
|
+
|
31
|
+
orginal_io, $stderr = $stderr, captured_stream
|
32
|
+
|
33
|
+
block.call
|
34
|
+
|
35
|
+
captured_stream.string
|
36
|
+
ensure
|
37
|
+
$stderr = orginal_io
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -13,7 +13,7 @@ module Ammeter
|
|
13
13
|
extend ActiveSupport::Concern
|
14
14
|
include ::RSpec::Rails::RailsExampleGroup
|
15
15
|
|
16
|
-
DELEGATED_METHODS = [:
|
16
|
+
DELEGATED_METHODS = [:destination_root, :current_path, :generator_class]
|
17
17
|
module ClassMethods
|
18
18
|
mattr_accessor :test_unit_test_case_delegate
|
19
19
|
delegate :default_arguments, :to => :'self.test_unit_test_case_delegate'
|
@@ -44,12 +44,12 @@ module Ammeter
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def run_generator(given_args=self.default_arguments, config={})
|
47
|
-
capture(:stdout) { generator(given_args, config).invoke_all }
|
47
|
+
OutputCapturer.capture(:stdout) { generator(given_args, config).invoke_all }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def invoke_task name
|
52
|
-
capture(:stdout) { generator.invoke_task(generator_class.all_tasks[name.to_s]) }
|
52
|
+
OutputCapturer.capture(:stdout) { generator.invoke_task(generator_class.all_tasks[name.to_s]) }
|
53
53
|
end
|
54
54
|
|
55
55
|
included do
|
data/lib/ammeter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ammeter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rothenberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -238,6 +238,7 @@ files:
|
|
238
238
|
- features/templates/rspec.rake
|
239
239
|
- lib/ammeter.rb
|
240
240
|
- lib/ammeter/init.rb
|
241
|
+
- lib/ammeter/output_capturer.rb
|
241
242
|
- lib/ammeter/railtie.rb
|
242
243
|
- lib/ammeter/rspec/generator/example.rb
|
243
244
|
- lib/ammeter/rspec/generator/example/generator_example_group.rb
|