minitest-rails 0.3 → 0.5

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 (59) hide show
  1. data/.travis.yml +4 -2
  2. data/LICENSE +1 -1
  3. data/Manifest.txt +5 -8
  4. data/README.rdoc +11 -29
  5. data/Rakefile +3 -3
  6. data/gemfiles/3.0.gemfile +1 -1
  7. data/gemfiles/3.0.gemfile.lock +35 -35
  8. data/gemfiles/3.1.gemfile +1 -1
  9. data/gemfiles/3.1.gemfile.lock +35 -35
  10. data/gemfiles/3.2.gemfile +1 -1
  11. data/gemfiles/3.2.gemfile.lock +39 -38
  12. data/gemfiles/4.0.gemfile +8 -0
  13. data/gemfiles/4.0.gemfile.lock +104 -0
  14. data/lib/generators/mini_test.rb +25 -12
  15. data/lib/generators/mini_test/controller/templates/controller_test.rb +1 -1
  16. data/lib/generators/mini_test/helper/templates/helper_test.rb +2 -2
  17. data/lib/generators/mini_test/install/install_generator.rb +1 -1
  18. data/lib/generators/mini_test/install/templates/test/minitest_helper.rb +3 -9
  19. data/lib/generators/mini_test/integration/integration_generator.rb +2 -2
  20. data/lib/generators/mini_test/integration/templates/integration_spec.rb +2 -2
  21. data/lib/generators/mini_test/integration/templates/integration_test.rb +1 -1
  22. data/lib/generators/mini_test/mailer/templates/mailer_test.rb +1 -1
  23. data/lib/generators/mini_test/model/templates/model_test.rb +1 -1
  24. data/lib/generators/mini_test/scaffold/templates/controller_test.rb +1 -1
  25. data/lib/minitest/rails.rb +109 -20
  26. data/lib/minitest/rails/constant_lookup.rb +41 -44
  27. data/lib/minitest/rails/tasks/minitest.rake +22 -51
  28. data/lib/minitest/rails/test_case.rb +93 -0
  29. data/lib/minitest/rails/testing.rb +39 -0
  30. data/lib/minitest/rails/version.rb +1 -1
  31. data/minitest-rails.gemspec +11 -11
  32. data/tasks/gemfiles.rake +2 -1
  33. data/tasks/test.rake +6 -0
  34. data/test/generators/test_controller_generator.rb +10 -39
  35. data/test/generators/test_helper_generator.rb +8 -35
  36. data/test/generators/test_install_generator.rb +4 -27
  37. data/test/generators/test_mailer_generator.rb +5 -29
  38. data/test/generators/test_model_generator.rb +7 -32
  39. data/test/generators/test_scaffold_generator.rb +5 -29
  40. data/test/helper.rb +35 -0
  41. data/test/rails/action_controller/test_controllers.rb +4 -14
  42. data/test/rails/action_controller/test_spec_type.rb +3 -7
  43. data/test/rails/action_dispatch/test_spec_type.rb +16 -11
  44. data/test/rails/action_mailer/test_mailers.rb +4 -8
  45. data/test/rails/action_mailer/test_spec_type.rb +3 -8
  46. data/test/rails/action_view/test_helpers.rb +4 -7
  47. data/test/rails/action_view/test_spec_type.rb +3 -10
  48. data/test/rails/active_support/test_spec_type.rb +2 -7
  49. data/test/rails/test_constant_lookup.rb +2 -5
  50. data/test/test_sanity.rb +1 -2
  51. metadata +33 -36
  52. data/gemfiles/minitest_tu_shim.rb +0 -4
  53. data/lib/minitest/rails/action_controller.rb +0 -28
  54. data/lib/minitest/rails/action_dispatch.rb +0 -41
  55. data/lib/minitest/rails/action_mailer.rb +0 -26
  56. data/lib/minitest/rails/action_view.rb +0 -23
  57. data/lib/minitest/rails/active_support.rb +0 -70
  58. data/lib/minitest/rails/declarative.rb +0 -27
  59. data/lib/minitest/rails/mochaing.rb +0 -11
