mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Put dev dependencies in generated plugin Gemfile
The Gemfile offers more flexibility than the gemspec in terms of gem groups and platforms. Putting the default development dependencies in the Gemfile encourages users to add their own development dependencies to the Gemfile. This is similar to the current behavior of the `bundle gem` command (see bundler/bundler#7222). This change also fixes a corner case where using the "--skip-gemspec" and "--skip-active-record" options together would incorrectly generate a "sqlite3" dependency in the Gemfile.
This commit is contained in:
parent
de853a296f
commit
5fbf14b92f
3 changed files with 26 additions and 31 deletions
|
@ -21,8 +21,4 @@ Gem::Specification.new do |spec|
|
|||
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
||||
|
||||
<%= '# ' if options.dev? || options.edge? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
|
||||
<% unless options[:skip_active_record] -%>
|
||||
|
||||
spec.add_development_dependency "<%= gem_for_database[0] %>"
|
||||
<% end -%>
|
||||
end
|
||||
|
|
|
@ -4,21 +4,14 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|||
<% if options[:skip_gemspec] -%>
|
||||
<%= '# ' if options.dev? || options.edge? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
|
||||
<% else -%>
|
||||
# Declare your gem's dependencies in <%= name %>.gemspec.
|
||||
# Bundler will treat runtime dependencies like base dependencies, and
|
||||
# development dependencies will be added by default to the :development group.
|
||||
# Specify your gem's dependencies in <%= name %>.gemspec.
|
||||
gemspec
|
||||
<% end -%>
|
||||
<% unless options[:skip_active_record] -%>
|
||||
|
||||
<% if options[:skip_gemspec] -%>
|
||||
group :development do
|
||||
gem '<%= gem_for_database[0] %>'
|
||||
end
|
||||
<% else -%>
|
||||
# Declare any dependencies that are still in development here instead of in
|
||||
# your gemspec. These might include edge Rails or gems from your path or
|
||||
# Git. Remember to move these dependencies to your gemspec before releasing
|
||||
# your gem to rubygems.org.
|
||||
<% end -%>
|
||||
|
||||
<% if options.dev? || options.edge? -%>
|
||||
|
|
|
@ -154,23 +154,31 @@ class PluginGeneratorTest < Rails::Generators::TestCase
|
|||
assert_no_directory "test"
|
||||
end
|
||||
|
||||
def test_database_entry_is_generated_for_sqlite3_by_default_in_full_mode
|
||||
run_generator([destination_root, "--full"])
|
||||
assert_file "test/dummy/config/database.yml", /sqlite/
|
||||
assert_file "bukkits.gemspec", /sqlite3/
|
||||
end
|
||||
|
||||
def test_config_another_database
|
||||
run_generator([destination_root, "-d", "mysql", "--full"])
|
||||
assert_file "test/dummy/config/database.yml", /mysql/
|
||||
assert_file "bukkits.gemspec", /mysql/
|
||||
end
|
||||
|
||||
def test_dont_generate_development_dependency
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
|
||||
def test_no_development_dependencies_in_gemspec
|
||||
run_generator
|
||||
assert_file "bukkits.gemspec" do |contents|
|
||||
assert_no_match(/s\.add_development_dependency "sqlite3"/, contents)
|
||||
assert_no_match(/add_development_dependency/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
def test_default_database_dependency_is_sqlite
|
||||
run_generator
|
||||
assert_file "test/dummy/config/database.yml", /sqlite/
|
||||
assert_file "Gemfile" do |contents|
|
||||
assert_match_sqlite3(contents)
|
||||
end
|
||||
end
|
||||
|
||||
def test_custom_database_dependency
|
||||
run_generator [destination_root, "-d", "mysql"]
|
||||
assert_file "test/dummy/config/database.yml", /mysql/
|
||||
assert_file "Gemfile", /mysql/
|
||||
end
|
||||
|
||||
def test_skip_database_dependency
|
||||
run_generator [destination_root, "--skip-active-record"]
|
||||
assert_file "Gemfile" do |contents|
|
||||
assert_no_match(/sqlite/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -495,7 +503,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "Gemfile" do |contents|
|
||||
assert_no_match("gemspec", contents)
|
||||
assert_match(/gem 'rails'/, contents)
|
||||
assert_match_sqlite3(contents)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -505,7 +512,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "Gemfile" do |contents|
|
||||
assert_no_match("gemspec", contents)
|
||||
assert_match(/gem 'rails'/, contents)
|
||||
assert_match_sqlite3(contents)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue