Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bug where namespaced generators were falling down

  • Loading branch information...
commit 1b1c181a1cebbf9e9a2f2bc3f247162bfe9a1f64 1 parent 3ba3a49
@dchelimsky dchelimsky authored
View
11 lib/generators/rspec/scaffold/scaffold_generator.rb
@@ -67,16 +67,19 @@ def params
# support for namespaced-resources
def ns_file_name
- ns_given? ? "#{$1.underscore}_#{$2.singularize.underscore}" : file_name
+ ns_parts.empty? ? file_name : "#{ns_parts[0].underscore}_#{ns_parts[1].singularize.underscore}"
end
# support for namespaced-resources
def ns_table_name
- ns_given? ? "#{$1.underscore}/#{$2.tableize}" : table_name
+ ns_parts.empty? ? table_name : "#{ns_parts[0].underscore}/#{ns_parts[1].tableize}"
end
- def ns_given?
- ARGV.any? && ARGV[0].match(/\A(\w+)\/(\w+)/)
+ def ns_parts
+ @ns_parts ||= begin
+ matches = ARGV[0].to_s.match(/\A(\w+)\/(\w+)/)
+ matches ? [matches[1], matches[2]] : []
+ end
end
# Returns the name of the mock. For example, if the file name is user,
View
74 spec/generators/rspec/scaffold/scaffold_generator_spec.rb
@@ -1,40 +1,36 @@
require 'spec_helper'
-# Generators are not automatically loaded by Rails
require 'generators/rspec/scaffold/scaffold_generator'
describe Rspec::Generators::ScaffoldGenerator do
- # Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)
before { prepare_destination }
- describe 'controller specs' do
+ describe 'standard controller spec' do
subject { file('spec/controllers/posts_controller_spec.rb') }
- describe 'generated by default' do
- before do
- run_generator %w(posts)
- end
- describe 'the spec' do
- it { should exist }
- it { should contain /require 'spec_helper'/ }
- it { should contain /describe PostsController/ }
- end
+ describe 'with no options' do
+ before { run_generator %w(posts) }
+ it { should contain /require 'spec_helper'/ }
+ it { should contain /describe PostsController/ }
end
- describe 'skipped with a flag' do
- before do
- run_generator %w(posts --no-controller_specs)
- end
+
+ describe 'with --no-controller_specs' do
+ before { run_generator %w(posts --no-controller_specs) }
it { should_not exist }
end
end
+ describe 'namespaced controller spec' do
+ subject { file('spec/controllers/admin/posts_controller_spec.rb') }
+ before { run_generator %w(admin/posts) }
+ it { should contain /describe Admin::PostsController/ }
+ end
+
describe 'view specs' do
- describe 'generated by default' do
- before do
- run_generator %w(posts)
- end
+ describe 'with no options' do
+ before { run_generator %w(posts) }
describe 'edit' do
subject { file("spec/views/posts/edit.html.erb_spec.rb") }
it { should exist }
@@ -42,6 +38,7 @@
it { should contain /describe "(.*)\/edit.html.erb"/ }
it { should contain /it "renders the edit (.*) form"/ }
end
+
describe 'index' do
subject { file("spec/views/posts/index.html.erb_spec.rb") }
it { should exist }
@@ -49,6 +46,7 @@
it { should contain /describe "(.*)\/index.html.erb"/ }
it { should contain /it "renders a list of (.*)"/ }
end
+
describe 'new' do
subject { file("spec/views/posts/new.html.erb_spec.rb") }
it { should exist }
@@ -56,6 +54,7 @@
it { should contain /describe "(.*)\/new.html.erb"/ }
it { should contain /it "renders new (.*) form"/ }
end
+
describe 'show' do
subject { file("spec/views/posts/show.html.erb_spec.rb") }
it { should exist }
@@ -65,22 +64,24 @@
end
end
- describe 'skipped with a flag' do
- before do
- run_generator %w(posts --no-view-specs)
- end
+ describe 'with --no-view-specs' do
+ before { run_generator %w(posts --no-view-specs) }
+
describe 'edit' do
subject { file("spec/views/posts/edit.html.erb_spec.rb") }
it { should_not exist }
end
+
describe 'index' do
subject { file("spec/views/posts/index.html.erb_spec.rb") }
it { should_not exist }
end
+
describe 'new' do
subject { file("spec/views/posts/new.html.erb_spec.rb") }
it { should_not exist }
end
+
describe 'show' do
subject { file("spec/views/posts/show.html.erb_spec.rb") }
it { should_not exist }
@@ -88,26 +89,19 @@
end
end
- describe 'routing specs' do
+ describe 'routing spec' do
subject { file('spec/routing/posts_routing_spec.rb') }
- describe 'generated by default' do
- before do
- run_generator %w(posts)
- end
- describe 'the spec' do
- it { should exist }
- it { should contain /require "spec_helper"/ }
- it { should contain /describe PostsController/ }
- it { should contain /describe "routing"/ }
- end
+ describe 'with default options' do
+ before { run_generator %w(posts) }
+ it { should contain /require "spec_helper"/ }
+ it { should contain /describe PostsController/ }
+ it { should contain /describe "routing"/ }
end
- describe 'skipped with a flag' do
- before do
- run_generator %w(posts --no-routing_specs)
- end
+
+ describe 'with --no-routing-specs' do
+ before { run_generator %w(posts --no-routing_specs) }
it { should_not exist }
end
end
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.