@@ -1,66 +1,39 @@
1
- require "minitest/autorun"
2
- require "minitest-rails"
3
-
4
- require "rails"
5
- require "rails/generators"
6
-
1
+ require "helper"
7
2
  require "generators/mini_test/helper/helper_generator"
8
3
 
9
- require "fakefs/safe"
10
-
11
- class FakeFS::File
12
- def self.binread file
13
- File.open(file, "rb") { |f| f.read }
14
- end
15
- end
16
-
17
- class TestHelperGenerator < MiniTest::Unit::TestCase
18
- def setup
19
- Rails::Generators.no_color!
20
- FakeFS.activate!
21
- FakeFS::FileSystem.clone "lib/generators"
22
- end
23
-
24
- def teardown
25
- FakeFS::FileSystem.clear
26
- FakeFS.deactivate!
27
- end
4
+ class TestHelperGenerator < GeneratorTest
28
5
 
29
6
  def test_helper_generator
30
- out, err = capture_io do
7
+ assert_output(/create test\/helpers\/user_helper_test.rb/m) do
31
8
  MiniTest::Generators::HelperGenerator.start ["user"]
32
9
  end
33
- assert_match(/create test\/helpers\/user_helper_test.rb/m, out)
34
10
  assert File.exists? "test/helpers/user_helper_test.rb"
35
11
  contents = File.read "test/helpers/user_helper_test.rb"
36
- assert_match(/class UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents)
12
+ assert_match(/class UserHelperTest < ActionView::TestCase/m, contents)
37
13
  end
38
14
 
39
15
  def test_namespaced_helper_generator
40
- out, err = capture_io do
16
+ assert_output(/create test\/helpers\/admin\/user_helper_test.rb/m) do
41
17
  MiniTest::Generators::HelperGenerator.start ["admin/user"]
42
18
  end
43
- assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, out)
44
19
  assert File.exists? "test/helpers/admin/user_helper_test.rb"
45
20
  contents = File.read "test/helpers/admin/user_helper_test.rb"
46
- assert_match(/class Admin::UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents)
21
+ assert_match(/class Admin::UserHelperTest < ActionView::TestCase/m, contents)
47
22
  end
48
23
 
49
24
  def test_helper_generator_spec
50
- out, err = capture_io do
25
+ assert_output(/create test\/helpers\/user_helper_test.rb/m) do
51
26
  MiniTest::Generators::HelperGenerator.start ["user", "--spec"]
52
27
  end
53
- assert_match(/create test\/helpers\/user_helper_test.rb/m, out)
54
28
  assert File.exists? "test/helpers/user_helper_test.rb"
55
29
  contents = File.read "test/helpers/user_helper_test.rb"
56
30
  assert_match(/describe UserHelper do/m, contents)
57
31
  end
58
32
 
59
33
  def test_namespaced_helper_generator_spec
60
- out, err = capture_io do
34
+ assert_output(/create test\/helpers\/admin\/user_helper_test.rb/m) do
61
35
  MiniTest::Generators::HelperGenerator.start ["admin/user", "--spec"]
62
36
  end
63
- assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, out)
64
37
  assert File.exists? "test/helpers/admin/user_helper_test.rb"
65
38
  contents = File.read "test/helpers/admin/user_helper_test.rb"
66
39
  assert_match(/describe Admin::UserHelper do/m, contents)
@@ -1,39 +1,16 @@
1
- require "minitest/autorun"
2
- require "minitest-rails"
3
-
4
- require "rails"
5
- require "rails/generators"
6
-
1
+ require "helper"
7
2
  require "generators/mini_test/install/install_generator"
8
3
 
