genspec 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -2,8 +2,11 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - ree
6
- - jruby
7
5
  - ruby-head
8
- - rbx-2.0
6
+ - ree
7
+ - jruby-18mode
8
+ - jruby-19mode
9
+ - jruby-head
10
+ - rbx-18mode
11
+ - rbx-19mode
9
12
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- genspec (0.2.4)
4
+ genspec (0.2.5)
5
5
  i18n (>= 0.5.0)
6
6
  rspec (~> 2)
7
7
  sc-core-ext (~> 1.2.1)
@@ -79,14 +79,14 @@ GEM
79
79
  rake (0.9.2.2)
80
80
  rdoc (3.11)
81
81
  json (~> 1.4)
82
- rspec (2.8.0)
83
- rspec-core (~> 2.8.0)
84
- rspec-expectations (~> 2.8.0)
85
- rspec-mocks (~> 2.8.0)
86
- rspec-core (2.8.0)
87
- rspec-expectations (2.8.0)
88
- diff-lcs (~> 1.1.2)
89
- rspec-mocks (2.8.0)
82
+ rspec (2.9.0)
83
+ rspec-core (~> 2.9.0)
84
+ rspec-expectations (~> 2.9.0)
85
+ rspec-mocks (~> 2.9.0)
86
+ rspec-core (2.9.0)
87
+ rspec-expectations (2.9.0)
88
+ diff-lcs (~> 1.1.3)
89
+ rspec-mocks (2.9.0)
90
90
  sc-core-ext (1.2.1)
91
91
  activesupport (>= 2.3.5)
92
92
  sprockets (2.0.3)
data/lib/genspec.rb CHANGED
@@ -17,13 +17,17 @@ end
17
17
 
18
18
  require 'fileutils'
19
19
 
20
- require 'sc-core-ext'
21
- require 'genspec/version' unless defined?(GenSpec::VERSION)
22
- require 'genspec/shell'
23
- require 'genspec/matchers'
24
- require 'genspec/generator_example_group'
20
+ module GenSpec
21
+ def self.root; @root; end
22
+ def self.root=(root); @root = root; end
23
+
24
+ require 'sc-core-ext'
25
+ require 'genspec/version' unless defined?(GenSpec::VERSION)
26
+ require 'genspec/shell'
27
+ require 'genspec/matchers'
28
+ require 'genspec/generator_example_group'
29
+ end
25
30
 
26
- # RSpec 2.0 compat
27
31
  RSpec.configure do |config|
28
32
  config.include GenSpec::GeneratorExampleGroup, :example_group => { :file_path => /spec[\/]generators/ }
29
33
 
@@ -29,14 +29,15 @@ module GenSpec
29
29
  #
30
30
  def generator_descriptor
31
31
  {
32
- :described => self.class.target_generator,
32
+ :described => self.class.generator,
33
33
  :args => self.class.generator_args,
34
34
  :input => self.class.generator_input,
35
+ :output => self.class.generator_output,
35
36
  :init_blocks => generator_init_blocks,
36
37
  :generator_options => self.class.generator_options
37
38
  }
38
39
  end
39
-
40
+
40
41
  module ClassMethods
41
42
  # Sets the list of arguments for this generator.
42
43
  #
@@ -174,6 +175,17 @@ module GenSpec
174
175
  end
175
176
  end
176
177
 
178
+ # Returns the generator output string or IO, or nil.
179
+ def generator_output
180
+ return metadata[:generator_output] if metadata[:generator_output]
181
+
182
+ metadata[:generator_output] = if genspec_subclass?
183
+ superclass.generator_output
184
+ else
185
+ nil
186
+ end
187
+ end
188
+
177
189
  # Returns the input stream to be used for this context. If this context doesn't
178
190
  # have an input stream, its superclass is checked, and so on until either the
179
191
  # parent isn't a GenSpec or an input stream is found. Only the closest input
@@ -195,9 +207,15 @@ module GenSpec
195
207
 
196
208
  # Traverses up the context tree to find the topmost description, which represents
197
209
  # the controller to be tested or the string/symbol representing it.
198
- def target_generator
210
+ #
211
+ # If name is specified, it will be used instead and subsequent calls to this method
212
+ # will return the specified name.
213
+ def generator(name = nil)
214
+ metadata[:generator_name] = name.to_s if name
215
+ return metadata[:generator_name] if metadata[:generator_name]
216
+
199
217
  if genspec_subclass?
200
- superclass.target_generator
218
+ superclass.generator
201
219
  else
202
220
  describes || description
203
221
  end
@@ -22,7 +22,7 @@ module GenSpec
22
22
  @described = generator[:described]
23
23
  @args = generator[:args]
24
24
  @generator_options = generator[:generator_options]
25
- @shell = GenSpec::Shell.new("", generator[:input] || "")
25
+ @shell = GenSpec::Shell.new(generator[:output] || "", generator[:input] || "")
26
26
  @init_blocks = generator[:init_blocks]
27
27
 
28
28
  if @described.kind_of?(Class)
@@ -96,18 +96,27 @@ module GenSpec
96
96
  raise error if error && !@errors_silenced
97
97
  end
98
98
 
99
+ def mktmpdir(&block)
100
+ tmpdir_args = [ @described.to_s ]
101
+ if GenSpec.root
102
+ FileUtils.mkdir_p GenSpec.root
103
+ tmpdir_args << GenSpec.root
104
+ end
105
+ Dir.mktmpdir *tmpdir_args, &block
106
+ end
107
+
99
108
  def invoke
