aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md23
-rw-r--r--railties/Rakefile29
-rw-r--r--railties/lib/rails/application/configuration.rb75
-rw-r--r--railties/lib/rails/application/default_middleware_stack.rb2
-rw-r--r--railties/lib/rails/command.rb70
-rw-r--r--railties/lib/rails/commands.rb5
-rw-r--r--railties/lib/rails/commands/commands_tasks.rb23
-rw-r--r--railties/lib/rails/commands/dbconsole.rb2
-rw-r--r--railties/lib/rails/commands/dev_cache.rb21
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb1
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt1
-rw-r--r--railties/lib/rails/tasks.rb1
-rw-r--r--railties/lib/rails/tasks/dev.rake14
-rw-r--r--railties/lib/rails/test_unit/minitest_plugin.rb4
-rw-r--r--railties/lib/rails/test_unit/reporter.rb6
-rw-r--r--railties/test/application/configuration_test.rb40
-rw-r--r--railties/test/application/loading_test.rb2
-rw-r--r--railties/test/application/rake/dbs_test.rb8
-rw-r--r--railties/test/application/rake/dev_test.rb35
-rw-r--r--railties/test/commands/dev_cache_test.rb32
-rw-r--r--railties/test/generators/api_app_generator_test.rb1
-rw-r--r--railties/test/generators/plugin_generator_test.rb4
-rw-r--r--railties/test/generators/plugin_test_helper.rb24
-rw-r--r--railties/test/generators/plugin_test_runner_test.rb27
-rw-r--r--railties/test/generators/test_runner_in_engine_test.rb31
25 files changed, 316 insertions, 165 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index d20ec75b61..e5ab31005e 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,26 @@
+* `config.debug_exception_response_format` configures the format used
+ in responses when errors occur in development mode.
+
+ Set `config.debug_exception_response_format` to render an HTML page with
+ debug info (using the value `:default`) or render debug info preserving
+ the response format (using the value `:api`).
+
+ *Jorge Bejar*
+
+* Fix setting exit status code for rake test tasks. The exit status code
+ was not set when tests were fired with `rake`. Now, it is being set and it matches
+ behavior of running tests via `rails` command (`rails test`), so no matter if
+ `rake test` or `rails test` command is used the exit code will be set.
+
+ *Arkadiusz Fal*
+
+* Add Command infrastructure to replace rake.
+
+ Also move `rake dev:cache` to new infrastructure. You'll need to use
+ `rails dev:cache` to toggle development caching from now on.
+
+ *Chuck Callebs*
+
* Allow use of minitest-rails gem with Rails test runner.
Fixes #22455.
diff --git a/railties/Rakefile b/railties/Rakefile
index 73d881b318..cf130a5f14 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -5,33 +5,20 @@ task :default => :test
desc "Run all unit tests"
task :test => 'test:isolated'
-dash_i = [
- 'test',
- 'lib',
- "#{File.dirname(__FILE__)}/../activesupport/lib",
- "#{File.dirname(__FILE__)}/../actionpack/lib",
- "#{File.dirname(__FILE__)}/../activemodel/lib"
-]
-
-dash_i.reverse_each do |x|
- $:.unshift x unless $:.include? x
-end
-$-w = true
-
-require 'bundler/setup' unless defined?(Bundler)
-require 'active_support'
-
namespace :test do
task :isolated do
dirs = (ENV["TEST_DIR"] || ENV["TEST_DIRS"] || "**").split(",")
test_files = dirs.map { |dir| "test/#{dir}/*_test.rb" }
Dir[*test_files].each do |file|
next true if file.include?("fixtures")
- puts "#{FileUtils::RUBY} -w -I#{dash_i.join ':'} #{file}"
-
- # We could run these in parallel, but pretty much all of the
- # railties tests already run in parallel, so ¯\_(⊙︿⊙)_/¯
- Process.waitpid fork { ARGV.clear; load file }
+ dash_i = [
+ 'test',
+ 'lib',
+ "#{File.dirname(__FILE__)}/../activesupport/lib",
+ "#{File.dirname(__FILE__)}/../actionpack/lib",
+ "#{File.dirname(__FILE__)}/../activemodel/lib"
+ ]
+ ruby "-w", "-I#{dash_i.join ':'}", file
end
end
end
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 80733c2d90..a5550df0de 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -24,35 +24,36 @@ module Rails
def initialize(*)
super
self.encoding = "utf-8"
- @allow_concurrency = nil
- @consider_all_requests_local = false
- @filter_parameters = []
- @filter_redirect = []
- @helpers_paths = []
- @public_file_server = ActiveSupport::OrderedOptions.new
- @public_file_server.enabled = true
- @public_file_server.index_name = "index"
- @force_ssl = false
- @ssl_options = {}
- @session_store = :cookie_store
- @session_options = {}
- @time_zone = "UTC"
- @beginning_of_week = :monday
- @log_level = nil
- @generators = app_generators
- @cache_store = [ :file_store, "#{root}/tmp/cache/" ]
- @railties_order = [:all]
- @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
- @reload_classes_only_on_change = true
- @file_watcher = file_update_checker
- @exceptions_app = nil
- @autoflush_log = true
- @log_formatter = ActiveSupport::Logger::SimpleFormatter.new
- @eager_load = nil
- @secret_token = nil
- @secret_key_base = nil
- @api_only = false
- @x = Custom.new
+ @allow_concurrency = nil
+ @consider_all_requests_local = false
+ @filter_parameters = []
+ @filter_redirect = []
+ @helpers_paths = []
+ @public_file_server = ActiveSupport::OrderedOptions.new
+ @public_file_server.enabled = true
+ @public_file_server.index_name = "index"
+ @force_ssl = false
+ @ssl_options = {}
+ @session_store = :cookie_store
+ @session_options = {}
+ @time_zone = "UTC"
+ @beginning_of_week = :monday
+ @log_level = nil
+ @generators = app_generators
+ @cache_store = [ :file_store, "#{root}/tmp/cache/" ]
+ @railties_order = [:all]
+ @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
+ @reload_classes_only_on_change = true
+ @file_watcher = file_update_checker
+ @exceptions_app = nil
+ @autoflush_log = true
+ @log_formatter = ActiveSupport::Logger::SimpleFormatter.new
+ @eager_load = nil
+ @secret_token = nil
+ @secret_key_base = nil
+ @api_only = false
+ @debug_exception_response_format = nil
+ @x = Custom.new
end
def static_cache_control=(value)
@@ -95,6 +96,16 @@ module Rails
def api_only=(value)
@api_only = value
generators.api_only = value
+
+ @debug_exception_response_format ||= :api
+ end
+
+ def debug_exception_response_format
+ @debug_exception_response_format || :default
+ end
+
+ def debug_exception_response_format=(value)
+ @debug_exception_response_format = value
end
def paths
@@ -182,11 +193,7 @@ module Rails
private
def file_update_checker
- if defined?(Listen) && Listen::Adapter.select() != Listen::Adapter::Polling
- ActiveSupport::FileEventedUpdateChecker
- else
- ActiveSupport::FileUpdateChecker
- end
+ ActiveSupport::FileUpdateChecker
end
class Custom #:nodoc:
diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb
index 5cb5bfb8b7..ed6a1f82d3 100644
--- a/railties/lib/rails/application/default_middleware_stack.rb
+++ b/railties/lib/rails/application/default_middleware_stack.rb
@@ -57,7 +57,7 @@ module Rails
# Must come after Rack::MethodOverride to properly log overridden methods
middleware.use ::Rails::Rack::Logger, config.log_tags
middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app
- middleware.use ::ActionDispatch::DebugExceptions, app
+ middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
unless config.cache_classes
diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb
new file mode 100644
index 0000000000..6587984b53
--- /dev/null
+++ b/railties/lib/rails/command.rb
@@ -0,0 +1,70 @@
+require 'rails/commands/commands_tasks'
+
+module Rails
+ class Command
+ attr_reader :argv
+
+ def initialize(argv = [])
+ @argv = argv
+
+ @option_parser = build_option_parser
+ @options = {}
+ end
+
+ def self.run(task_name, argv)
+ command_name = command_name_for(task_name)
+
+ if command = command_for(command_name)
+ command.new(argv).run(command_name)
+ else
+ Rails::CommandsTasks.new(argv).run_command!(task_name)
+ end
+ end
+
+ def run(command_name)
+ parse_options_for(command_name)
+ @option_parser.parse! @argv
+
+ public_send(command_name)
+ end
+
+ def self.options_for(command_name, &options_to_parse)
+ @@command_options[command_name] = options_to_parse
+ end
+
+ def self.set_banner(command_name, banner)
+ options_for(command_name) { |opts, _| opts.banner = banner }
+ end
+
+ private
+ @@commands = []
+ @@command_options = {}
+
+ def parse_options_for(command_name)
+ @@command_options.fetch(command_name, proc {}).call(@option_parser, @options)
+ end
+
+ def build_option_parser
+ OptionParser.new do |opts|
+ opts.on('-h', '--help', 'Show this help.') do
+ puts opts
+ exit
+ end
+ end
+ end
+
+ def self.inherited(command)
+ @@commands << command
+ end
+
+ def self.command_name_for(task_name)
+ task_name.gsub(':', '_').to_sym
+ end
+
+ def self.command_for(command_name)
+ @@commands.find do |command|
+ command.public_instance_methods.include?(command_name)
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 12bd73db24..b9c4e02ca0 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -13,6 +13,7 @@ aliases = {
command = ARGV.shift
command = aliases[command] || command
-require 'rails/commands/commands_tasks'
+require 'rails/command'
+require 'rails/commands/dev_cache'
-Rails::CommandsTasks.new(ARGV).run_command!(command)
+Rails::Command.run(command, ARGV)
diff --git a/railties/lib/rails/commands/commands_tasks.rb b/railties/lib/rails/commands/commands_tasks.rb
index 685d55eea8..7e6b49e2a3 100644
--- a/railties/lib/rails/commands/commands_tasks.rb
+++ b/railties/lib/rails/commands/commands_tasks.rb
@@ -36,10 +36,9 @@ EOT
def run_command!(command)
command = parse_command(command)
+
if COMMAND_WHITELIST.include?(command)
send(command)
- else
- write_error_message(command)
end
end
@@ -151,26 +150,6 @@ EOT
puts HELP_MESSAGE
end
- # Output an error message stating that the attempted command is not a valid rails command.
- # Run the attempted command as a rake command with the --dry-run flag. If successful, suggest
- # to the user that they possibly meant to run the given rails command as a rake command.
- # Append the help message.
- #
- # Example:
- # $ rails db:migrate
- # Error: Command 'db:migrate' not recognized
- # Did you mean: `$ rake db:migrate` ?
- # (Help message output)
- #
- def write_error_message(command)
- puts "Error: Command '#{command}' not recognized"
- if %x{rake #{command} --dry-run 2>&1 } && $?.success?
- puts "Did you mean: `$ rake #{command}` ?\n\n"
- end
- write_help_message
- exit(1)
- end
-
def parse_command(command)
case command
when '--version', '-v'
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index dca60f948f..2c36edfa3f 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -65,7 +65,7 @@ module Rails
'sslca' => '--ssl-ca',
'sslcert' => '--ssl-cert',
'sslcapath' => '--ssl-capath',
- 'sslcipher' => '--ssh-cipher',
+ 'sslcipher' => '--ssl-cipher',
'sslkey' => '--ssl-key'
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
diff --git a/railties/lib/rails/commands/dev_cache.rb b/railties/lib/rails/commands/dev_cache.rb
new file mode 100644
index 0000000000..ec96e8f630
--- /dev/null
+++ b/railties/lib/rails/commands/dev_cache.rb
@@ -0,0 +1,21 @@
+require 'rails/command'
+
+module Rails
+ module Commands
+ # This is a wrapper around the Rails dev:cache command
+ class DevCache < Command
+ set_banner :dev_cache, 'Toggle development mode caching on/off'
+ def dev_cache
+ if File.exist? 'tmp/caching-dev.txt'
+ File.delete 'tmp/caching-dev.txt'
+ puts 'Development mode is no longer being cached.'
+ else
+ FileUtils.touch 'tmp/caching-dev.txt'
+ puts 'Development mode is now being cached.'
+ end
+
+ FileUtils.touch 'tmp/restart.txt'
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index b813b083f4..889154494d 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -303,6 +303,7 @@ module Rails
if options[:api]
remove_file 'config/initializers/session_store.rb'
remove_file 'config/initializers/cookies_serializer.rb'
+ remove_file 'config/initializers/request_forgery_protection.rb'
end
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 4dd20a9d2e..2778dd8247 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -23,7 +23,6 @@ Rails.application.configure do
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
-
<%- unless options.skip_action_mailer? -%>
# Don't care if the mailer can't send.
diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb
index d3e33584d7..d60eaf6f4f 100644
--- a/railties/lib/rails/tasks.rb
+++ b/railties/lib/rails/tasks.rb
@@ -3,7 +3,6 @@ require 'rake'
# Load Rails Rakefile extensions
%w(
annotations
- dev
framework
initializers
log
diff --git a/railties/lib/rails/tasks/dev.rake b/railties/lib/rails/tasks/dev.rake
deleted file mode 100644
index 4593100465..0000000000
--- a/railties/lib/rails/tasks/dev.rake
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace :dev do
- desc 'Toggle development mode caching on/off'
- task :cache do
- if File.exist? 'tmp/caching-dev.txt'
- File.delete 'tmp/caching-dev.txt'
- puts 'Development mode is no longer being cached.'
- else
- FileUtils.touch 'tmp/caching-dev.txt'
- puts 'Development mode is now being cached.'
- end
-
- FileUtils.touch 'tmp/restart.txt'
- end
-end
diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb
index 4e1fb13009..d39d2f32bf 100644
--- a/railties/lib/rails/test_unit/minitest_plugin.rb
+++ b/railties/lib/rails/test_unit/minitest_plugin.rb
@@ -57,7 +57,9 @@ module Minitest
# as the patterns would also contain the other Rake tasks.
def self.rake_run(patterns) # :nodoc:
@rake_patterns = patterns
- run
+ passed = run
+ exit passed unless passed
+ passed
end
def self.plugin_rails_init(options)
diff --git a/railties/lib/rails/test_unit/reporter.rb b/railties/lib/rails/test_unit/reporter.rb
index de4b002e55..00ea32d1b8 100644
--- a/railties/lib/rails/test_unit/reporter.rb
+++ b/railties/lib/rails/test_unit/reporter.rb
@@ -44,7 +44,7 @@ module Rails
end
def relative_path_for(file)
- file.sub(/^#{Rails.root}\/?/, '')
+ file.sub(/^#{app_root}\/?/, '')
end
private
@@ -66,5 +66,9 @@ module Rails
"#{self.executable} #{relative_path_for(assertion_path)}"
end
+
+ def app_root
+ @app_root ||= defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
+ end
end
end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 5f3d1879eb..49f63d5d31 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -1393,5 +1393,45 @@ module ApplicationTests
assert_equal 'unicorn', Rails.application.config.my_custom_config['key']
end
+
+ test "api_only is false by default" do
+ app 'development'
+ refute Rails.application.config.api_only
+ end
+
+ test "api_only generator config is set when api_only is set" do
+ add_to_config <<-RUBY
+ config.api_only = true
+ RUBY
+ app 'development'
+
+ Rails.application.load_generators
+ assert Rails.configuration.api_only
+ end
+
+ test "debug_exception_response_format is :api by default if only_api is enabled" do
+ add_to_config <<-RUBY
+ config.api_only = true
+ RUBY
+ app 'development'
+
+ assert_equal :api, Rails.configuration.debug_exception_response_format
+ end
+
+ test "debug_exception_response_format can be override" do
+ add_to_config <<-RUBY
+ config.api_only = true
+ RUBY
+
+ app_file 'config/environments/development.rb', <<-RUBY
+ Rails.application.configure do
+ config.debug_exception_response_format = :default
+ end
+ RUBY
+
+ app 'development'
+
+ assert_equal :default, Rails.configuration.debug_exception_response_format
+ end
end
end
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index 1027bca2c1..2106708c98 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -169,6 +169,8 @@ class LoadingTest < ActiveSupport::TestCase
config.file_watcher = Class.new do
def initialize(*); end
def updated?; false; end
+ def execute; end
+ def execute_if_updated; false; end
end
RUBY
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index f94d08673a..0b0fb50fe1 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -61,7 +61,7 @@ module ApplicationTests
test 'db:create failure because database exists' do
with_database_existing do
output = `bin/rake db:create 2>&1`
- assert_match /already exists/, output
+ assert_match(/already exists/, output)
assert_equal 0, $?.exitstatus
end
end
@@ -78,7 +78,7 @@ module ApplicationTests
test 'db:create failure because bad permissions' do
with_bad_permissions do
output = `bin/rake db:create 2>&1`
- assert_match /Couldn't create database/, output
+ assert_match(/Couldn't create database/, output)
assert_equal 1, $?.exitstatus
end
end
@@ -86,7 +86,7 @@ module ApplicationTests
test 'db:drop failure because database does not exist' do
Dir.chdir(app_path) do
output = `bin/rake db:drop 2>&1`
- assert_match /does not exist/, output
+ assert_match(/does not exist/, output)
assert_equal 0, $?.exitstatus
end
end
@@ -95,7 +95,7 @@ module ApplicationTests
with_database_existing do
with_bad_permissions do
output = `bin/rake db:drop 2>&1`
- assert_match /Couldn't drop/, output
+ assert_match(/Couldn't drop/, output)
assert_equal 1, $?.exitstatus
end
end
diff --git a/railties/test/application/rake/dev_test.rb b/railties/test/application/rake/dev_test.rb
deleted file mode 100644
index 28d8b22a37..0000000000
--- a/railties/test/application/rake/dev_test.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require 'isolation/abstract_unit'
-
-module ApplicationTests
- module RakeTests
- class RakeDevTest < ActiveSupport::TestCase
- include ActiveSupport::Testing::Isolation
-
- def setup
- build_app
- boot_rails
- end
-
- def teardown
- teardown_app
- end
-
- test 'dev:cache creates file and outputs message' do
- Dir.chdir(app_path) do
- output = `rake dev:cache`
- assert File.exist?('tmp/caching-dev.txt')
- assert_match(/Development mode is now being cached/, output)
- end
- end
-
- test 'dev:cache deletes file and outputs message' do
- Dir.chdir(app_path) do
- output = `rake dev:cache`
- output = `rake dev:cache`
- assert_not File.exist?('tmp/caching-dev.txt')
- assert_match(/Development mode is no longer being cached/, output)
- end
- end
- end
- end
-end
diff --git a/railties/test/commands/dev_cache_test.rb b/railties/test/commands/dev_cache_test.rb
new file mode 100644
index 0000000000..1b7a72e7fc
--- /dev/null
+++ b/railties/test/commands/dev_cache_test.rb
@@ -0,0 +1,32 @@
+require_relative '../isolation/abstract_unit'
+
+module CommandsTests
+ class DevCacheTest < ActiveSupport::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ end
+
+ def teardown
+ teardown_app
+ end
+
+ test 'dev:cache creates file and outputs message' do
+ Dir.chdir(app_path) do
+ output = `rails dev:cache`
+ assert File.exist?('tmp/caching-dev.txt')
+ assert_match(%r{Development mode is now being cached}, output)
+ end
+ end
+
+ test 'dev:cache deletes file and outputs message' do
+ Dir.chdir(app_path) do
+ `rails dev:cache` # Create caching file.
+ output = `rails dev:cache` # Delete caching file.
+ assert_not File.exist?('tmp/caching-dev.txt')
+ assert_match(%r{Development mode is no longer being cached}, output)
+ end
+ end
+ end
+end
diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb
index 998da3ef84..be2cd3a853 100644
--- a/railties/test/generators/api_app_generator_test.rb
+++ b/railties/test/generators/api_app_generator_test.rb
@@ -89,6 +89,7 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
config/initializers/assets.rb
config/initializers/cookies_serializer.rb
config/initializers/session_store.rb
+ config/initializers/request_forgery_protection.rb
lib/assets
vendor/assets
test/helpers
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 67c744b529..60390cfa01 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -387,7 +387,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
run_generator
assert_file "bukkits.gemspec", /s.name\s+= "bukkits"/
assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,db,lib\}\/\*\*\/\*", "MIT-LICENSE", "Rakefile", "README\.rdoc"\]/
- assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/
assert_file "bukkits.gemspec", /s.version\s+ = Bukkits::VERSION/
end
@@ -461,9 +460,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
def test_skipping_test_files
run_generator [destination_root, "--skip-test"]
assert_no_file "test"
- assert_file "bukkits.gemspec" do |contents|
- assert_no_match(/s.test_files = Dir\["test\/\*\*\/\*"\]/, contents)
- end
assert_file '.gitignore' do |contents|
assert_no_match(/test\dummy/, contents)
end
diff --git a/railties/test/generators/plugin_test_helper.rb b/railties/test/generators/plugin_test_helper.rb
new file mode 100644
index 0000000000..96c1b1d31f
--- /dev/null
+++ b/railties/test/generators/plugin_test_helper.rb
@@ -0,0 +1,24 @@
+require 'abstract_unit'
+require 'tmpdir'
+
+module PluginTestHelper
+ def create_test_file(name, pass: true)
+ plugin_file "test/#{name}_test.rb", <<-RUBY
+ require 'test_helper'
+
+ class #{name.camelize}Test < ActiveSupport::TestCase
+ def test_truth
+ puts "#{name.camelize}Test"
+ assert #{pass}, 'wups!'
+ end
+ end
+ RUBY
+ end
+
+ def plugin_file(path, contents, mode: 'w')
+ FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}")
+ File.open("#{plugin_path}/#{path}", mode) do |f|
+ f.puts contents
+ end
+ end
+end
diff --git a/railties/test/generators/plugin_test_runner_test.rb b/railties/test/generators/plugin_test_runner_test.rb
index 0887afd0db..716728819e 100644
--- a/railties/test/generators/plugin_test_runner_test.rb
+++ b/railties/test/generators/plugin_test_runner_test.rb
@@ -1,7 +1,8 @@
-require 'tmpdir'
-require 'abstract_unit'
+require 'generators/plugin_test_helper'
class PluginTestRunnerTest < ActiveSupport::TestCase
+ include PluginTestHelper
+
def setup
@destination_root = Dir.mktmpdir('bukkits')
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --skip-bundle` }
@@ -70,7 +71,7 @@ class PluginTestRunnerTest < ActiveSupport::TestCase
create_test_file 'post', pass: false
output = run_test_command('test/post_test.rb')
- assert_match %r{Running:\n\nPostTest\nF\n\nwups!\n\nbin/test #{plugin_path}/test/post_test.rb:6}, output
+ assert_match %r{Running:\n\nPostTest\nF\n\nwups!\n\nbin/test (/private)?#{plugin_path}/test/post_test.rb:6}, output
end
def test_only_inline_failure_output
@@ -100,24 +101,4 @@ class PluginTestRunnerTest < ActiveSupport::TestCase
def run_test_command(arguments)
Dir.chdir(plugin_path) { `bin/test #{arguments}` }
end
-
- def create_test_file(name, pass: true)
- plugin_file "test/#{name}_test.rb", <<-RUBY
- require 'test_helper'
-
- class #{name.camelize}Test < ActiveSupport::TestCase
- def test_truth
- puts "#{name.camelize}Test"
- assert #{pass}, 'wups!'
- end
- end
- RUBY
- end
-
- def plugin_file(path, contents, mode: 'w')
- FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}")
- File.open("#{plugin_path}/#{path}", mode) do |f|
- f.puts contents
- end
- end
end
diff --git a/railties/test/generators/test_runner_in_engine_test.rb b/railties/test/generators/test_runner_in_engine_test.rb
new file mode 100644
index 0000000000..641c5d0835
--- /dev/null
+++ b/railties/test/generators/test_runner_in_engine_test.rb
@@ -0,0 +1,31 @@
+require 'generators/plugin_test_helper'
+
+class TestRunnerInEngineTest < ActiveSupport::TestCase
+ include PluginTestHelper
+
+ def setup
+ @destination_root = Dir.mktmpdir('bukkits')
+ Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --full --skip-bundle` }
+ plugin_file 'test/dummy/db/schema.rb', ''
+ end
+
+ def teardown
+ FileUtils.rm_rf(@destination_root)
+ end
+
+ def test_rerun_snippet_is_relative_path
+ create_test_file 'post', pass: false
+
+ output = run_test_command('test/post_test.rb')
+ assert_match %r{Running:\n\nPostTest\nF\n\nwups!\n\nbin/rails test test/post_test.rb:6}, output
+ end
+
+ private
+ def plugin_path
+ "#{@destination_root}/bukkits"
+ end
+
+ def run_test_command(arguments)
+ Dir.chdir(plugin_path) { `bin/rails test #{arguments}` }
+ end
+end