9
- require "fakefs/safe"
10
-
11
- class FakeFS::File
12
- def self.binread file
13
- File.open(file, "rb") { |f| f.read }
14
- end
15
- end
16
-
17
- class TestInstallGenerator < MiniTest::Unit::TestCase
18
- def setup
19
- Rails::Generators.no_color!
20
- FakeFS.activate!
21
- FakeFS::FileSystem.clone "lib/generators"
22
- end
23
-
24
- def teardown
25
- FakeFS::FileSystem.clear
26
- FakeFS.deactivate!
27
- end
4
+ class TestInstallGenerator < GeneratorTest
28
5
 
29
6
  def test_install_generator
30
- out, err = capture_io do
7
+ assert_output(/create test\/minitest_helper.rb/m) do
31
8
  MiniTest::Generators::InstallGenerator.start
32
9
  end
33
- assert_match(/create test\/minitest_helper.rb/m, out)
34
10
  assert File.exists? "test/minitest_helper.rb"
35
11
  contents = File.read "test/minitest_helper.rb"
36
12
  assert_match(/require "minitest\/autorun"/m, contents)
37
13
  assert_match(/require "minitest\/rails"/m, contents)
38
14
  end
15
+
39
16
  end
@@ -1,48 +1,24 @@
1
- require "minitest/autorun"
2
- require "minitest-rails"
3
-
4
- require "rails"
5
- require "rails/generators"
6
-
1
+ require "helper"
7
2
  require "generators/mini_test/mailer/mailer_generator"
8
3
 
9
- require "fakefs/safe"
10
-
11
- class FakeFS::File
12
- def self.binread file
13
- File.open(file, "rb") { |f| f.read }
14
- end
15
- end
16
-
17
- class TestMailerGenerator < MiniTest::Unit::TestCase
18
- def setup
19
- Rails::Generators.no_color!
20
- FakeFS.activate!
21
- FakeFS::FileSystem.clone "lib/generators"
22
- end
23
-
24
- def teardown
25
- FakeFS::FileSystem.clear
26
- FakeFS.deactivate!
27
- end
4
+ class TestMailerGenerator < GeneratorTest
28
5
 
29
6
  def test_mailer_generator
30
- out, err = capture_io do
7
+ assert_output(/create test\/mailers\/notification_test.rb/m) do
31
8
  MiniTest::Generators::MailerGenerator.start ["notification"]
32
9
  end
33
- assert_match(/create test\/mailers\/notification_test.rb/m, out)
34
10
  assert File.exists? "test/mailers/notification_test.rb"
35
11
  contents = File.read "test/mailers/notification_test.rb"
36
12
  assert_match(/class NotificationTest/m, contents)
37
13
  end
38
14
 
39
15
  def test_mailer_generator_spec
40
- out, err = capture_io do
16
+ assert_output(/create test\/mailers\/notification_test.rb/m) do
41
17
  MiniTest::Generators::MailerGenerator.start ["notification", "welcome", "--spec"]
42
18
  end
43
- assert_match(/create test\/mailers\/notification_test.rb/m, out)
44
19
  assert File.exists? "test/mailers/notification_test.rb"
45
20
  contents = File.read "test/mailers/notification_test.rb"
46
21
  assert_match(/describe Notification do/m, contents)
47
22
  end
23
+
48
24
  end
@@ -1,46 +1,21 @@
1
- require "minitest/autorun"
2
- require "minitest-rails"
3
-
4
- require "rails"
5
- require "rails/generators"
6
-
1
+ require "helper"
7
2
  require "generators/mini_test/model/model_generator"
8
3
 
9
- require "fakefs/safe"
10
-
11
- class FakeFS::File
12
- def self.binread file
13
- File.open(file, "rb") { |f| f.read }
14
- end
15
- end
16
-
17
- class TestModelGenerator < MiniTest::Unit::TestCase
18
- def setup
19
- Rails::Generators.no_color!
20
- FakeFS.activate!
21
- FakeFS::FileSystem.clone "lib/generators"
22
- end
23
-
24
- def teardown
25
- FakeFS::FileSystem.clear
26
- FakeFS.deactivate!
27
- end
4
+ class TestModelGenerator < GeneratorTest
28
5
 
