minitest-rails 3.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +117 -0
  5. data/UPDATING.md +31 -0
  6. data/lib/generators/minitest.rb +17 -4
  7. data/lib/generators/minitest/controller/controller_generator.rb +6 -9
  8. data/lib/generators/minitest/controller/templates/{controller_spec.rb → functional_spec.rb.tt} +4 -4
  9. data/lib/generators/minitest/controller/templates/{controller_test.rb → functional_test.rb.tt} +3 -3
  10. data/lib/generators/minitest/generator/generator_generator.rb +3 -8
  11. data/lib/generators/minitest/generator/templates/{generator_spec.rb → generator_spec.rb.tt} +2 -2
  12. data/lib/generators/minitest/generator/templates/{generator_test.rb → generator_test.rb.tt} +1 -2
  13. data/lib/generators/minitest/helper/helper_generator.rb +5 -3
  14. data/lib/generators/minitest/install/install_generator.rb +21 -8
  15. data/lib/generators/minitest/install/templates/test/application_system_test_case.rb.tt +10 -0
  16. data/lib/generators/minitest/install/templates/test/channels/application_cable/connection_test.rb.tt +23 -0
  17. data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +23 -0
  18. data/lib/generators/minitest/integration/integration_generator.rb +12 -9
  19. data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
  20. data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
  21. data/lib/generators/minitest/job/job_generator.rb +13 -10
  22. data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
  23. data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
  24. data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
  25. data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
  26. data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
  27. data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  28. data/lib/generators/minitest/model/model_generator.rb +9 -12
  29. data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
  30. data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
  31. data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
  32. data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
  33. data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
  34. data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
  35. data/lib/generators/minitest/scaffold/scaffold_generator.rb +28 -23
  36. data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
  37. data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
  38. data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
  39. data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
  40. data/lib/generators/minitest/scaffold/templates/system_spec.rb.tt +55 -0
  41. data/lib/generators/minitest/scaffold/templates/system_test.rb.tt +57 -0
  42. data/lib/generators/minitest/system/system_generator.rb +25 -0
  43. data/lib/generators/minitest/system/templates/application_system_test_case.rb.tt +10 -0
  44. data/lib/generators/minitest/system/templates/system_spec.rb.tt +9 -0
  45. data/lib/generators/minitest/system/templates/system_test.rb.tt +9 -0
  46. data/lib/minitest/rails.rb +76 -105
  47. data/lib/minitest/rails/assertions.rb +6 -906
  48. data/lib/minitest/rails/assertions/action_cable.rb +232 -0
  49. data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
  50. data/lib/minitest/rails/assertions/action_mailer.rb +153 -0
  51. data/lib/minitest/rails/assertions/action_view.rb +356 -0
  52. data/lib/minitest/rails/assertions/active_job.rb +151 -0
  53. data/lib/minitest/rails/assertions/active_support.rb +57 -0
  54. data/lib/minitest/rails/capybara.rb +17 -0
  55. data/lib/minitest/rails/expectations.rb +5 -565
  56. data/lib/minitest/rails/expectations/action_cable.rb +197 -0
  57. data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
  58. data/lib/minitest/rails/expectations/action_mailer.rb +175 -0
  59. data/lib/minitest/rails/expectations/active_job.rb +182 -0
  60. data/lib/minitest/rails/expectations/active_support.rb +73 -0
  61. data/lib/minitest/rails/parallelize.rb +41 -0
  62. data/lib/minitest/rails/railtie.rb +3 -2
  63. data/lib/minitest/rails/version.rb +1 -1
  64. metadata +87 -92
  65. data/.autotest +0 -23
  66. data/.gemtest +0 -0
  67. data/.travis.yml +0 -25
  68. data/CHANGELOG.rdoc +0 -223
  69. data/Gemfile +0 -7
  70. data/Manifest.txt +0 -76
  71. data/README.rdoc +0 -110
  72. data/Rakefile +0 -30
  73. data/gemfiles/5.0.gemfile +0 -5
  74. data/gemfiles/head.gemfile +0 -5
  75. data/lib/generators/.document +0 -0
  76. data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
  77. data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
  78. data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
  79. data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
  80. data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
  81. data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
  82. data/lib/generators/minitest/model/templates/model_test.rb +0 -13
  83. data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
  84. data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
  85. data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
  86. data/lib/minitest/rails/constant_lookup.rb +0 -52
  87. data/lib/minitest/rails/controller.rb +0 -14
  88. data/minitest-rails.gemspec +0 -48
  89. data/tasks/test.rake +0 -29
  90. data/test/generators/test_controller_generator.rb +0 -58
  91. data/test/generators/test_generator_generator.rb +0 -58
  92. data/test/generators/test_helper_generator.rb +0 -34
  93. data/test/generators/test_install_generator.rb +0 -27
  94. data/test/generators/test_job_generator.rb +0 -45
  95. data/test/generators/test_mailer_generator.rb +0 -42
  96. data/test/generators/test_model_generator.rb +0 -80
  97. data/test/generators/test_scaffold_generator.rb +0 -26
  98. data/test/helper.rb +0 -93
  99. data/test/rails/action_dispatch/test_assertions.rb +0 -39
  100. data/test/rails/action_dispatch/test_expectations.rb +0 -39
  101. data/test/rails/action_dispatch/test_spec_type.rb +0 -49
  102. data/test/rails/action_mailer/test_mailers.rb +0 -109
  103. data/test/rails/action_mailer/test_spec_type.rb +0 -47
  104. data/test/rails/action_view/test_helpers.rb +0 -73
  105. data/test/rails/action_view/test_spec_type.rb +0 -58
  106. data/test/rails/active_job/test_assertions.rb +0 -46
  107. data/test/rails/active_job/test_expectations.rb +0 -55
  108. data/test/rails/active_job/test_spec_type.rb +0 -49
  109. data/test/rails/active_support/test_assertions.rb +0 -31
  110. data/test/rails/active_support/test_expectations.rb +0 -21
  111. data/test/rails/active_support/test_spec_type.rb +0 -28
  112. data/test/rails/generators/test_spec_type.rb +0 -45
  113. data/test/rails/test_constant_lookup.rb +0 -58
  114. data/test/test_sanity.rb +0 -7
