railties 5.1.2 → 5.1.3.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7685a90fdb075ddece6002b6b1b064495602bf93
4
- data.tar.gz: ece2faf8800420587984148032da7ac92eb396a0
3
+ metadata.gz: 7b856f7a9711178b06bf7ef9a9e826bf3e47e5cd
4
+ data.tar.gz: 971b769b568c0fcc83c4a96f8c68a79b09705fea
5
5
  SHA512:
6
- metadata.gz: '0615908da73a23cabf6ae9ea22b49c1be0e0f60187e7e999933a79882a667f2898b9fa2e2f4a33ea42d6e10142c2da839bfe5e2465b018ea0b790fcbdc845471'
7
- data.tar.gz: 228cc16fc2f224cf524cfe573e015f2941b79d595fdd6d20e66b30fd8a989cb12a844689884cb51dd4d1c4e7c2edff921dd7c839b0c623f82203efb3d7e2b905
6
+ metadata.gz: d9ebadfd36d020f67fbbadba2da90f54978f00d5db751691651a527b0da67c8661647be7f728cad782015cf251a93b43400b993da51f34d110ca719b5a95e8e4
7
+ data.tar.gz: a095b545bb6e62f2754e34a39eae5021171c9cb3bf1b1e383e7879d0587f12cf9e048811e56c71e0afba092e5ac7fdb837aa1eb223c278a36561d2250eb311de
@@ -1,3 +1,26 @@
1
+ ## Rails 5.1.3.rc1 (July 19, 2017) ##
2
+
3
+ * Make Rails' test runner work better with minitest plugins.
4
+
5
+ By demoting the Rails test runner to just another minitest plugin —
6
+ and thereby not eager loading it — we can co-exist much better with
7
+ other minitest plugins such as pride and minitest-focus.
8
+
9
+ *Kasper Timm Hansen*
10
+
11
+ * Load environment file in `dbconsole` command.
12
+
13
+ Fixes #29717
14
+
15
+ *Yuji Yaginuma*
16
+
17
+ * Allow mounting the same engine several times in different locations.
18
+
19
+ Fixes #20204.
20
+
21
+ *David Rodríguez*
22
+
23
+
1
24
  ## Rails 5.1.2 (June 26, 2017) ##
2
25
 
3
26
  * Add Windows support to `rails secrets:edit`.
@@ -0,0 +1,49 @@
1
+ require "active_support/core_ext/module/attribute_accessors"
2
+ require "rails/test_unit/reporter"
3
+
4
+ module Minitest
5
+ class SuppressedSummaryReporter < SummaryReporter
6
+ # Disable extra failure output after a run if output is inline.
7
+ def aggregated_results(*)
8
+ super unless options[:output_inline]
9
+ end
10
+ end
11
+
12
+ def self.plugin_rails_options(opts, options)
13
+ opts.on("-b", "--backtrace", "Show the complete backtrace") do
14
+ options[:full_backtrace] = true
15
+ end
16
+
17
+ opts.on("-d", "--defer-output", "Output test failures and errors after the test run") do
18
+ options[:output_inline] = false
19
+ end
20
+
21
+ opts.on("-f", "--fail-fast", "Abort test run on first failure or error") do
22
+ options[:fail_fast] = true
23
+ end
24
+
25
+ opts.on("-c", "--[no-]color", "Enable color in the output") do |value|
26
+ options[:color] = value
27
+ end
28
+
29
+ options[:color] = true
30
+ options[:output_inline] = true
31
+ end
32
+
33
+ # Owes great inspiration to test runner trailblazers like RSpec,
34
+ # minitest-reporters, maxitest and others.
35
+ def self.plugin_rails_init(options)
36
+ unless options[:full_backtrace] || ENV["BACKTRACE"]
37
+ # Plugin can run without Rails loaded, check before filtering.
38
+ Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
39
+ end
40
+
41
+ # Replace progress reporter for colors.
42
+ reporter.reporters.delete_if { |reporter| reporter.kind_of?(SummaryReporter) || reporter.kind_of?(ProgressReporter) }
43
+ reporter << SuppressedSummaryReporter.new(options[:io], options)
44
+ reporter << ::Rails::TestUnitReporter.new(options[:io], options)
45
+ end
46
+
47
+ # Backwardscompatibility with Rails 5.0 generated plugin test scripts
48
+ mattr_reader(:run_via) { Hash.new }
49
+ end
Binary file
@@ -11,7 +11,7 @@ module Rails
11
11
  end
