Skip to content

Commit

Permalink
fix bug where namespaced generators were falling down
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 1, 2011
1 parent 3ba3a49 commit 1b1c181
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
11 changes: 7 additions & 4 deletions lib/generators/rspec/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
74 changes: 34 additions & 40 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
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 }
it { should contain /require 'spec_helper'/ }
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 }
it { should contain /require 'spec_helper'/ }
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 }
it { should contain /require 'spec_helper'/ }
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 }
Expand All @@ -65,49 +64,44 @@
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 }
end
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

0 comments on commit 1b1c181

Please sign in to comment.