@@ -1,17 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "generators/minitest"
2
4
 
3
- module Minitest
4
- module Generators
5
- class IntegrationGenerator < Base
5
+ module Minitest # :nodoc:
6
+ module Generators # :nodoc:
7
+ class IntegrationGenerator < Base # :nodoc:
6
8
  check_class_collision suffix: "Test"
7
9
 
8
10
  def create_test_files
9
- if options[:spec]
10
- template_file = "integration_spec.rb"
11
- else
12
- template_file = "integration_test.rb"
13
- end
14
- template template_file, File.join("test/integration", class_path, "#{file_name}_test.rb")
11
+ template "integration_#{test_file_type}.rb", File.join("test/integration", class_path, "#{file_name}_test.rb")
12
+ end
13
+
14
+ private
15
+
16
+ def file_name
17
+ @_file_name ||= super.sub(/_test\z/i, "")
15
18
  end
16
19
  end
17
20
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ describe "<%= human_name %>", :integration do
5
+ # it "does a thing" do
6
+ # <%= spec_expectation_monad %>(1+1).must_equal 2
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>Test < ActionDispatch::IntegrationTest
5
+ # def test_truth
6
+ # assert true
7
+ # end
8
+ end
9
+ <% end -%>
@@ -1,17 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "generators/minitest"
2
4
 
3
- module Minitest
4
- module Generators
5
- class JobGenerator < Base
5
+ module Minitest # :nodoc:
6
+ module Generators # :nodoc:
7
+ class JobGenerator < Base # :nodoc:
6
8
  check_class_collision suffix: "JobTest"