12
12
 
13
13
  def start
14
- ENV["RAILS_ENV"] = @options[:environment] || environment
14
+ ENV["RAILS_ENV"] ||= @options[:environment] || environment
15
15
 
16
16
  case config["adapter"]
17
17
  when /^(jdbc)?mysql/
@@ -148,6 +148,10 @@ module Rails
148
148
  def perform
149
149
  extract_environment_option_from_argument
150
150
 
151
+ # RAILS_ENV needs to be set before config/application is required.
152
+ ENV["RAILS_ENV"] = options[:environment]
153
+
154
+ require_application_and_environment!
151
155
  Rails::DBConsole.start(options)
152
156
  end
153
157
  end
@@ -1,21 +1,41 @@
1
- require "rails/command"
2
- require "rails/test_unit/minitest_plugin"
1
+ require_relative "../../command"
2
+ require_relative "../../test_unit/runner"
3
3
 
4
4
  module Rails
5
5
  module Command
6
6
  class TestCommand < Base # :nodoc:
7
7
  no_commands do
8
8
  def help
9
- perform # Hand over help printing to minitest.
9
+ require "optparse"
10
+ require "minitest/rails_plugin"
11
+
12
+ opts = OptionParser.new
13
+ opts.banner = "Usage: #{Rails::TestUnitReporter.executable} [options] [files or directories]"
14
+ opts.separator ""
15
+ opts.separator "You can run a single test by appending a line number to a filename:"
16
+ opts.separator ""
17
+ opts.separator " #{Rails::TestUnitReporter.executable} test/models/user_test.rb:27"
18
+ opts.separator ""
19
+ opts.separator "You can run multiple files and directories at the same time:"
20
+ opts.separator ""
21
+ opts.separator " #{Rails::TestUnitReporter.executable} test/controllers test/integration/login_test.rb"
22
+ opts.separator ""
23
+ opts.separator "By default test failures and errors are reported inline during a run."
24
+ opts.separator ""
25
+
26
+ opts.separator "Rails options:"
27
+ Rails::TestUnit::Runner.options(opts)
28
+ Minitest.plugin_rails_options(opts, {})
29
+
30
+ say opts
10
31
  end
11
32
  end
12
33
 
13
34
  def perform(*)
14
35
  $LOAD_PATH << Rails::Command.root.join("test").to_s
15
36
 
16
- Minitest.run_via = :rails
17
-
18
- require "active_support/testing/autorun"
37
+ Rails::TestUnit::Runner.parse_options(ARGV)
38
+ Rails::TestUnit::Runner.run(ARGV)
19
39
  end
20
40
  end
21
41
  end
@@ -7,8 +7,8 @@ module Rails
7
7
  module VERSION
8
8
  MAJOR = 5
9
9
  MINOR = 1
10
- TINY = 2
11
- PRE = nil
10
+ TINY = 3
11
+ PRE = "rc1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,7 +1,7 @@
1
- require "rails/test_unit/minitest_plugin"
1
+ require_relative "../test_unit/runner"
2
+ require_relative "../test_unit/reporter"
2
3
 
3
4
  Rails::TestUnitReporter.executable = "bin/test"
4
5
 
5
- Minitest.run_via = :rails
6
-
7
- require "active_support/testing/autorun"
6
+ Rails::TestUnit::Runner.parse_options(ARGV)
7
+ Rails::TestUnit::Runner.run(ARGV)
@@ -42,7 +42,7 @@ module Rails
42
42
  <<-end_of_template.strip_heredoc
43
43
  # See `secrets.yml` for tips on generating suitable keys.
44
44
  # production:
45
- # external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289
45
+ # external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289
46
46
 
47
47
  end_of_template
48
48
  end
@@ -100,12 +100,15 @@ module Rails
100
100
  end
