genspec 0.1.1 → 0.2.0.prerails3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.rdoc +79 -31
  2. data/Rakefile +69 -22
  3. data/VERSION +1 -1
  4. data/genspec.gemspec +31 -40
  5. data/lib/gen_spec.rb +1 -0
  6. data/lib/genspec.rb +23 -8
  7. data/lib/genspec/generator_example_group.rb +47 -52
  8. data/lib/genspec/matchers.rb +59 -0
  9. data/lib/genspec/matchers/base.rb +148 -0
  10. data/lib/genspec/matchers/generation_method_matcher.rb +88 -0
  11. data/lib/genspec/matchers/output_matcher.rb +34 -0
  12. data/lib/genspec/matchers/result_matcher.rb +28 -0
  13. data/lib/genspec/shell.rb +99 -0
  14. data/pkg/genspec-0.1.1.gem +0 -0
  15. data/pkg/genspec-0.2.0.pre1.gem +0 -0
  16. data/pkg/genspec-0.2.0.prerails3.1.gem +0 -0
  17. data/spec/generators/test_rails3_spec.rb +74 -0
  18. data/spec/rcov.opts +2 -0
  19. data/spec/rspec.opts +2 -0
  20. data/spec/spec_helper.rb +10 -3
  21. data/spec/support/generators/test_rails3/USAGE +8 -0
  22. data/spec/support/generators/{test → test_rails3}/templates/file +0 -0
  23. data/spec/support/generators/test_rails3/test_rails3_generator.rb +23 -0
  24. metadata +48 -40
  25. data/lib/genspec/generation_matchers.rb +0 -27
  26. data/lib/genspec/generation_matchers/generation_matcher.rb +0 -147
  27. data/lib/genspec/generation_matchers/result_matcher.rb +0 -42
  28. data/pkg/genspec-0.0.0.gem +0 -0
  29. data/pkg/genspec-0.1.0.gem +0 -0
  30. data/rdoc/classes/GenSpec.html +0 -124
  31. data/rdoc/classes/GenSpec/GenerationMatchers.html +0 -197
  32. data/rdoc/classes/GenSpec/GenerationMatchers/GenerationMatcher.html +0 -363
  33. data/rdoc/classes/GenSpec/GenerationMatchers/ResultMatcher.html +0 -241
  34. data/rdoc/classes/GenSpec/GeneratorExampleGroup.html +0 -285
  35. data/rdoc/created.rid +0 -1
  36. data/rdoc/files/README_rdoc.html +0 -261
  37. data/rdoc/files/lib/genspec/generation_matchers/generation_matcher_rb.html +0 -101
  38. data/rdoc/files/lib/genspec/generation_matchers/result_matcher_rb.html +0 -101
  39. data/rdoc/files/lib/genspec/generation_matchers_rb.html +0 -109
  40. data/rdoc/files/lib/genspec/generator_example_group_rb.html +0 -101
  41. data/rdoc/files/lib/genspec_rb.html +0 -114
  42. data/rdoc/fr_class_index.html +0 -31
  43. data/rdoc/fr_file_index.html +0 -32
  44. data/rdoc/fr_method_index.html +0 -46
  45. data/rdoc/index.html +0 -26
  46. data/rdoc/rdoc-style.css +0 -208
  47. data/spec/generators/test_spec.rb +0 -96
  48. data/spec/support/generators/test/test_generator.rb +0 -29
data/README.rdoc CHANGED
@@ -1,14 +1,19 @@
1
1
  = genspec
2
2
 
3
- Simple, expressive Rails generator testing for RSpec.
3
+ Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.
4
4
 
5
5
  == Installation
6
6
 
7
- sudo gem install genspec
7
+ sudo gem install genspec --pre
8
8
 
9
- ...then, in your config/environments/test.rb...
9
+ ...then, in your Gemfile...
10
10
 
11
- config.gem 'genspec'
11
+ group :test do
12
+ config.gem 'genspec'
13
+ end
14
+
15
+ Warning: The prerelease version is for Rails 3.0 and is NOT compatible with 2.x! See the master branch
16
+ for the Rails 2.3 version.
12
17
 