29
6
  def test_model_generator
30
- out, err = capture_io do
7
+ assert_output(/create test\/models\/user_test.rb/m) do
31
8
  MiniTest::Generators::ModelGenerator.start ["user"]
32
9
  end
33
- assert_match(/create test\/models\/user_test.rb/m, out)
34
10
  assert File.exists? "test/models/user_test.rb"
35
11
  contents = File.read "test/models/user_test.rb"
36
12
  assert_match(/class UserTest/m, contents)
37
13
  end
38
14
 
39
15
  def test_model_generator_spec
40
- out, err = capture_io do
16
+ assert_output(/create test\/models\/user_test.rb/m) do
41
17
  MiniTest::Generators::ModelGenerator.start ["user", "--spec"]
42
18
  end
43
- assert_match(/create test\/models\/user_test.rb/m, out)
44
19
  assert File.exists? "test/models/user_test.rb"
45
20
  assert File.exists? "test/fixtures/users.yml"
46
21
  contents = File.read "test/models/user_test.rb"
@@ -48,18 +23,18 @@ class TestModelGenerator < MiniTest::Unit::TestCase
48
23
  end
49
24
 
50
25
  def test_model_generator_fixture
51
- out, err = capture_io do
26
+ assert_output(/create test\/fixtures\/users.yml/m) do
52
27
  MiniTest::Generators::ModelGenerator.start ["user"]
53
28
  end
54
- assert_match(/create test\/fixtures\/users.yml/m, out)
55
29
  assert File.exists? "test/fixtures/users.yml"
56
30
  end
57
31
 
58
32
  def test_model_generator_skip_fixture
59
- out, err = capture_io do
33
+ out, _ = capture_io do
60
34
  MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
61
35
  end
62
36
  refute_match(/create test\/fixtures\/users.yml/m, out)
63
37
  refute File.exists? "test/fixtures/users.yml"
64
38
  end
39
+
65
40
  end
@@ -1,48 +1,24 @@
1
- require "minitest/autorun"
2
- require "minitest-rails"
3
-
4
- require "rails"
5
- require "rails/generators"
6
-
1
+ require "helper"
7
2
  require "generators/mini_test/scaffold/scaffold_generator"
8
3
 
9
- require "fakefs/safe"
10
-
11
- class FakeFS::File
12
- def self.binread file
13
- File.open(file, "rb") { |f| f.read }
14
- end
15
- end
16
-
17
- class TestScaffoldGenerator < MiniTest::Unit::TestCase
18
- def setup
19
- Rails::Generators.no_color!
20
- FakeFS.activate!
21
- FakeFS::FileSystem.clone "lib/generators"
22
- end
23
-
24
- def teardown
25
- FakeFS::FileSystem.clear
26
- FakeFS.deactivate!
27
- end
4
+ class TestScaffoldGenerator < GeneratorTest
28
5
 
29
6
  def test_scaffold_generator
30
- out, err = capture_io do
7
+ assert_output(/create test\/controllers\/users_controller_test.rb/m) do
31
8
  MiniTest::Generators::ScaffoldGenerator.start ["user"]
32
9
  end
33
- assert_match(/create test\/controllers\/users_controller_test.rb/m, out)
34
10
  assert File.exists? "test/controllers/users_controller_test.rb"
35
11
  contents = File.read "test/controllers/users_controller_test.rb"
36
12
  assert_match(/class UsersControllerTest/m, contents)
37
13
  end
38
14
 
39
15
  def test_scaffold_generator_spec
40
- out, err = capture_io do
16
+ assert_output(/create test\/controllers\/users_controller_test.rb/m) do
41
17
  MiniTest::Generators::ScaffoldGenerator.start ["user", "--spec"]
42
18
  end
43
- assert_match(/create test\/controllers\/users_controller_test.rb/m, out)
44
19
  assert File.exists? "test/controllers/users_controller_test.rb"