101
101
 
102
102
  def writing(contents)
103
- tmp_path = File.join(Dir.tmpdir, File.basename(path))
104
- File.write(tmp_path, contents)
103
+ tmp_file = "#{File.basename(path)}.#{Process.pid}"
104
+ tmp_path = File.join(Dir.tmpdir, tmp_file)
105
+ IO.binwrite(tmp_path, contents)
105
106
 
106
107
  yield tmp_path
107
108
 
108
- write(File.read(tmp_path))
109
+ updated_contents = IO.binread(tmp_path)
110
+
111
+ write(updated_contents) if updated_contents != contents
109
112
  ensure
110
113
  FileUtils.rm(tmp_path) if File.exist?(tmp_path)
111
114
  end
@@ -2,7 +2,6 @@
2
2
  # so fixtures aren't loaded into that environment
3
3
  abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
4
4
 
5
- require "rails/test_unit/minitest_plugin"
6
5
  require "active_support/test_case"
7
6
  require "action_controller"
8
7
  require "action_controller/test_case"
@@ -1,78 +1,12 @@
1
1
  require "method_source"
2
+ require "rails/test_unit/runner"
2
3
 
3
4
  module Rails
4
5
  module LineFiltering # :nodoc:
5
6
  def run(reporter, options = {})
6
- if options[:patterns] && options[:patterns].any? { |p| p =~ /:\d+/ }
7
- options[:filter] = \
8
- CompositeFilter.new(self, options[:filter], options[:patterns])
9
- end
7
+ options[:filter] = Rails::TestUnit::Runner.compose_filter(self, options[:filter])
10
8
 
11
9
  super
12
10
  end
13
11
  end
14
-
15
- class CompositeFilter # :nodoc:
16
- attr_reader :named_filter
17
-
18
- def initialize(runnable, filter, patterns)
19
- @runnable = runnable
20
- @named_filter = derive_named_filter(filter)
21
- @filters = [ @named_filter, *derive_line_filters(patterns) ].compact
22
- end
23
-
24
- # Minitest uses === to find matching filters.
25
- def ===(method)
26
- @filters.any? { |filter| filter === method }
27
- end
28
-
29
- private
30
- def derive_named_filter(filter)
31
- if filter.respond_to?(:named_filter)
32
- filter.named_filter
33
- elsif filter =~ %r%/(.*)/% # Regexp filtering copied from Minitest.
34
- Regexp.new $1
35
- elsif filter.is_a?(String)
36
- filter
37
- end
38
- end
39
-
40
- def derive_line_filters(patterns)
41
- patterns.flat_map do |file_and_line|
42
- file, *lines = file_and_line.split(":")
43
-
44
- if lines.empty?
45
- Filter.new(@runnable, file, nil) if file
46
- else
47
- lines.map { |line| Filter.new(@runnable, file, line) }
48
- end
49
- end
50
- end
51
- end
52
-
53
- class Filter # :nodoc:
54
- def initialize(runnable, file, line)
55
- @runnable, @file = runnable, File.expand_path(file)
56
- @line = line.to_i if line
57
- end
58
-
59
- def ===(method)
60
- return unless @runnable.method_defined?(method)
61
-
62
- if @line
63
- test_file, test_range = definition_for(@runnable.instance_method(method))
64
- test_file == @file && test_range.include?(@line)
65
- else
66
- @runnable.instance_method(method).source_location.first == @file
67
- end
68
- end
69
-
70
- private
71
- def definition_for(method)
72
- file, start_line = method.source_location
73
- end_line = method.source.count("\n") + start_line - 1
74
-
75
- return file, start_line..end_line
76
- end
77
- end
78
12
  end
@@ -72,7 +72,12 @@ module Rails
72
72
  end
73
73
 
74
74
  def app_root
75
- @app_root ||= defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
75
+ @app_root ||=
76
+ if defined?(ENGINE_ROOT)
77
+ ENGINE_ROOT
78
+ elsif Rails.respond_to?(:root)
79
+ Rails.root
80
+ end
76
81
  end
77
82
 
78
83
  def colored_output?