100
- Dir.mktmpdir do |tempdir|
109
+ mktmpdir do |tempdir|
101
110
  FileUtils.chdir tempdir do
102
111
  init_blocks.each do |block|
103
112
  block.call(tempdir)
104
113
  end
105
114
 
106
115
  @destination_root = tempdir
107
- @generator.start(@args || [], @generator_options.reverse_merge(
116
+ @generator.start @args || [], @generator_options.reverse_merge(
108
117
  :shell => @shell,
109
118
  :destination_root => destination_root
110
- ))
119
+ )
111
120
  check_for_errors
112
121
  generated
113
122
  end
@@ -2,7 +2,7 @@ module GenSpec
2
2
  class Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 5
5
+ PATCH = 6
6
6
  RELEASE = nil
7
7
 
8
8
  STRING = (RELEASE ? [MAJOR, MINOR, PATCH, RELEASE] : [MAJOR, MINOR, PATCH]).join('.')
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe GenSpec do
4
+ include GenSpec::GeneratorExampleGroup
5
+ generator :test_rails3
6
+ with_args "one", "two"
7
+
8
+ describe "with a custom root" do
9
+ before { GenSpec.root = File.expand_path("../../tmp", File.dirname(__FILE__)) }
10
+ after { GenSpec.root = nil }
11
+
12
+ it "should generate files in generation root" do
13
+ within_source_root { Dir[File.join(GenSpec.root, '**/*')].should_not be_empty }
14
+ subject.should generate("a_directory")
15
+ end
16
+ end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -23,5 +23,9 @@ if !defined?(Rails)
23
23
  require File.expand_path('support/generators/question/question_generator', File.dirname(__FILE__))
24
24
  end
25
25
 
26
+ RSpec.configure do |c|
27
+ c.before { GenSpec.root = File.expand_path('../tmp', File.dirname(__FILE__)) } if RUBY_PLATFORM =~ /java/i
28
+ end
29
+
26
30
  require File.join(File.dirname(__FILE__),"../lib/gen_spec")
27
31
  GenSpec::Matchers::GenerationMethodMatcher::GENERATION_CLASSES << "CustomActions"
@@ -23,10 +23,12 @@ class TestRails3 < base
23
23
  end
24
24
 
25
25
  def gen_gem_source
26
- if defined?(Rails)
27
- add_source "http://gems.github.com/"
28
- else
29
- append_file "Gemfile", 'source "http://gems.github.com/"'
26
+ if File.file?("Gemfile")
27
+ if defined?(Rails)
28
+ add_source "http://gems.github.com/"
29
+ else
30
+ append_file "Gemfile", 'source "http://gems.github.com/"'
31
+ end
30
32
  end
31
33
  end
32
34
  end
metadata CHANGED
@@ -1,71 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: genspec
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.6
4
5
  prerelease:
5
- version: 0.2.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Colin MacKenzie IV
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2010-07-08 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2010-07-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: thor
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152490020 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.14.6
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152490020
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2152489100 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "2"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: sc-core-ext
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2152489100
36
+ - !ruby/object:Gem::Dependency
37
+ name: sc-core-ext
38
+ requirement: &2152488220 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
42
+ - !ruby/object:Gem::Version
45
43
  version: 1.2.1
46
44
  type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: i18n
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2152488220
47
+ - !ruby/object:Gem::Dependency
48
+ name: i18n
49
+ requirement: &2152487180 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
56
54
  version: 0.5.0
57
55
  type: :runtime
58
- version_requirements: *id004
59
- description: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
56
+ prerelease: false
57
+ version_requirements: *2152487180
58
+ description: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For
59
+ the Rails 2.3 version, use genspec 0.1.x.
60
60
  email: sinisterchipmunk@gmail.com
61
61
  executables: []
62
-
63
62
  extensions: []
64
-
65
- extra_rdoc_files:
63
+ extra_rdoc_files:
66
64
  - LICENSE
67
65
  - README.rdoc
68
- files:
66
+ files:
69
67
  - .document
70
68
  - .gitignore
71
69
  - .rspec
@@ -89,6 +87,7 @@ files:
89
87
  - spec/generators/migration_spec.rb
90
88
  - spec/generators/question_spec.rb
91
89
  - spec/generators/test_rails3_spec.rb
90
+ - spec/lib/genspec_spec.rb
92
91
  - spec/rcov.opts
93
92
  - spec/rspec.opts
94
93
  - spec/spec_helper.rb
@@ -99,35 +98,35 @@ files:
99
98
  - spec/support/generators/test_rails3/test_rails3_generator.rb
100
99
  homepage: http://www.thoughtsincomputation.com
101
100
  licenses: []
102
-
103
101
  post_install_message:
104
- rdoc_options:
102
+ rdoc_options:
105
103
  - --charset=UTF-8
106
- require_paths:
104
+ require_paths:
107
105
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
109
107
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
114
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
113
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
120
118
  requirements: []
121
-
122
119
  rubyforge_project:
123
120
  rubygems_version: 1.8.10
124
121
  signing_key:
125
122
  specification_version: 3
126
- summary: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
127
- test_files:
123
+ summary: Simple, expressive Thor and/or Rails 3 generator testing for RSpec. For the
124
+ Rails 2.3 version, use genspec 0.1.x.
125
+ test_files:
128
126
  - spec/generators/migration_spec.rb
129
127
  - spec/generators/question_spec.rb
130
128
  - spec/generators/test_rails3_spec.rb
129
+ - spec/lib/genspec_spec.rb
131
130
  - spec/rcov.opts
132
131
  - spec/rspec.opts
133
132
  - spec/spec_helper.rb