45
20
  contents = File.read "test/controllers/users_controller_test.rb"
46
21
  assert_match(/describe UsersController do/m, contents)
47
22
  end
23
+
48
24
  end
data/test/helper.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "minitest/autorun"
2
+
3
+ require "rails"
4
+ require "rails/generators"
5
+
6
+ require "active_record"
7
+
8
+ require "action_controller"
9
+ require "action_controller/railtie"
10
+
11
+ require "action_mailer"
12
+
13
+ require "minitest-rails"
14
+ require "minitest/rails"
15
+
16
+ require "fakefs/safe"
17
+
18
+ class FakeFS::File
19
+ def self.binread file
20
+ File.open(file, "rb") { |f| f.read }
21
+ end
22
+ end
23
+
24
+ class GeneratorTest < MiniTest::Unit::TestCase
25
+ def setup
26
+ Rails::Generators.no_color!
27
+ FakeFS.activate!
28
+ FakeFS::FileSystem.clone "lib/generators"
29
+ end
30
+
31
+ def teardown
32
+ FakeFS::FileSystem.clear
33
+ FakeFS.deactivate!
34
+ end
35
+ end
@@ -1,19 +1,9 @@
1
- require "minitest/autorun"
2
- require "rails"
3
-
4
- require "minitest/rails/action_controller"
5
- require "action_controller"
6
-
7
- # require "active_record/railtie"
8
- require "action_controller/railtie"
9
- # require "action_mailer/railtie"
10
- # require "active_resource/railtie"
11
- # require "sprockets/railtie"
12
- # require "rails/test_unit/railtie"
1
+ require "helper"
13
2
 
14
3
  class TestApp < Rails::Application
15
4
  end
16
5
  Rails.application = TestApp
6
+ Rails.configuration.secret_key_base = "abc123"
17
7
 
18
8
  class ApplicationController < ActionController::Base; end
19
9
  class ModelsController < ApplicationController; end
@@ -145,7 +135,7 @@ end
145
135
 
146
136
  # Nested Admin::WidgetsControllerTest
147
137
  module Admin
148
- class WidgetsControllerTest < MiniTest::Rails::ActionController::TestCase
138
+ class WidgetsControllerTest < ActionController::TestCase
149
139
  test "exists" do
150
140
  assert_kind_of Admin::WidgetsController, @controller
151
141
  end
@@ -168,7 +158,7 @@ module Admin
168
158
  end
169
159
  end
170
160
 
171
- class Admin::WidgetsControllerTest < MiniTest::Rails::ActionController::TestCase
161
+ class Admin::WidgetsControllerTest < ActionController::TestCase
172
162
  test "exists here too" do
173
163
  assert_kind_of Admin::WidgetsController, @controller
174
164
  end
@@ -1,19 +1,15 @@
1
- require "minitest/autorun"
2
- require "rails"
3
-
4
- require "minitest/rails/action_controller"
5
- require "action_controller"
1
+ require "helper"
6
2
 
7
3
  class ApplicationController < ActionController::Base; end
8
4
  class ModelsController < ApplicationController; end
9
5
 
10
6
  class TestApplicationControllerSpecType < MiniTest::Unit::TestCase
11
7
  def assert_controller actual
12
- assert_equal MiniTest::Rails::ActionController::TestCase, actual
8
+ assert_equal ActionController::TestCase, actual
13
9
  end
14
10
 
15
11
  def refute_controller actual
16
- refute_equal MiniTest::Rails::ActionController::TestCase, actual
12
+ refute_equal ActionController::TestCase, actual
17
13
  end
18
14
 
19
15
  def test_spec_type_resolves_for_class_constants
@@ -1,23 +1,24 @@
1
- require "minitest/autorun"
2
- require "rails"
3
-
4
- require "minitest/rails/action_dispatch"
1
+ require "helper"
5
2
 
6
3
  class TestActionDispatchSpecType < MiniTest::Unit::TestCase
7
4
  def assert_dispatch actual