@@ -0,0 +1,140 @@
1
+ require "shellwords"
2
+ require "method_source"
3
+ require "rake/file_list"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+
6
+ module Rails
7
+ module TestUnit
8
+ class Runner
9
+ mattr_reader(:filters) { [] }
10
+
11
+ class << self
12
+ def options(opts)
13
+ opts.on("--warnings", "-w", "Run with Ruby warnings enabled") {}
14
+ opts.on("--environment", "-e", "Run tests in the ENV environment") {}
15
+ end
16
+
17
+ def parse_options(argv)
18
+ # Perform manual parsing and cleanup since option parser raises on unknown options.
19
+ env_index = argv.index("--environment") || argv.index("-e")
20
+ if env_index
21
+ argv.delete_at(env_index)
22
+ environment = argv.delete_at(env_index).strip
23
+ end
24
+ ENV["RAILS_ENV"] = environment || "test"
25
+
26
+ w_index = argv.index("--warnings") || argv.index("-w")
27
+ $VERBOSE = argv.delete_at(w_index) if w_index
28
+ end
29
+
30
+ def rake_run(argv = [])
31
+ ARGV.replace Shellwords.split(ENV["TESTOPTS"] || "")
32
+
33
+ run(argv)
34
+ end
35
+
36
+ def run(argv = [])
37
+ load_tests(argv)
38
+
39
+ require "active_support/testing/autorun"
40
+ end
41
+
42
+ def load_tests(argv)
43
+ patterns = extract_filters(argv)
44
+
45
+ tests = Rake::FileList[patterns.any? ? patterns : "test/**/*_test.rb"]
46
+ tests.exclude("test/system/**/*") if patterns.empty?
47
+
48
+ tests.to_a.each { |path| require File.expand_path(path) }
49
+ end
50
+
51
+ def compose_filter(runnable, filter)
52
+ if filters.any? { |_, lines| lines.any? }
53
+ CompositeFilter.new(runnable, filter, filters)
54
+ else
55
+ filter
56
+ end
57
+ end
58
+
59
+ private
60
+ def extract_filters(argv)
61
+ argv.select { |arg| arg =~ /^\w+\// }.map do |path|
62
+ case
63
+ when path =~ /(:\d+)+$/
64
+ file, *lines = path.split(":")
65
+ filters << [ file, lines ]
66
+ file
67
+ when Dir.exist?(path)
68
+ "#{path}/**/*_test.rb"
69
+ else
70
+ filters << [ path, [] ]
71
+ path
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ class CompositeFilter # :nodoc:
79
+ attr_reader :named_filter
80
+
81
+ def initialize(runnable, filter, patterns)
82
+ @runnable = runnable
83
+ @named_filter = derive_named_filter(filter)
84
+ @filters = [ @named_filter, *derive_line_filters(patterns) ].compact
85
+ end
86
+
87
+ # Minitest uses === to find matching filters.
88
+ def ===(method)
89
+ @filters.any? { |filter| filter === method }
90
+ end
91
+
92
+ private
93
+ def derive_named_filter(filter)
94
+ if filter.respond_to?(:named_filter)
95
+ filter.named_filter
96
+ elsif filter =~ %r%/(.*)/% # Regexp filtering copied from Minitest.
97
+ Regexp.new $1
98
+ elsif filter.is_a?(String)
99
+ filter
100
+ end
101
+ end
102
+
103
+ def derive_line_filters(patterns)
104
+ patterns.flat_map do |file, lines|
105
+ if lines.empty?
106
+ Filter.new(@runnable, file, nil) if file
107
+ else
108
+ lines.map { |line| Filter.new(@runnable, file, line) }
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ class Filter # :nodoc:
115
+ def initialize(runnable, file, line)
116
+ @runnable, @file = runnable, File.expand_path(file)
117
+ @line = line.to_i if line
118
+ end
119
+
120
+ def ===(method)
121
+ return unless @runnable.method_defined?(method)
122
+
123
+ if @line
124
+ test_file, test_range = definition_for(@runnable.instance_method(method))
125
+ test_file == @file && test_range.include?(@line)
126
+ else
127
+ @runnable.instance_method(method).source_location.first == @file
128
+ end
129
+ end
130
+
131
+ private
132
+ def definition_for(method)
133
+ file, start_line = method.source_location
134
+ end_line = method.source.count("\n") + start_line - 1
135
+
136
+ return file, start_line..end_line
137
+ end
138
+ end
139
+ end
140
+ end
@@ -1,6 +1,6 @@
1
1
  gem "minitest"
2
2
  require "minitest"
3
- require "rails/test_unit/minitest_plugin"
3
+ require_relative "runner"
4
4
 
5
5
  task default: :test
6
6
 
@@ -9,9 +9,9 @@ task :test do
9
9
  $: << "test"
10
10
 
11
11
  if ENV.key?("TEST")
12
- Minitest.rake_run([ENV["TEST"]])
12
+ Rails::TestUnit::Runner.rake_run([ENV["TEST"]])
13
13
  else
14
- Minitest.rake_run(["test"], ["test/system/**/*"])
14
+ Rails::TestUnit::Runner.rake_run
15
15
  end
16
16
  end
17
17
 
@@ -29,28 +29,28 @@ namespace :test do
29
29
  ["models", "helpers", "controllers", "mailers", "integration", "jobs"].each do |name|
30
30
  task name => "test:prepare" do
31
31
  $: << "test"
32
- Minitest.rake_run(["test/#{name}"])
32
+ Rails::TestUnit::Runner.rake_run(["test/#{name}"])
33
33
  end
34
34
  end
35
35
 
36
36
  task generators: "test:prepare" do
37
37
  $: << "test"
38
- Minitest.rake_run(["test/lib/generators"])
38
+ Rails::TestUnit::Runner.rake_run(["test/lib/generators"])
39
39
  end
40
40
 
41
41
  task units: "test:prepare" do
42
42
  $: << "test"
43
- Minitest.rake_run(["test/models", "test/helpers", "test/unit"])
43
+ Rails::TestUnit::Runner.rake_run(["test/models", "test/helpers", "test/unit"])
44
44
  end
45
45
 
46
46
  task functionals: "test:prepare" do
47
47
  $: << "test"
48
- Minitest.rake_run(["test/controllers", "test/mailers", "test/functional"])
48
+ Rails::TestUnit::Runner.rake_run(["test/controllers", "test/mailers", "test/functional"])
49
49
  end
50
50
 
51
51
  desc "Run system tests only"
52
52
  task system: "test:prepare" do
53
53
  $: << "test"
54
- Minitest.rake_run(["test/system"])
54
+ Rails::TestUnit::Runner.rake_run(["test/system"])
55
55
  end
56
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railties
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.1.3.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.2
19
+ version: 5.1.3.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.2
26
+ version: 5.1.3.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 5.1.2
33
+ version: 5.1.3.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 5.1.2
40
+ version: 5.1.3.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - '='
94
94
  - !ruby/object:Gem::Version
95
- version: 5.1.2
95
+ version: 5.1.3.rc1
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - '='
101
101
  - !ruby/object:Gem::Version
102
- version: 5.1.2
102
+ version: 5.1.3.rc1
103
103
  description: 'Rails internals: application bootup, plugins, generators, and rake tasks.'
104
104
  email: david@loudthinking.com
105
105
  executables:
@@ -112,7 +112,9 @@ files:
112
112
  - RDOC_MAIN.rdoc
113
113
  - README.rdoc
114
114
  - exe/rails
115
+ - lib/minitest/rails_plugin.rb
115
116
  - lib/rails.rb
117
+ - lib/rails/.DS_Store
116
118
  - lib/rails/all.rb
117
119
  - lib/rails/api/generator.rb
118
120
  - lib/rails/api/task.rb
@@ -129,15 +131,18 @@ files:
129
131
  - lib/rails/code_statistics.rb
130
132
  - lib/rails/code_statistics_calculator.rb
131
133
  - lib/rails/command.rb
134
+ - lib/rails/command/.DS_Store
132
135
  - lib/rails/command/actions.rb
133
136
  - lib/rails/command/base.rb
134
137
  - lib/rails/command/behavior.rb
135
138
  - lib/rails/command/environment_argument.rb
136
139
  - lib/rails/commands.rb
140
+ - lib/rails/commands/.DS_Store
137
141
  - lib/rails/commands/application/application_command.rb
138
142
  - lib/rails/commands/console/console_command.rb
139
143
  - lib/rails/commands/dbconsole/dbconsole_command.rb
140
144
  - lib/rails/commands/destroy/destroy_command.rb
145
+ - lib/rails/commands/generate/.DS_Store
141
146
  - lib/rails/commands/generate/generate_command.rb
142
147
  - lib/rails/commands/help/USAGE
143
148
  - lib/rails/commands/help/help_command.rb
@@ -156,6 +161,7 @@ files:
156
161
  - lib/rails/console/helpers.rb
157
162
  - lib/rails/dev_caching.rb
158
163
  - lib/rails/engine.rb
164
+ - lib/rails/engine/.DS_Store
159
165
  - lib/rails/engine/commands.rb
160
166
  - lib/rails/engine/configuration.rb
161
167
  - lib/rails/engine/railties.rb
@@ -397,10 +403,9 @@ files:
397
403
  - lib/rails/templates/rails/welcome/index.html.erb
398
404
  - lib/rails/test_help.rb
399
405
  - lib/rails/test_unit/line_filtering.rb
400
- - lib/rails/test_unit/minitest_plugin.rb
401
406
  - lib/rails/test_unit/railtie.rb
402
407
  - lib/rails/test_unit/reporter.rb
403
- - lib/rails/test_unit/test_requirer.rb
408
+ - lib/rails/test_unit/runner.rb
404
409
  - lib/rails/test_unit/testing.rake
405
410
  - lib/rails/version.rb
406
411
  - lib/rails/welcome_controller.rb
@@ -421,9 +426,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
421
426
  version: 2.2.2
422
427
  required_rubygems_version: !ruby/object:Gem::Requirement
423
428
  requirements:
424
- - - ">="
429
+ - - ">"
425
430
  - !ruby/object:Gem::Version
426
- version: '0'
431
+ version: 1.3.1
427
432
  requirements: []
428
433
  rubyforge_project:
429
434
  rubygems_version: 2.6.12
@@ -1,145 +0,0 @@
1
- require "active_support/core_ext/module/attribute_accessors"
2
- require "rails/test_unit/reporter"
3
- require "rails/test_unit/test_requirer"
4
- require "shellwords"
5
-
6
- module Minitest
7
- class SuppressedSummaryReporter < SummaryReporter
8
- # Disable extra failure output after a run if output is inline.
9
- def aggregated_results(*)
10
- super unless options[:output_inline]
11
- end
12
- end
13
-
14
- def self.plugin_rails_options(opts, options)
15
- executable = ::Rails::TestUnitReporter.executable
16
- opts.separator ""
17
- opts.separator "Usage: #{executable} [options] [files or directories]"
18
- opts.separator "You can run a single test by appending a line number to a filename:"
19
- opts.separator ""
20
- opts.separator " #{executable} test/models/user_test.rb:27"
21
- opts.separator ""
22
- opts.separator "You can run multiple files and directories at the same time:"
23
- opts.separator ""
24
- opts.separator " #{executable} test/controllers test/integration/login_test.rb"
25
- opts.separator ""
26
- opts.separator "By default test failures and errors are reported inline during a run."
27
- opts.separator ""
28
-
29
- opts.separator "Rails options:"
30
- opts.on("-e", "--environment ENV",
31
- "Run tests in the ENV environment") do |env|
32
- options[:environment] = env.strip
33
- end
34
-
35
- opts.on("-b", "--backtrace",
36
- "Show the complete backtrace") do
37
- options[:full_backtrace] = true
38
- end
39
-
40
- opts.on("-d", "--defer-output",
41
- "Output test failures and errors after the test run") do
42
- options[:output_inline] = false
43
- end
44
-
45
- opts.on("-f", "--fail-fast",
46
- "Abort test run on first failure or error") do
47
- options[:fail_fast] = true
48
- end
49
-
50
- opts.on("-c", "--[no-]color",
51
- "Enable color in the output") do |value|
52
- options[:color] = value
53
- end
54
-
55
- opts.on("-w", "--warnings",
56
- "Enable ruby warnings") do
57
- $VERBOSE = true
58
- end
59
-
60
- options[:color] = true
61
- options[:output_inline] = true
62
- options[:patterns] = opts.order! unless run_via.rake?
63
- end
64
-
65
- def self.rake_run(patterns, exclude_patterns = []) # :nodoc:
66
- self.run_via = :rake unless run_via.set?
67
- ::Rails::TestRequirer.require_files(patterns, exclude_patterns)
68
- autorun
69
- end
70
-
71
- module RunRespectingRakeTestopts
72
- def run(args = [])
73
- if run_via.rake?
74
- args = Shellwords.split(ENV["TESTOPTS"] || "")
75
- end
76
-
77
- super
78
- end
79
- end
80
-
81
- singleton_class.prepend RunRespectingRakeTestopts
82
-
83
- # Owes great inspiration to test runner trailblazers like RSpec,
84
- # minitest-reporters, maxitest and others.
85
- def self.plugin_rails_init(options)
86
- ENV["RAILS_ENV"] = options[:environment] || "test"
87
-
88
- # If run via `ruby` we've been passed the files to run directly, or if run
89
- # via `rake` then they have already been eagerly required.
90
- unless run_via.ruby? || run_via.rake?
91
- # If there are no given patterns, we can assume that the user
92
- # simply runs the `bin/rails test` command without extra arguments.
93
- if options[:patterns].empty?
94
- ::Rails::TestRequirer.require_files(options[:patterns], ["test/system/**/*"])
95
- else
96
- ::Rails::TestRequirer.require_files(options[:patterns])
97
- end
98
- end
99
-
100
- unless options[:full_backtrace] || ENV["BACKTRACE"]
101
- # Plugin can run without Rails loaded, check before filtering.
102
- Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
103
- end
104
-
105
- # Replace progress reporter for colors.
106
- reporter.reporters.delete_if { |reporter| reporter.kind_of?(SummaryReporter) || reporter.kind_of?(ProgressReporter) }
107
- reporter << SuppressedSummaryReporter.new(options[:io], options)
108
- reporter << ::Rails::TestUnitReporter.new(options[:io], options)
109
- end
110
-
111
- def self.run_via=(runner)
112
- if run_via.set?
113
- raise ArgumentError, "run_via already assigned"
114
- else
115
- run_via.runner = runner
116
- end
117
- end
118
-
119
- class RunVia
120
- attr_accessor :runner
121
- alias set? runner
122
-
123
- # Backwardscompatibility with Rails 5.0 generated plugin test scripts.
124
- def []=(runner, *)
125
- @runner = runner
126
- end
127
-
128
- def ruby?
129
- runner == :ruby
130
- end
131
-
132
- def rake?
133
- runner == :rake
134
- end
135
- end
136
-
137
- mattr_reader(:run_via) { RunVia.new }
138
- end
139
-
140
- # Put Rails as the first plugin minitest initializes so other plugins
141
- # can override or replace our default reporter setup.
142
- # Since minitest only loads plugins if its extensions are empty we have
143
- # to call `load_plugins` first.
144
- Minitest.load_plugins
145
- Minitest.extensions.unshift "rails"
@@ -1,31 +0,0 @@
1
- require "active_support/core_ext/object/blank"
2
- require "rake/file_list"
3
-
4
- module Rails
5
- class TestRequirer # :nodoc:
6
- class << self
7
- def require_files(patterns, exclude_patterns = [])
8
- patterns = expand_patterns(patterns)
9
-
10
- file_list = Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"]
11
- file_list.exclude(exclude_patterns)
12
-
13
- file_list.to_a.each do |file|
14
- require File.expand_path(file)
15
- end
16
- end
17
-
18
- private
19
- def expand_patterns(patterns)
20
- patterns.map do |arg|
21
- arg = arg.gsub(/(:\d+)+?$/, "")
22
- if Dir.exist?(arg)
23
- "#{arg}/**/*_test.rb"
24
- else
25
- arg
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end