7
9
 
8
- def create_test_files
9
- if options[:spec]
10
- template_file = "job_spec.rb"
11
- else
12
- template_file = "job_test.rb"
13
- end
14
- template template_file, File.join("test/jobs", class_path, "#{file_name}_job_test.rb")
10
+ def create_test_file
11
+ template "unit_#{test_file_type}.rb", File.join("test/jobs", class_path, "#{file_name}_job_test.rb")
12
+ end
13
+
14
+ private
15
+
16
+ def file_name
17
+ @_file_name ||= super.sub(/_job\z/i, "")
15
18
  end
16
19
  end
17
20
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ describe <%= class_name %>Job do
5
+ # it "does a thing" do
6
+ # <%= spec_expectation_monad %>(1+1).must_equal 2
7
+ # end
8
+ end
9
+ <% end -%>
@@ -1,9 +1,9 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  class <%= class_name %>JobTest < ActiveJob::TestCase
5
- # def test_sanity
6
- # flunk "Need real tests"
5
+ # def test_truth
6
+ # assert true
7
7
  # end
8
8
  end
9
9
  <% end -%>
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "generators/minitest"
2
4
 
3
- module Minitest
4
- module Generators
5
- class MailerGenerator < Base
5
+ module Minitest # :nodoc:
6
+ module Generators # :nodoc:
7
+ class MailerGenerator < Base # :nodoc:
6
8
  argument :actions, type: :array, default: [], banner: "method method"
7
9
 
8
10
  def check_class_collision
@@ -10,22 +12,17 @@ module Minitest
10
12
  end
11
13
 
12
14
  def create_test_files
13
- if options[:spec]
14
- template_file = "mailer_spec.rb"
15
- else
16
- template_file = "mailer_test.rb"
17
- end
18
- template template_file, File.join("test/mailers", class_path, "#{file_name}_mailer_test.rb")
15
+ template "functional_#{test_file_type}.rb", File.join("test/mailers", class_path, "#{file_name}_mailer_test.rb")
19
16
  end
20
17
 
21
18
  def create_preview_files
22
19
  template "preview.rb", File.join("test/mailers/previews", class_path, "#{file_name}_mailer_preview.rb")
23
20
  end
24
21
 
25
- protected
22
+ private
26
23
 
27
24
  def file_name
28
- @_file_name ||= super.gsub(/_mailer/i, "")
25
+ @_file_name ||= super.sub(/_mailer\z/i, "")
29
26
  end
30
27
  end
31
28
  end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ describe <%= class_name %>Mailer do
5
+ <% actions.each do |action| -%>
6
+ it "creates <%= action %> email" do
7
+ mail = <%= class_name %>Mailer.<%= action %>
8
+ mail.subject.must_equal <%= action.to_s.humanize.inspect %>
9
+ mail.to.must_equal ["to@example.org"]
10
+ mail.from.must_equal ["from@example.com"]
11
+ mail.body.encoded.must_equal "Hi"
12
+ end
13
+
14
+ <% end -%>
15
+ <% if actions.blank? -%>
16
+ # it "does a thing" do
17
+ # <%= spec_expectation_monad %>(1+1).must_equal 2
18
+ # end
19
+ <% end -%>
20
+ end
21
+ <% end -%>
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  class <%= class_name %>MailerTest < ActionMailer::TestCase
@@ -13,8 +13,8 @@ class <%= class_name %>MailerTest < ActionMailer::TestCase
13
13
 
14
14
  <% end -%>
15
15
  <% if actions.blank? -%>
16
- # def test_sanity
17
- # flunk "Need real tests"
16
+ # def test_truth
17
+ # assert true
18
18
  # end
19
19
  <% end -%>
20
20
  end
@@ -1,22 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "generators/minitest"
2
4
 
