minitest-rails 3.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +94 -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 +19 -8
  15. data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +16 -0
  16. data/lib/generators/minitest/integration/integration_generator.rb +12 -9
  17. data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
  18. data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
  19. data/lib/generators/minitest/job/job_generator.rb +13 -10
  20. data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
  21. data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
  22. data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
  23. data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
  24. data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
  25. data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  26. data/lib/generators/minitest/model/model_generator.rb +9 -12
  27. data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
  28. data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
  29. data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
  30. data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
  31. data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
  32. data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
  33. data/lib/generators/minitest/scaffold/scaffold_generator.rb +21 -23
  34. data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
  35. data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
  36. data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
  37. data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
  38. data/lib/minitest/rails.rb +45 -108
  39. data/lib/minitest/rails/assertions.rb +5 -906
  40. data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
  41. data/lib/minitest/rails/assertions/action_mailer.rb +115 -0
  42. data/lib/minitest/rails/assertions/action_view.rb +356 -0
  43. data/lib/minitest/rails/assertions/active_job.rb +151 -0
  44. data/lib/minitest/rails/assertions/active_support.rb +29 -0
  45. data/lib/minitest/rails/expectations.rb +4 -565
  46. data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
  47. data/lib/minitest/rails/expectations/action_mailer.rb +136 -0
  48. data/lib/minitest/rails/expectations/active_job.rb +182 -0
  49. data/lib/minitest/rails/expectations/active_support.rb +42 -0
  50. data/lib/minitest/rails/railtie.rb +3 -2
  51. data/lib/minitest/rails/version.rb +1 -1
  52. metadata +72 -89
  53. data/.autotest +0 -23
  54. data/.gemtest +0 -0
  55. data/.travis.yml +0 -25
  56. data/CHANGELOG.rdoc +0 -223
  57. data/Gemfile +0 -7
  58. data/Manifest.txt +0 -76
  59. data/README.rdoc +0 -110
  60. data/Rakefile +0 -30
  61. data/gemfiles/5.0.gemfile +0 -5
  62. data/gemfiles/head.gemfile +0 -5
  63. data/lib/generators/.document +0 -0
  64. data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
  65. data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
  66. data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
  67. data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
  68. data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
  69. data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
  70. data/lib/generators/minitest/model/templates/model_test.rb +0 -13
  71. data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
  72. data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
  73. data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
  74. data/lib/minitest/rails/constant_lookup.rb +0 -52
  75. data/lib/minitest/rails/controller.rb +0 -14
  76. data/minitest-rails.gemspec +0 -48
  77. data/tasks/test.rake +0 -29
  78. data/test/generators/test_controller_generator.rb +0 -58
  79. data/test/generators/test_generator_generator.rb +0 -58
  80. data/test/generators/test_helper_generator.rb +0 -34
  81. data/test/generators/test_install_generator.rb +0 -27
  82. data/test/generators/test_job_generator.rb +0 -45
  83. data/test/generators/test_mailer_generator.rb +0 -42
  84. data/test/generators/test_model_generator.rb +0 -80
  85. data/test/generators/test_scaffold_generator.rb +0 -26
  86. data/test/helper.rb +0 -93
  87. data/test/rails/action_dispatch/test_assertions.rb +0 -39
  88. data/test/rails/action_dispatch/test_expectations.rb +0 -39
  89. data/test/rails/action_dispatch/test_spec_type.rb +0 -49
  90. data/test/rails/action_mailer/test_mailers.rb +0 -109
  91. data/test/rails/action_mailer/test_spec_type.rb +0 -47
  92. data/test/rails/action_view/test_helpers.rb +0 -73
  93. data/test/rails/action_view/test_spec_type.rb +0 -58
  94. data/test/rails/active_job/test_assertions.rb +0 -46
  95. data/test/rails/active_job/test_expectations.rb +0 -55
  96. data/test/rails/active_job/test_spec_type.rb +0 -49
  97. data/test/rails/active_support/test_assertions.rb +0 -31
  98. data/test/rails/active_support/test_expectations.rb +0 -21
  99. data/test/rails/active_support/test_spec_type.rb +0 -28
  100. data/test/rails/generators/test_spec_type.rb +0 -45
  101. data/test/rails/test_constant_lookup.rb +0 -58
  102. data/test/test_sanity.rb +0 -7