13
18
  == Usage
14
19
 
@@ -35,6 +40,49 @@ A basic generator spec might look something like this:
35
40
  end
36
41
  end
37
42
 
43
+ === Specifying Arguments
44
+
45
+ You may have noticed in the example above that we used _with_args_ to set up arguments passed into the generator. We
46
+ can also pass any options we wish into that array. For instance, to pretend the _--verbose_ option was passed, we
47
+ could use the following spec:
48
+
49
+ describe :custom_controller do
50
+ context "with --verbose option" do
51
+ with_args "--verbose"
52
+
53
+ # . . .
54
+ end
55
+ end
56
+
57
+ Here is another example using _with_args_:
58
+
59
+ describe :custom_controller do
60
+ context "with a users controller and index, new, edit actions" do
61
+ with_args :users, :index, :new, :edit
62
+
63
+ # . . .
64
+ end
65
+ end
66
+
67
+ Note that no matter what you specify as arguments, they'll be converted to an array of Strings -- because this is what
68
+ gets passed into the generator if you run it from the command line. You can bypass that by passing an :object => true
69
+ option as the last argument:
70
+
71
+ describe :custom_controller do
72
+ with_args MyFancyObject.new, :object => true
73
+ # . . .
74
+ end
75
+
76
+ Finally, you can also let with_args generate a context for you:
77
+
78
+ describe :custom_controller do
79
+ with_args :users, :index, :new, :edit do
80
+ # . . .
81
+ end
82
+ end
83
+
84
+ This will generate an RSpec context that reads something like, "...with arguments [:users, :index, :new, :edit]".
85
+
38
86
  === Checking for Output
39
87
 
40
88
  If you need to test the generator's feedback rather than the generator's results, you can use the _output_ matcher to
@@ -62,8 +110,8 @@ as passing the name of the file you expected to be generated:
62
110
  subject.should generate("README")
63
111
  end
64
112
 
65
- You can also check the generated file's content by simply passing a block. The argument in the block is the plaintext
66
- content of the file:
113
+ You can also check the generated file's content by simply passing a block. The _content_ argument in the block is
114
+ a simple String containing the content of the file:
67
115
 
68
116
  it "should generate a model called 'user'" do