3
- module Minitest
4
- module Generators
5
- class ModelGenerator < Base
6
- RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null)
5
+ module Minitest # :nodoc:
6
+ module Generators # :nodoc:
7
+ class ModelGenerator < Base # :nodoc:
8
+ RESERVED_YAML_KEYWORDS = %w[y yes n no true false on off null].freeze
7
9
 
8
10
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
9
- class_option :fixture, type: :boolean, default: true, desc: "Create fixture file"
11
+ class_option :fixture, type: :boolean
10
12
 
11
13
  check_class_collision suffix: "Test"
12
14
 
13
15
  def create_test_file
14
- if options[:spec]
15
- template_file = "model_spec.rb"
16
- else
17
- template_file = "model_test.rb"
18
- end
19
- template template_file, File.join("test/models", class_path, "#{file_name}_test.rb")
16
+ template "unit_#{test_file_type}.rb", File.join("test/models", class_path, "#{file_name}_test.rb")
20
17
  end
21
18
 
22
19
  hook_for :fixture_replacement
@@ -29,7 +26,7 @@ module Minitest
29
26
 
30
27
  private
31
28
 
32
- def yaml_key_value(key, value)
29
+ def yaml_key_value key, value
33
30
  if RESERVED_YAML_KEYWORDS.include?(key.downcase)
34
31
  "'#{key}': #{value}"
35
32
  else
@@ -4,9 +4,9 @@
4
4
  <%= name %>:
5
5
  <% attributes.each do |attribute| -%>
6
6
  <%- if attribute.password_digest? -%>
7
- password_digest: <%%= BCrypt::Password.create("secret") %>
7
+ password_digest: <%%= BCrypt::Password.create('secret') %>
8
8
  <%- elsif attribute.reference? -%>
9
- <%= yaml_key_value(attribute.column_name.sub(/_id$/, ""), attribute.default || name) %>
9
+ <%= yaml_key_value(attribute.column_name.sub(/_id$/, ''), attribute.default || name) %>
10
10
  <%- else -%>
11
11
  <%= yaml_key_value(attribute.column_name, attribute.default) %>
12
12
  <%- end -%>
@@ -18,7 +18,7 @@
18
18
  <% else -%>
19
19
 
20
20
  # This model initially had no columns defined. If you add columns to the
21
- # model remove the "{}" from the fixture names and add the columns immediately
21
+ # model remove the '{}' from the fixture names and add the columns immediately
22
22
  # below each fixture, per the syntax in the comments below
23
23
  #
24
24
  one: {}
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ describe <%= class_name %> do
5
+ # it "does a thing" do
6
+ # <%= spec_expectation_monad %>(1+1).must_equal 2
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>Test < ActiveSupport::TestCase
5
+ # def test_truth
6
+ # assert true
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "generators/minitest"
4
+
5
+ module Minitest # :nodoc:
6
+ module Generators # :nodoc:
7
+ class PluginGenerator < Base # :nodoc:
8
+ check_class_collision suffix: "Test"
9
+
10
+ def create_test_files
11
+ directory ".", "test"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ <%- if options[:spec] -%>
4
+ describe <%= class_name %> do
5
+ # it "does a thing" do
6
+ # <%= spec_expectation_monad %>(1+1).must_equal 2
7
+ # end
8
+ end
9
+ <%- else -%>
10
+ class <%= class_name %>Test < ActiveSupport::TestCase
11
+ # def test_truth
12
+ # assert true
13
+ # end
14
+ end
15
+ <%- end -%>
@@ -0,0 +1,2 @@
1
+ require "active_support/testing/autorun"
2
+ require "active_support"
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "generators/minitest"
2
4
  require "rails/generators/resource_helpers"
3
5
 
4
- module Minitest
5
- module Generators
6
- class ScaffoldGenerator < Base
6
+ module Minitest # :nodoc:
7
+ module Generators # :nodoc:
8
+ class ScaffoldGenerator < Base # :nodoc:
7
9
  include ::Rails::Generators::ResourceHelpers