8
- assert_equal MiniTest::Rails::ActionDispatch::IntegrationTest, actual
5
+ assert_equal ActionDispatch::IntegrationTest, actual
9
6
  end
10
7
 
11
8
  def refute_dispatch actual
12
- refute_equal MiniTest::Rails::ActionDispatch::IntegrationTest, actual
9
+ refute_equal ActionDispatch::IntegrationTest, actual
13
10
  end
14
11
 
15
12
  def test_spec_type_resolves_for_matching_acceptance_strings
16
13
  assert_dispatch MiniTest::Spec.spec_type("WidgetAcceptanceTest")
17
14
  assert_dispatch MiniTest::Spec.spec_type("Widget Acceptance Test")
15
+ assert_dispatch MiniTest::Spec.spec_type("WidgetAcceptance")
16
+ assert_dispatch MiniTest::Spec.spec_type("Widget Acceptance")
18
17
  # And is not case sensitive
19
18
  assert_dispatch MiniTest::Spec.spec_type("widgetacceptancetest")
20
19
  assert_dispatch MiniTest::Spec.spec_type("widget acceptance test")
20
+ assert_dispatch MiniTest::Spec.spec_type("widgetacceptance")
21
+ assert_dispatch MiniTest::Spec.spec_type("widget acceptance")
21
22
  end
22
23
 
23
24
  def test_spec_type_wont_match_non_space_characters_acceptance
@@ -32,17 +33,21 @@ class TestActionDispatchSpecType < MiniTest::Unit::TestCase
32
33
  def test_spec_type_resolves_for_matching_integration_strings
33
34
  assert_dispatch MiniTest::Spec.spec_type("WidgetIntegrationTest")
34
35
  assert_dispatch MiniTest::Spec.spec_type("Widget Integration Test")
36
+ assert_dispatch MiniTest::Spec.spec_type("WidgetIntegration")
37
+ assert_dispatch MiniTest::Spec.spec_type("Widget Integration")
35
38
  # And is not case sensitive
36
39
  assert_dispatch MiniTest::Spec.spec_type("widgetintegrationtest")
37
40
  assert_dispatch MiniTest::Spec.spec_type("widget integration test")
41
+ assert_dispatch MiniTest::Spec.spec_type("widgetintegration")
42
+ assert_dispatch MiniTest::Spec.spec_type("widget integration")
38
43
  end
39
44
 
40
45
  def test_spec_type_wont_match_non_space_characters_integration
41
- refute_equal MiniTest::Spec.spec_type("Widget Integration\tTest"), MiniTest::Rails::ActionDispatch::IntegrationTest
42
- refute_equal MiniTest::Spec.spec_type("Widget Integration\rTest"), MiniTest::Rails::ActionDispatch::IntegrationTest
46
+ refute_equal MiniTest::Spec.spec_type("Widget Integration\tTest"), ActionDispatch::IntegrationTest
47
+ refute_equal MiniTest::Spec.spec_type("Widget Integration\rTest"), ActionDispatch::IntegrationTest
43
48
  # TODO: Update regex so that new lines don't match.
44
- refute_equal MiniTest::Spec.spec_type("Widget Integration\nTest"), MiniTest::Rails::ActionDispatch::IntegrationTest
45
- refute_equal MiniTest::Spec.spec_type("Widget Integration\fTest"), MiniTest::Rails::ActionDispatch::IntegrationTest
46
- refute_equal MiniTest::Spec.spec_type("Widget IntegrationXTest"), MiniTest::Rails::ActionDispatch::IntegrationTest
49
+ refute_equal MiniTest::Spec.spec_type("Widget Integration\nTest"), ActionDispatch::IntegrationTest
50
+ refute_equal MiniTest::Spec.spec_type("Widget Integration\fTest"), ActionDispatch::IntegrationTest
51
+ refute_equal MiniTest::Spec.spec_type("Widget IntegrationXTest"), ActionDispatch::IntegrationTest
47
52
  end
48
53
  end