69
117
  subject.should generate("app/models/user.rb") { |content|
@@ -73,40 +121,40 @@ content of the file:
73
121
 
74
122
  === Checking Generation Methods
75
123
 
76
- This is the most intrusive form of generation matching, and should be avoided where possible. However, in some cases
77
- you just can't check behavior directly (migrations are a case in point, because the version number is unpredictable).
78
- In that case, you can verify that a particular method is called within the generator's manifest like so:
124
+ This is the most intrusive form of generation matching. While powerful, it will also make your tests brittle, because
125
+ there's a high likelihood that even minor changes to your generators will require you to update the spec to match.
126
+
127
+ However, sometimes you need to verify that some action occurs which can't be validated using the methods above, such
128
+ as adding a gem source to the Gemfile. You can use the generation method matcher for this.
79
129
 
80
- it "should generate a user migration template" do
81
- subject.should generate(:migration_template, "migration_template.erb", "db/migrate", :migration_file => "create_users")
130
+ it "should add a gem source" do
131
+ subject.should generate(:add_source, "http://gems.github.com")
82
132
  end
83
133
 
84
- You can stop passing arguments at any time. This has the effect of widening the range of acceptable parameters. For
85
- instance, the following example does the same thing but will accept _any_ migration file name in _any_ destination
86
- directory, as long as the "migration_template.erb" file is used for the source:
134
+ # -or-
135
+ it "should add a gem source" do
136
+ subject.should call_action(:add_source, "http://gems.github.com")
137
+ end
87
138
 
88
- it "should generate a migration template" do
89
- subject.should generate(:migration_template, "migration_template.rb")
139
+ # -or-
140
+ it "should add a gem source" do
141
+ subject.should add_source("http://gems.github.com")
90
142
  end
143
+
144
+ Note that all three of the above examples accomplish exactly the same task. Use whichever is most expressive for you.
91
145
 
92
- Any method that is normally available to Rails generators can be tested in this way:
146
+ You can stop passing arguments at any time. This has the effect of widening the range of acceptable parameters. For
147
+ instance, the following example does the same thing but will accept _any_ source URL, as long as the _add_source_
148
+ action is called:
93
149
 
94
- it "should test one of each generation type" do
95
- subject.should generate(:directory, "db/migrate")
96
- subject.should generate(:file, "input_file", "output_file")
97
- subject.should generate(:template, "input_template", "output_template")
98
- subject.should generate(:class_collisions, 'ActionController::Base')
99
- subject.should generate(:migration_template, "file", "directory", :migration_file_name => "filename")
100
- subject.should generate(:resource_routes, 'model_name')
101
- subject.should generate(:readme, "README")
150
+ it "should add a gem source" do
151
+ subject.should generate(:add_source)
102
152
  end
103
-
104
- But again... Use these as last resorts, for the most part. Technically, you will probably need this for
105
- :migration_template and :resource_routes, but anything else should really be tested for _behavior_. Like any other
106
- class, you should really only care about how the generator interacts with other objects -- in this case, your file
107
- system -- and not so much about what it's doing on the inside.
108
153
 
109
-
154
+ Any method added to Thor, the backend code that drives Rails generators, should be picked up automatically by
155
+ GenSpec.
156
+
157
+
110
158
  == Note on Patches/Pull Requests
111
159
 
112
160
  * Fork the project.
data/Rakefile CHANGED
@@ -1,18 +1,49 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ begin
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ rescue MissingSourceFile
7
+ module RSpec
8
+ module Core
9
+ class RakeTask
10
+ def initialize(name)
11
+ task name do
12
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
13
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
14
+
15
+ # ... otherwise, do this:
16
+ raise <<-MSG
17
+
18
+ #{"*" * 80}
19
+ * You are trying to run an rspec rake task defined in
20
+ * #{__FILE__},
21
+ * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
22
+ #{"*" * 80}
23
+ MSG
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def rcov_opts
32
+ IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
33
+ end
3
34
 
4
35
  begin
5
36
  require 'jeweler'
6
37
  Jeweler::Tasks.new do |gem|
7
38
  gem.name = "genspec"
8
- gem.summary = "Simple, expressive Rails generator testing for RSpec."
9
- gem.description = "Just like rspec-rails uses the structure of your spec/ directory to infer which test is being run (controllers, helpers, lib, etc.), you just need to create a spec/generators directory and put your generator specs in there."
39
+ gem.summary = "Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x."
40
+ gem.description = "Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x."
10
41
  gem.email = "sinisterchipmunk@gmail.com"
11
42
  gem.homepage = "http://www.thoughtsincomputation.com"
12
43
  gem.authors = ["Colin MacKenzie IV"]
13
44
  gem.files = FileList['**/*']
14
- gem.add_dependency "rspec"
15
- gem.add_dependency "sc-core-ext", ">= 1.2.0"
45
+ gem.add_dependency "rspec", ">= 2.0.0.beta.14" # TODO add version info when rspec isn't beta any more (it interferes with dep resolution)
46
+ gem.add_dependency "sc-core-ext", ">= 1.2.1"
16
47
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
48
  end
18
49
  Jeweler::GemcutterTasks.new
@@ -20,29 +51,45 @@ rescue LoadError
20
51
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
52
  end
22
53
 
23
- require 'rake/testtask'
24
- Rake::TestTask.new(:test) do |test|
25
- test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/test_*.rb'
27
- test.verbose = true
54
+ desc "Run all specs in spec directory"
55
+ RSpec::Core::RakeTask.new(:spec) do |t|
56
+ t.pattern = 'spec/**/*_spec.rb'
57
+ t.rcov = false
28
58
  end
29
59
 
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
60
+ desc "Spec coverage"
61
+ RSpec::Core::RakeTask.new(:rcov) do |t|
62
+ t.pattern = 'vendor/cache/genspec/spec/**/*_spec.rb'
63
+ # t.spec_opts = ['--options', 'spec/spec.opts']
64
+ t.rcov = true
65
+ t.rcov_path = 'coverage'
66
+ t.rcov_opts = rcov_opts
41
67
  end
42
68
 
43
- task :test => :check_dependencies
69
+ task :default => [:check_dependencies, :spec]
44
70
 
45
- task :default => :test
71
+ #desc "rebuilds the package and then copies the .gem file back a directory"
72
+ #task :bundle => :build do
73
+ # Dir["../cache/genspec-*.gem"].each { |f| rm File.expand_path(f) }
74
+ # Dir["pkg/*.gem"].each { |f| cp File.expand_path(f), File.expand_path('../cache') }
75
+ #end
76
+ #
77
+ #namespace :bundle do
78
+ # desc "builds and installs the gem, then runs bundle package, then uninstalls the gem"
79
+ # task :lock => [:install, :rebundle, :uninstall]
80
+ #
81
+ # desc "runs 'bundle package' in the rails project"
82
+ # task :rebundle do
83
+ # chdir File.expand_path(File.join(File.dirname(__FILE__), "../..")) do
84
+ # system("bundle package")
85
+ # end
86
+ # end
87
+ #
88
+ # desc "uninstalls the gem"
89
+ # task :uninstall do
90
+ # system("gem uninstall genspec")
91
+ # end
92
+ #end
46
93
 
47
94
  require 'rake/rdoctask'
48
95
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0.prerails3.1
data/genspec.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{genspec}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0.prerails3.1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Colin MacKenzie IV"]
12
- s.date = %q{2010-06-21}
13
- s.description = %q{Just like rspec-rails uses the structure of your spec/ directory to infer which test is being run (controllers, helpers, lib, etc.), you just need to create a spec/generators directory and put your generator specs in there.}
12
+ s.date = %q{2010-07-01}
13
+ s.description = %q{Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.}
14
14
  s.email = %q{sinisterchipmunk@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -22,62 +22,53 @@ Gem::Specification.new do |s|
22
22
  "Rakefile",
23
23
  "VERSION",
24
24
  "genspec.gemspec",
25
+ "lib/gen_spec.rb",
25
26
  "lib/genspec.rb",
26
- "lib/genspec/generation_matchers.rb",
27
- "lib/genspec/generation_matchers/generation_matcher.rb",
28
- "lib/genspec/generation_matchers/result_matcher.rb",
29
27
  "lib/genspec/generator_example_group.rb",
30
- "pkg/genspec-0.0.0.gem",
31
- "pkg/genspec-0.1.0.gem",
32
- "rdoc/classes/GenSpec.html",
33
- "rdoc/classes/GenSpec/GenerationMatchers.html",
34
- "rdoc/classes/GenSpec/GenerationMatchers/GenerationMatcher.html",
35
- "rdoc/classes/GenSpec/GenerationMatchers/ResultMatcher.html",
36
- "rdoc/classes/GenSpec/GeneratorExampleGroup.html",
37
- "rdoc/created.rid",
38
- "rdoc/files/README_rdoc.html",
39
- "rdoc/files/lib/genspec/generation_matchers/generation_matcher_rb.html",
40
- "rdoc/files/lib/genspec/generation_matchers/result_matcher_rb.html",
41
- "rdoc/files/lib/genspec/generation_matchers_rb.html",
42
- "rdoc/files/lib/genspec/generator_example_group_rb.html",
43
- "rdoc/files/lib/genspec_rb.html",
44
- "rdoc/fr_class_index.html",
45
- "rdoc/fr_file_index.html",
46
- "rdoc/fr_method_index.html",
47
- "rdoc/index.html",
48
- "rdoc/rdoc-style.css",
28
+ "lib/genspec/matchers.rb",
29
+ "lib/genspec/matchers/base.rb",
30
+ "lib/genspec/matchers/generation_method_matcher.rb",
31
+ "lib/genspec/matchers/output_matcher.rb",
32
+ "lib/genspec/matchers/result_matcher.rb",
33
+ "lib/genspec/shell.rb",
34
+ "pkg/genspec-0.1.1.gem",
35
+ "pkg/genspec-0.2.0.pre1.gem",
36
+ "pkg/genspec-0.2.0.prerails3.1.gem",
49
37
  "spec/environment_spec.rb",
50
- "spec/generators/test_spec.rb",
38
+ "spec/generators/test_rails3_spec.rb",
39
+ "spec/rcov.opts",
40
+ "spec/rspec.opts",
51
41
  "spec/spec_helper.rb",
52
- "spec/support/generators/test/templates/file",
53
- "spec/support/generators/test/test_generator.rb"
42
+ "spec/support/generators/test_rails3/USAGE",
43
+ "spec/support/generators/test_rails3/templates/file",
44
+ "spec/support/generators/test_rails3/test_rails3_generator.rb"
54
45
  ]
55
46
  s.homepage = %q{http://www.thoughtsincomputation.com}
56
47
  s.rdoc_options = ["--charset=UTF-8"]
57
48
  s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.6}
59
- s.summary = %q{Simple, expressive Rails generator testing for RSpec.}
49
+ s.rubygems_version = %q{1.3.7}
50
+ s.summary = %q{Simple, expressive Rails 3 generator testing for RSpec. For the Rails 2.3 version, use genspec 0.1.x.}
60
51
  s.test_files = [
61
52
  "spec/environment_spec.rb",
62
- "spec/generators/test_spec.rb",
53
+ "spec/generators/test_rails3_spec.rb",
63
54
  "spec/spec_helper.rb",
64
- "spec/support/generators/test/test_generator.rb"
55
+ "spec/support/generators/test_rails3/test_rails3_generator.rb"
65
56
  ]
66
57
 
67
58
  if s.respond_to? :specification_version then
68
59
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
60
  s.specification_version = 3
70
61
 
71
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
72
- s.add_runtime_dependency(%q<rspec>, [">= 0"])
73
- s.add_runtime_dependency(%q<sc-core-ext>, [">= 1.2.0"])
62
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.14"])
64
+ s.add_runtime_dependency(%q<sc-core-ext>, [">= 1.2.1"])
74
65
  else
75
- s.add_dependency(%q<rspec>, [">= 0"])
76
- s.add_dependency(%q<sc-core-ext>, [">= 1.2.0"])
66
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.14"])
67
+ s.add_dependency(%q<sc-core-ext>, [">= 1.2.1"])
77
68
  end
78
69
  else
79
- s.add_dependency(%q<rspec>, [">= 0"])
80
- s.add_dependency(%q<sc-core-ext>, [">= 1.2.0"])
70
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.14"])
71
+ s.add_dependency(%q<sc-core-ext>, [">= 1.2.1"])
81
72
  end
82
73
  end
83
74
 
data/lib/gen_spec.rb ADDED
@@ -0,0 +1 @@
1
+ require 'genspec'
data/lib/genspec.rb CHANGED
@@ -1,14 +1,29 @@
1
- require 'spec'
1
+ if defined?(RAILS_ROOT)
2
+ if Rails::VERSION::MAJOR == 2
3
+ raise "Use genspec 0.1.0 for Rails 2; this version is for Rails 3."
4
+ elsif Rails::VERSION::MAJOR == 3
5
+ require 'rails/generators'
6
+ else
7
+ raise "Unsupported Rails version: #{Rails::VERSION::STRING}"
8
+ end
9
+ end
10
+
11
+ begin
12
+ require 'rspec/core'
13
+ rescue LoadError
14
+ raise "GenSpec requires RSpec v2.0."
15
+ end
16
+
2
17
  require 'fileutils'
3
18
 
4
19
  require 'sc-core-ext'
5
-
6
- require 'genspec/generation_matchers'
20
+ require 'genspec/shell'
21
+ require 'genspec/matchers'
7
22
  require 'genspec/generator_example_group'
8
23
 
9
- if defined?(RAILS_ROOT)
10
- require 'rails_generator'
11
- require 'rails_generator/scripts/generate'
12
- end
24
+ Thor::Base.shell = GenSpec::Shell.new
13
25
 
14
- Spec::Example::ExampleGroupFactory.register(:generator, GenSpec::GeneratorExampleGroup)
26
+ # RSpec 2.0 compat
27
+ RSpec.configure do |config|
28
+ config.include GenSpec::GeneratorExampleGroup, :example_group => { :file_path => /spec[\/]generators/ }
29
+ end
@@ -1,71 +1,66 @@
1
1
  module GenSpec
2
- class GeneratorExampleGroup
3
- extend Spec::Example::ExampleGroupMethods
4
- include Spec::Example::ExampleMethods
5
- include GenSpec::GenerationMatchers
6
- delegate :generator_arguments, :generator_options, :generator_args, :to => "self.class"
7
-
8
- class << self
9
- def generator_arguments
10
- @generator_args.dup? || []
11
- end
12
-
13
- def generator_options
14
- @generator_options.dup? || {}
15
- end
16
-
17
- def with_arguments(*args, &block)
2
+ module GeneratorExampleGroup
3
+ include RSpec::Matchers
4
+ include GenSpec::Matchers
5
+
6
+ def self.included(base)
7
+ base.send(:extend, GenSpec::GeneratorExampleGroup::ClassMethods)
8
+ base.send(:subject) { self.class.generator_descriptor }
9
+ end
10
+
11
+ module ClassMethods
12
+ # Sets the list of arguments for this generator.
13
+ #
14
+ # * All arguments will be converted to Strings, because that's how
15
+ # they'd enter the generator from a command line. To avoid this,
16
+ # pass :object => true at the end;
17
+ #
18
+ # Ex:
19
+ #
20
+ def with_args(*args, &block)
21
+ options = args.extract_options!
22
+ args = args.flatten.collect { |c| c.to_s } unless options[:object]
18
23
  if block_given?
19
24
  context "with arguments #{args.inspect}" do
20
- with_arguments(*args)
25
+ with_args(args, options)
21
26
  instance_eval(&block)
22
27
  end
23
28
  else
24
- @generator_args = args.flatten.collect { |c| c.to_s }
29
+ metadata[:generator_args] = args
25
30
  end
26
31
  end
27
32
 
28
- def with_options(hash, &block)
29
- if block_given?
30
- context "with options #{hash.inspect}" do
31
- with_options(hash)
32
- instance_eval(&block)
33
- end
33
+ def generator_args
34
+ return metadata[:generator_args] if metadata[:generator_args]
35
+
36
+ metadata[:generator_args] = if genspec_subclass?
37
+ superclass.generator_args
34
38
  else
35
- @generator_options = hash
39
+ []
36
40
  end
37
41
  end
38
42
 
39
- alias_method :generator_args, :generator_arguments
40
- alias_method :with_args, :with_arguments
41
- end
42
-
43
- def subject(&block)
44
- block.nil? ?
45
- explicit_subject || implicit_subject : @explicit_subject_block = block
46
- end
47
-
48
- private
49
- def explicit_subject
50
- group = self
51
- while group.respond_to?(:explicit_subject_block)
52
- return group.explicit_subject_block if group.explicit_subject_block
53
- group = group.superclass
54
- end
55
- end
56
-
57
- def implicit_subject
58
- target = example_group_hierarchy[1].described_class || example_group_hierarchy[1].description_args.first
43
+ alias with_arguments with_args
44
+ alias generator_arguments generator_args
59
45
 
60
- if target.kind_of?(Symbol) || target.kind_of?(String)
61
- target = self.class.lookup_missing_generator("#{target.to_s.underscore}_generator".camelize)
46
+ def generator_descriptor
47
+ {
48
+ :described => target_generator,
49
+ :args => generator_args
50
+ }
62
51
  end
63
- target.new(generator_args, generator_options)
64
- rescue Rails::Generator::GeneratorError, Rails::Generator::UsageError
65
- # let them pass, so the user can test the output.
66
- # TODO: Make this disable-able via configuration.
67
52
 
68
- $! # return this because it is the content we'll check against.
53
+ def target_generator
54
+ if genspec_subclass?
55
+ superclass.target_generator
56
+ else
57
+ describes || description
58
+ end
59
+ end
60
+
61
+ def genspec_subclass?
62
+ superclass.include?(GenSpec::GeneratorExampleGroup)
63
+ end
69
64
  end
70
65
  end
71
66
  end