@@ -1,26 +0,0 @@
1
- require "helper"
2
- require "generators/minitest/scaffold/scaffold_generator"
3
-
4
- class TestScaffoldGenerator < GeneratorTest
5
-
6
- def test_scaffold_generator
7
- assert_output(/create test\/controllers\/users_controller_test.rb/m) do
8
- Minitest::Generators::ScaffoldGenerator.start ["User", "name:string", "email:string", "--no-spec"]
9
- end
10
- assert File.exists? "test/controllers/users_controller_test.rb"
11
- contents = File.read "test/controllers/users_controller_test.rb"
12
- assert_match(/class UsersControllerTest/m, contents)
13
- assert_match(/post users_url, params: { user: { email: user.email, name: user.name } }/m, contents)
14
- end
15
-
16
- def test_scaffold_generator_spec
17
- assert_output(/create test\/controllers\/users_controller_test.rb/m) do
18
- Minitest::Generators::ScaffoldGenerator.start ["User", "name:string", "email:string"]
19
- end
20
- assert File.exists? "test/controllers/users_controller_test.rb"
21
- contents = File.read "test/controllers/users_controller_test.rb"
22
- assert_match(/describe UsersController do/m, contents)
23
- assert_match(/post users_url, params: { user: { email: user.email, name: user.name } }/m, contents)
24
- end
25
-
26
- end
@@ -1,93 +0,0 @@
1
- require "minitest/autorun"
2
-
3
- require "rails"
4
- require "rails/generators"
5
-
6
- require "sqlite3"
7
- require "active_record"
8
-
9
- require "action_controller"
10
- require "action_controller/railtie"
11
-
12
- begin
13
- require "active_job"
14
- rescue LoadError
15
- end
16
-
17
- require "action_mailer"
18
-
19
- require "minitest-rails"
20
- require "rails/test_help"
21
- require "minitest/rails"
22
-
23
- require "minitest/focus"
24
- require "fakefs/safe"
25
-
26
- class FakeFS::File
27
- def self.binread file
28
- File.open(file, "rb") { |f| f.read }
29
- end
30
- end
31
-
32
- class GeneratorTest < Minitest::Test
33
- def setup
34
- Rails::Generators.no_color!
35
- FakeFS.activate!
36
- FakeFS::FileSystem.clone "lib/generators"
37
- end
38
-
39
- def teardown
40
- FakeFS::FileSystem.clear
41
- FakeFS.deactivate!
42
- end
43
-
44
- def refute_output stdout = nil, stderr = nil
45
- out, err = capture_io do
46
- yield
47
- end
48
-
49
- err_msg = Regexp === stderr ? :refute_match : :refute_equal if stderr
50
- out_msg = Regexp === stdout ? :refute_match : :refute_equal if stdout
51
-
52
- y = send err_msg, stderr, err, "In stderr" if err_msg
53
- x = send out_msg, stdout, out, "In stdout" if out_msg
54
-
55
- (!stdout || x) && (!stderr || y)
56
- end
57
- end
58
-
59
- require "rails/test_help"
60
-
61
- module TestApp
62
- class Application < ::Rails::Application
63
- config.active_support.test_order = :random
64
- config.secret_key_base = "abc123"
65
- end
66
- end
67
-
68
- TestApp::Application.initialize!
69
-
70
- class ApplicationController < ActionController::Base; end
71
- class ModelsController < ApplicationController
72
- def index; render html: "<html><head><title>Models</title></head><body><h1>All <em>Models</em></h1></body></html>".html_safe; end
73
- def new; redirect_to "/models"; end
74
- end
75
- module Admin
76
- class WidgetsController < ApplicationController; end
77
- end
78
-
79
- TestApp::Application.routes.draw do
80
- # root :to => "models#index"
81
- resources :models
82
- namespace :admin do
83
- resources :widgets
84
- end
85
- end
86
-
87
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
88
-
89
- if defined? ActiveJob
90
- class UserInviteJob < ActiveJob::Base
91
- def perform(arg = nil); end
92
- end
93
- end
@@ -1,39 +0,0 @@
1
- require "helper"
2
-
3
- class TestIntegrationAssertions < ActionDispatch::IntegrationTest
4
- def test_assert_response
5
- get models_path
6
- assert_response :success
7
- end
8
-
9
- def test_assert_redirected_to
10
- get new_model_path
11
- assert_redirected_to :models
12
- end
13
-
14
- def test_routing_assertions
15
- params = { :controller => "models", :action => "index" }
16
- path = "/models"
17
- assert_generates path, params
18
- assert_recognizes params, path
19
- assert_routing path, params
20
- end
21
-
22
- def test_assert_dom_equal
23
- apple_link = '<a href="http://www.example.com" target="_blank">Apples</a>'
24
- apple_link2 = '<a target="_blank" href="http://www.example.com">Apples</a>'
25
- orange_link = '<a href="http://www.example.com">Oranges</a>'
26
-
27
- assert_dom_equal apple_link, apple_link2
28
- refute_dom_equal apple_link, orange_link
29
- assert_dom_not_equal apple_link, orange_link
30
- end
31
-
32
- def test_assert_select
33
- get models_path
34
- assert_select "body h1"
35
- assert_select "body" do
36
- assert_select "h1"
37
- end
38
- end
39
- end
@@ -1,39 +0,0 @@
1
- require "helper"
2
-
3
- class TestIntegrationExpectations < ActionDispatch::IntegrationTest
4
- def test_must_respond_with
5
- get models_path
6
- must_respond_with :success
7
- value(response).must_be :success?
8
- end
9
-
10
- def test_must_redirect_to
11
- get new_model_path
12
- must_redirect_to :models
13
- end
14
-
15
- def test_routing_expectations
16
- params = { :controller => "models", :action => "index" }
17
- path = "/models"
18
- value(params).must_route_to path
19
- value(path).must_route_from params
20
- value(params).must_route_for path
21
- end
22
-
23
- def test_must_dom_equal
24
- apple_link = '<a href="http://www.example.com" target="_blank">Apples</a>'
25
- apple_link2 = '<a target="_blank" href="http://www.example.com">Apples</a>'
26
- orange_link = '<a href="http://www.example.com">Oranges</a>'
27
-
28
- value(apple_link).must_dom_equal apple_link2
29
- value(apple_link).wont_dom_equal orange_link
30
- end
31
-
32
- def test_must_select
33
- get models_path
34
- must_select "body h1"
35
- must_select "body" do
36
- must_select "h1"
37
- end
38
- end
39
- end
@@ -1,49 +0,0 @@
1
- require "helper"
2
-
3
- class ApplicationController < ActionController::Base; end
4
- class ModelsController < ApplicationController; end
5
-
6
- class TestActionDispatchSpecType < Minitest::Test
7
- def assert_dispatch actual
8
- assert_equal ActionDispatch::IntegrationTest, actual
9
- end
10
-
11
- def refute_dispatch actual
12
- refute_equal ActionDispatch::IntegrationTest, actual
13
- end
14
-
15
- def test_spec_type_resolves_for_class_constants
16
- assert_dispatch Minitest::Spec.spec_type(ApplicationController)
17
- assert_dispatch Minitest::Spec.spec_type(ModelsController)
18
- end
19
-
20
- def test_spec_type_resolves_for_matching_integration_strings
21
- assert_dispatch Minitest::Spec.spec_type("WidgetIntegrationTest")
22
- assert_dispatch Minitest::Spec.spec_type("Widget Integration Test")
23
- assert_dispatch Minitest::Spec.spec_type("WidgetIntegration")
24
- assert_dispatch Minitest::Spec.spec_type("Widget Integration")
25
- # And is not case sensitive
26
- assert_dispatch Minitest::Spec.spec_type("widgetintegrationtest")
27
- assert_dispatch Minitest::Spec.spec_type("widget integration test")
28
- assert_dispatch Minitest::Spec.spec_type("widgetintegration")
29
- assert_dispatch Minitest::Spec.spec_type("widget integration")
30
- end
31
-
32
- def test_spec_type_wont_match_non_space_characters_integration
33
- refute_dispatch Minitest::Spec.spec_type("Widget Integration\tTest")
34
- refute_dispatch Minitest::Spec.spec_type("Widget Integration\rTest")
35
- refute_dispatch Minitest::Spec.spec_type("Widget Integration\nTest")
36
- refute_dispatch Minitest::Spec.spec_type("Widget Integration\fTest")
37
- refute_dispatch Minitest::Spec.spec_type("Widget IntegrationXTest")
38
- end
39
-
40
- def test_spec_type_doesnt_resolve_random_strings
41
- refute_dispatch Minitest::Spec.spec_type("Unmatched String")
42
- end
43
-
44
- def test_spec_type_resolves_for_additional_desc_integration
45
- assert_dispatch Minitest::Spec.spec_type("Unmatched String", :integration)
46
- assert_dispatch Minitest::Spec.spec_type("Unmatched String", :integration, :other)
47
- assert_dispatch Minitest::Spec.spec_type("Unmatched String", :other, :integration)
48
- end
49
- end
@@ -1,109 +0,0 @@
1
- require "helper"
2
-
3
- class TestTestMailer < ActionMailer::Base; end
4
-
5
- # From Rails...
6
- class CrazyNameMailerTest < ActionMailer::TestCase
7
- tests TestTestMailer
8
-
9
- def test_set_mailer_class_manual
10
- assert_equal TestTestMailer, self.class.mailer_class
11
- end
12
- end
13
-
14
- class CrazySymbolNameMailerTest < ActionMailer::TestCase
15
- tests :test_test_mailer
16
-
17
- def test_set_mailer_class_manual_using_symbol
18
- assert_equal TestTestMailer, self.class.mailer_class
19
- end
20
- end
21
-
22
- class CrazyStringNameMailerTest < ActionMailer::TestCase
23
- tests 'test_test_mailer'
24
-
25
- def test_set_mailer_class_manual_using_string
26
- assert_equal TestTestMailer, self.class.mailer_class
27
- end
28
- end
29
-
30
- # New tests...
31
- describe TestTestMailer do
32
- it "gets the mailer from the test name" do
33
- assert_equal TestTestMailer, self.class.mailer_class
34
- end
35
- end
36
-
37
- describe TestTestMailer, :action do
38
- it "gets the mailer from the test name" do
39
- assert_equal TestTestMailer, self.class.mailer_class
40
- end
41
- end
42
-
43
- describe TestTestMailer do
44
- describe "nested" do
45
- it "gets the mailer from the test name" do
46
- assert_equal TestTestMailer, self.class.mailer_class
47
- end
48
- end
49
- end
50
-
51
- describe TestTestMailer, :action do
52
- describe "nested" do
53
- it "gets the mailer from the test name" do
54
- assert_equal TestTestMailer, self.class.mailer_class
55
- end
56
- end
57
- end
58
-
59
- describe "TestTestMailer" do
60
- it "gets the mailer from the test name" do
61
- assert_equal TestTestMailer, self.class.mailer_class
62
- end
63
- end
64
-
65
- describe "TestTestMailerTest" do
66
- it "gets the mailer from the test name" do
67
- assert_equal TestTestMailer, self.class.mailer_class
68
- end
69
- end
70
-
71
- describe "AnotherCrazySymbolNameMailerTest" do
72
- tests :test_test_mailer
73
-
74
- it "gets the mailer after setting it with a symbol" do
75
- assert_equal TestTestMailer, self.class.mailer_class
76
- end
77
- end
78
-
79
- describe "AnotherCrazyStringNameMailerTest" do
80
- tests 'test_test_mailer'
81
-
82
- it "gets the mailer after setting it with a string" do
83
- assert_equal TestTestMailer, self.class.mailer_class
84
- end
85
- end
86
-
87
- describe "Another Crazy Name Mailer Test" do
88
- tests TestTestMailer
89
-
90
- it "gets the mailer after setting it manually" do
91
- assert_equal TestTestMailer, self.class.mailer_class
92
- end
93
- end
94
-
95
- describe "Another Crazy Symbol Name Mailer Test" do
96
- tests :test_test_mailer
97
-
98
- it "gets the mailer after setting it with a symbol" do
99
- assert_equal TestTestMailer, self.class.mailer_class
100
- end
101
- end
102
-
103
- describe "Another Crazy String Name Mailer Test" do
104
- tests 'test_test_mailer'
105
-
106
- it "gets the mailer after setting it with a string" do
107
- assert_equal TestTestMailer, self.class.mailer_class
108
- end
109
- end
@@ -1,47 +0,0 @@
1
- require "helper"
2
-
3
- class NotificationMailer < ActionMailer::Base; end
4
- class Notifications < ActionMailer::Base; end
5
-
6
- class TestActionMailerSpecType < Minitest::Test
7
- def assert_mailer actual
8
- assert_equal ActionMailer::TestCase, actual
9
- end
10
-
11
- def refute_mailer actual
12
- refute_equal ActionMailer::TestCase, actual
13
- end
14
-
15
- def test_spec_type_resolves_for_class_constants
16
- assert_mailer Minitest::Spec.spec_type(NotificationMailer)
17
- assert_mailer Minitest::Spec.spec_type(Notifications)
18
- end
19
-
20
- def test_spec_type_resolves_for_matching_strings
21
- assert_mailer Minitest::Spec.spec_type("WidgetMailer")
22
- assert_mailer Minitest::Spec.spec_type("WidgetMailerTest")
23
- assert_mailer Minitest::Spec.spec_type("Widget Mailer Test")
24
- # And is not case sensitive
25
- assert_mailer Minitest::Spec.spec_type("widgetmailer")
26
- assert_mailer Minitest::Spec.spec_type("widgetmailertest")
27
- assert_mailer Minitest::Spec.spec_type("widget mailer test")
28
- end
29
-
30
- def test_spec_type_wont_match_non_space_characters
31
- refute_mailer Minitest::Spec.spec_type("Widget Mailer\tTest")
32
- refute_mailer Minitest::Spec.spec_type("Widget Mailer\rTest")
33
- refute_mailer Minitest::Spec.spec_type("Widget Mailer\nTest")
34
- refute_mailer Minitest::Spec.spec_type("Widget Mailer\fTest")
35
- refute_mailer Minitest::Spec.spec_type("Widget MailerXTest")
36
- end
37
-
38
- def test_spec_type_doesnt_resolve_random_strings
39
- refute_mailer Minitest::Spec.spec_type("Unmatched String")
40
- end
41
-
42
- def test_spec_type_resolves_for_additional_desc_mailer
43
- assert_mailer Minitest::Spec.spec_type("Unmatched String", :mailer)
44
- assert_mailer Minitest::Spec.spec_type("Unmatched String", :mailer, :other)
45
- assert_mailer Minitest::Spec.spec_type("Unmatched String", :other, :mailer)
46
- end
47
- end
@@ -1,73 +0,0 @@
1
- require "helper"
2
-
3
- module PeopleHelper
4
- def title(text)
5
- content_tag(:h1, text)
6
- end
7
-
8
- def homepage_path
9
- people_path
10
- end
11
-
12
- def homepage_url
13
- people_url
14
- end
15
-
16
- def link_to_person(person)
17
- link_to person.name, person
18
- end
19
- end
20
-
21
- # From Rails...
22
- class CrazyHelperTest < ActionView::TestCase
23
- tests PeopleHelper
24
-
25
- def test_helper_class_can_be_set_manually_not_just_inferred
26
- assert_equal PeopleHelper, self.class.helper_class
27
- end
28
- end
29
-
30
- class CrazySymbolHelperTest < ActionView::TestCase
31
- tests :people
32
-
33
- def test_set_helper_class_using_symbol
34
- assert_equal PeopleHelper, self.class.helper_class
35
- end
36
- end
37
-
38
- class CrazyStringHelperTest < ActionView::TestCase
39
- tests 'people'
40
-
41
- def test_set_helper_class_using_string
42
- assert_equal PeopleHelper, self.class.helper_class
43
- end
44
- end
45
-
46
- # New tests...
47
- describe PeopleHelper do
48
- it "resolves the right helper_class" do
49
- assert_equal PeopleHelper, self.class.helper_class
50
- end
51
- end
52
-
53
- describe PeopleHelper, :helper_class do
54
- it "resolves the right helper_class" do
55
- assert_equal PeopleHelper, self.class.helper_class
56
- end
57
- end
58
-
59
- describe PeopleHelper do
60
- describe "even while nested" do
61
- it "resolves the right helper_class" do
62
- assert_equal PeopleHelper, self.class.helper_class
63
- end
64
- end
65
- end
66
-
67
- describe PeopleHelper, :helper_class do
68
- describe "even while nested" do
69
- it "resolves the right helper_class" do
70
- assert_equal PeopleHelper, self.class.helper_class
71
- end
72
- end
73
- end