8
10
 
9
11
  check_class_collision suffix: "ControllerTest"
@@ -11,30 +13,25 @@ module Minitest
11
13
  class_option :api, type: :boolean,
12
14
  desc: "Generates API functional tests"
13
15
 
16
+ class_option :system_tests, type: :string,
17
+ desc: "Skip system test files"
18
+
14
19
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
15
20
 
16
21
  def create_test_files
17
- if options.api?
18
- if options[:spec]
19
- template_file = "api_controller_spec.rb"
20
- else
21
- template_file = "api_controller_test.rb"
22
- end
23
- else
24
- if options[:spec]
25
- template_file = "controller_spec.rb"
26
- else
27
- template_file = "controller_test.rb"
28
- end
29
- end
22
+ template_file = options.api? ? "api_functional_#{test_file_type}.rb" : "functional_#{test_file_type}.rb"
30
23
  template template_file,
31
24
  File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
25
+
26
+ if !options.api? && options[:system_tests]
27
+ template "system_#{test_file_type}.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb")
28
+ end
32
29
  end
33
30
 
34
31
  def fixture_name
35
32
  @fixture_name ||=
36
33
  if mountable_engine?
37
- "%s_%s" % [namespaced_path, table_name]
34
+ (namespace_dirs + [table_name]).join("_")
38
35
  else
39
36
  table_name
40
37
  end
@@ -42,17 +39,25 @@ module Minitest
42
39
 
43
40
  private
44
41
 
42
+ def attributes_string
43
+ attributes_hash.map { |k, v| "#{k}: #{v}" }.join(", ")
44
+ end
45
+
45
46
  def attributes_hash
46
- return if attributes_names.empty?
47
+ return {} if attributes_names.empty?
47
48
 
48
49
  attributes_names.map do |name|
49
- if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
50
- "#{name}: 'secret'"
50
+ if %w[password password_confirmation].include?(name) && attributes.any?(&:password_digest?)
51
+ [name.to_s, "'secret'"]
51
52
  else
52
- # don't use the ivar, use the accessor method
53
- "#{name}: #{singular_table_name}.#{name}"
53
+ [name.to_s, "@#{singular_table_name}.#{name}"]
54
54
  end
55
- end.sort.join(", ")
55
+ end.sort.to_h
56
+ end
57
+
58
+ def boolean? name
59
+ attribute = attributes.find { |attr| attr.name == name }
60
+ attribute&.type == :boolean
56
61
  end
57
62
  end
58
63
  end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ describe <%= controller_class_name %>Controller do
5
+ <%- if mountable_engine? -%>
6
+ include Engine.routes.url_helpers
7
+
8
+ <%- end -%>
9
+ let(:<%= singular_table_name %>) { <%= fixture_name %>(:one) }
10
+
11
+ it "should get index" do
12
+ get <%= index_helper %>_url, as: :json
13
+ must_respond_with :success
14
+ end
15
+
16
+ it "should create <%= singular_table_name %>" do
17
+ <%= spec_expectation_monad %> do
18
+ post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
19
+ end.must_differ "<%= class_name %>.count"
20
+
21
+ must_respond_with 201
22
+ end
23
+
24
+ it "should show <%= singular_table_name %>" do
25
+ get <%= show_helper %>, as: :json
26
+ must_respond_with :success
27
+ end
28
+
29
+ it "should update <%= singular_table_name %>" do
30
+ patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
31
+ must_respond_with 200
32
+ end
33
+
34
+ it "should destroy <%= singular_table_name %>" do
35
+ <%= spec_expectation_monad %> do
36
+ delete <%= show_helper %>, as: :json
37
+ end.must_differ "<%= class_name %>.count", -1
38
+
39
+ must_respond_with 204
40
+ end
41
+ end
42
+ <% end -%>