minitest-rails 0.1 → 0.2

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 (45) hide show
  1. data/.travis.yml +19 -0
  2. data/CHANGELOG.rdoc +33 -1
  3. data/Manifest.txt +29 -7
  4. data/README.rdoc +27 -4
  5. data/Rakefile +6 -4
  6. data/gemfiles/3.0.gemfile +9 -0
  7. data/gemfiles/3.0.gemfile.lock +92 -0
  8. data/gemfiles/3.1.gemfile +9 -0
  9. data/gemfiles/3.1.gemfile.lock +103 -0
  10. data/gemfiles/3.2.gemfile +9 -0
  11. data/gemfiles/3.2.gemfile.lock +101 -0
  12. data/gemfiles/minitest_tu_shim.rb +4 -0
  13. data/lib/autotest/discover.rb +5 -0
  14. data/lib/autotest/fixtures.rb +7 -0
  15. data/lib/autotest/migrate.rb +5 -0
  16. data/lib/autotest/minitest_rails.rb +62 -0
  17. data/lib/generators/mini_test.rb +15 -0
  18. data/lib/minitest/rails/action_controller.rb +43 -1
  19. data/lib/minitest/rails/action_dispatch.rb +6 -6
  20. data/lib/minitest/rails/action_mailer.rb +3 -1
  21. data/lib/minitest/rails/action_view.rb +7 -5
  22. data/lib/minitest/rails/active_support.rb +8 -8
  23. data/lib/minitest/rails/declarative.rb +27 -0
  24. data/lib/minitest/rails/mochaing.rb +11 -0
  25. data/lib/minitest/rails/tasks/minitest.rake +48 -13
  26. data/lib/minitest/rails/tasks/sub_test_task.rb +14 -0
  27. data/lib/minitest/rails.rb +2 -2
  28. data/lib/minitest-rails.rb +1 -1
  29. data/minitest-rails.gemspec +12 -9
  30. data/test/{test_controller_generator.rb → generators/test_controller_generator.rb} +34 -27
  31. data/test/{test_helper_generator.rb → generators/test_helper_generator.rb} +32 -27
  32. data/test/{test_install_generator.rb → generators/test_install_generator.rb} +20 -9
  33. data/test/{test_mailer_generator.rb → generators/test_mailer_generator.rb} +23 -14
  34. data/test/{test_model_generator.rb → generators/test_model_generator.rb} +28 -24
  35. data/test/generators/test_scaffold_generator.rb +48 -0
  36. data/test/rails/action_controller/test_controller_lookup.rb +49 -0
  37. data/test/rails/action_controller/test_controllers.rb +223 -0
  38. data/test/rails/action_controller/test_spec_type.rb +41 -0
  39. data/test/rails/test_action_dispatch_spec_type.rb +48 -0
  40. data/test/rails/test_action_mailer_spec_type.rb +42 -0
  41. data/test/rails/test_action_view_spec_type.rb +42 -0
  42. data/test/rails/test_active_support_spec_type.rb +27 -0
  43. metadata +65 -20
  44. data/test/test_scaffold_generator.rb +0 -39
  45. /data/test/{test_minitest.rb → test_sanity.rb} +0 -0
@@ -6,56 +6,60 @@ require "rails/generators"
6
6
 
7
7
  require "generators/mini_test/model/model_generator"
8
8
 
9
- require "fileutils"
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
10
16
 
11
17
  class TestModelGenerator < MiniTest::Unit::TestCase
12
- Rails::Generators.no_color!
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
13
28
 
14
29
  def test_model_generator
15
- text = capture(:stdout) do
30
+ out, err = capture_io do
16
31
  MiniTest::Generators::ModelGenerator.start ["user"]
17
32
  end
18
- assert_match(/create test\/models\/user_test.rb/m, text)
33
+ assert_match(/create test\/models\/user_test.rb/m, out)
19
34
  assert File.exists? "test/models/user_test.rb"
20
- contents = open("test/models/user_test.rb").read
35
+ contents = File.read "test/models/user_test.rb"
21
36
  assert_match(/class UserTest/m, contents)
22
- ensure
23
- # TODO: Don"t write the files
24
- # I agree, it would be better to mock the file getting written
25
- FileUtils.rm_r "test/models"
26
- FileUtils.rm_r "test/fixtures"
27
37
  end
28
38
 
29
39
  def test_model_generator_spec
30
- text = capture(:stdout) do
40
+ out, err = capture_io do
31
41
  MiniTest::Generators::ModelGenerator.start ["user", "--spec"]
32
42
  end
33
- assert_match(/create test\/models\/user_test.rb/m, text)
43
+ assert_match(/create test\/models\/user_test.rb/m, out)
34
44
  assert File.exists? "test/models/user_test.rb"
35
45
  assert File.exists? "test/fixtures/users.yml"
36
- contents = open("test/models/user_test.rb").read
46
+ contents = File.read "test/models/user_test.rb"
37
47
  assert_match(/describe User do/m, contents)
38
- ensure
39
- FileUtils.rm_r "test/models"
40
- FileUtils.rm_r "test/fixtures"
41
48
  end
42
49
 
43
50
  def test_model_generator_fixture
44
- text = capture(:stdout) do
51
+ out, err = capture_io do
45
52
  MiniTest::Generators::ModelGenerator.start ["user"]
46
53
  end
54
+ assert_match(/create test\/fixtures\/users.yml/m, out)
47
55
  assert File.exists? "test/fixtures/users.yml"
48
- ensure
49
- FileUtils.rm_r "test/models"
50
- FileUtils.rm_r "test/fixtures"
51
56
  end
52
57
 
53
- def test_model_generator_no_fixture
54
- text = capture(:stdout) do
58
+ def test_model_generator_skip_fixture
59
+ out, err = capture_io do
55
60
  MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
56
61
  end
62
+ refute_match(/create test\/fixtures\/users.yml/m, out)
57
63
  refute File.exists? "test/fixtures/users.yml"
58
- ensure
59
- FileUtils.rm_r "test/models"
60
64
  end
61
65
  end
@@ -0,0 +1,48 @@
1
+ require "minitest/autorun"
2
+ require "minitest-rails"
3
+
4
+ require "rails"
5
+ require "rails/generators"
6
+
7
+ require "generators/mini_test/scaffold/scaffold_generator"
8
+
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
28
+
29
+ def test_scaffold_generator
30
+ out, err = capture_io do
31
+ MiniTest::Generators::ScaffoldGenerator.start ["user"]
32
+ end
33
+ assert_match(/create test\/controllers\/users_controller_test.rb/m, out)
34
+ assert File.exists? "test/controllers/users_controller_test.rb"
35
+ contents = File.read "test/controllers/users_controller_test.rb"
36
+ assert_match(/class UsersControllerTest/m, contents)
37
+ end
38
+
39
+ def test_scaffold_generator_spec
40
+ out, err = capture_io do
41
+ MiniTest::Generators::ScaffoldGenerator.start ["user", "--spec"]
42
+ end
43
+ assert_match(/create test\/controllers\/users_controller_test.rb/m, out)
44
+ assert File.exists? "test/controllers/users_controller_test.rb"
45
+ contents = File.read "test/controllers/users_controller_test.rb"
46
+ assert_match(/describe UsersController do/m, contents)
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "minitest/rails/action_controller"
5
+ require "action_controller"
6
+
7
+ class ApplicationController < ActionController::Base; end
8
+ class ModelsController < ApplicationController; end
9
+ module Admin
10
+ class WidgetsController < ApplicationController; end
11
+ end
12
+
13
+ class TestControllerLookup < MiniTest::Unit::TestCase
14
+ include MiniTest::Rails::ActionController
15
+ def test_find_application_controller
16
+ assert_equal ApplicationController, ControllerLookup.find("ApplicationController")
17
+ assert_equal ApplicationController, ControllerLookup.find("ApplicationControllerTest")
18
+ assert_equal ApplicationController, ControllerLookup.find("ApplicationController::index")
19
+ assert_equal ApplicationController, ControllerLookup.find("ApplicationController::index::authenticated")
20
+ assert_equal ApplicationController, ControllerLookup.find("ApplicationControllerTest::index")
21
+ assert_equal ApplicationController, ControllerLookup.find("ApplicationControllerTest::index::authenticated")
22
+ end
23
+
24
+ def test_find_models_controller
25
+ assert_equal ModelsController, ControllerLookup.find("ModelsController")
26
+ assert_equal ModelsController, ControllerLookup.find("ModelsControllerTest")
27
+ assert_equal ModelsController, ControllerLookup.find("ModelsController::index")
28
+ assert_equal ModelsController, ControllerLookup.find("ModelsController::index::authenticated")
29
+ assert_equal ModelsController, ControllerLookup.find("ModelsControllerTest::index")
30
+ assert_equal ModelsController, ControllerLookup.find("ModelsControllerTest::index::authenticated")
31
+ end
32
+
33
+ def test_find_admin_widgets_controller
34
+ assert_equal Admin::WidgetsController, ControllerLookup.find("Admin::WidgetsController")
35
+ assert_equal Admin::WidgetsController, ControllerLookup.find("Admin::WidgetsControllerTest")
36
+ assert_equal Admin::WidgetsController, ControllerLookup.find("Admin::WidgetsController::index")
37
+ assert_equal Admin::WidgetsController, ControllerLookup.find("Admin::WidgetsController::index::authenticated")
38
+ assert_equal Admin::WidgetsController, ControllerLookup.find("Admin::WidgetsControllerTest::index")
39
+ assert_equal Admin::WidgetsController, ControllerLookup.find("Admin::WidgetsControllerTest::index::authenticated")
40
+ end
41
+
42
+ def test_raises_when_cant_find_controller
43
+ assert_raises(NameError) { ControllerLookup.find("DoesntExistController") }
44
+ assert_raises(NameError) { ControllerLookup.find("DoesntExistControllerTest") }
45
+ assert_raises(NameError) { ControllerLookup.find("DoesntExistController::Nadda") }
46
+ assert_raises(NameError) { ControllerLookup.find("DoesntExistController::Nadda::Nope") }
47
+ assert_raises(NameError) { ControllerLookup.find("DoesntExistController::Nadda::Nope::NotHere") }
48
+ end
49
+ end
@@ -0,0 +1,223 @@
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"
13
+
14
+ class TestApp < Rails::Application
15
+ end
16
+ Rails.application = TestApp
17
+
18
+ class ApplicationController < ActionController::Base; end
19
+ class ModelsController < ApplicationController; end
20
+ module Admin
21
+ class WidgetsController < ApplicationController; end
22
+ end
23
+
24
+ # ApplicationController
25
+ describe ApplicationController do
26
+ describe "nested" do
27
+ describe "even deeper" do
28
+ it "exists" do
29
+ assert_kind_of ApplicationController, @controller
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ describe ApplicationController, :index do
36
+ describe "nested" do
37
+ describe "even deeper" do
38
+ it "exists" do
39
+ assert_kind_of ApplicationController, @controller
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ describe ApplicationController, "unauthenticated user" do
46
+ describe "nested" do
47
+ describe "even deeper" do
48
+ it "exists" do
49
+ assert_kind_of ApplicationController, @controller
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "ApplicationControllerTest" do
56
+ describe "nested" do
57
+ describe "even deeper" do
58
+ it "exists" do
59
+ assert_kind_of ApplicationController, @controller
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "ApplicationControllerTest", :index do
66
+ describe "nested" do
67
+ describe "even deeper" do
68
+ it "exists" do
69
+ assert_kind_of ApplicationController, @controller
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "ApplicationControllerTest", "unauthenticated user" do
76
+ describe "nested" do
77
+ describe "even deeper" do
78
+ it "exists" do
79
+ assert_kind_of ApplicationController, @controller
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ # ModelsController
86
+ describe ModelsController do
87
+ describe "nested" do
88
+ describe "even deeper" do
89
+ it "exists" do
90
+ assert_kind_of ModelsController, @controller
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ describe ModelsController, :index do
97
+ describe "nested" do
98
+ describe "even deeper" do
99
+ it "exists" do
100
+ assert_kind_of ModelsController, @controller
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ describe ModelsController, "unauthenticated user" do
107
+ describe "nested" do
108
+ describe "even deeper" do
109
+ it "exists" do
110
+ assert_kind_of ModelsController, @controller
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "ModelsControllerTest" do
117
+ describe "nested" do
118
+ describe "even deeper" do
119
+ it "exists" do
120
+ assert_kind_of ModelsController, @controller
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "ModelsControllerTest", :index do
127
+ describe "nested" do
128
+ describe "even deeper" do
129
+ it "exists" do
130
+ assert_kind_of ModelsController, @controller
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "ModelsControllerTest", "unauthenticated user" do
137
+ describe "nested" do
138
+ describe "even deeper" do
139
+ it "exists" do
140
+ assert_kind_of ModelsController, @controller
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ # Nested Admin::WidgetsControllerTest
147
+ module Admin
148
+ class WidgetsControllerTest < MiniTest::Rails::ActionController::TestCase
149
+ test "exists" do
150
+ assert_kind_of Admin::WidgetsController, @controller
151
+ end
152
+ end
153
+
154
+ describe WidgetsController do
155
+ describe "index" do
156
+ it "respond successful" do
157
+ assert_kind_of Admin::WidgetsController, @controller
158
+ end
159
+ end
160
+ end
161
+
162
+ describe WidgetsController, "unauthenticated users" do
163
+ describe "index" do
164
+ it "respond successful" do
165
+ assert_kind_of Admin::WidgetsController, @controller
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ class Admin::WidgetsControllerTest < MiniTest::Rails::ActionController::TestCase
172
+ test "exists here too" do
173
+ assert_kind_of Admin::WidgetsController, @controller
174
+ end
175
+ end
176
+
177
+ describe Admin::WidgetsController do
178
+ describe "index" do
179
+ it "respond successful" do
180
+ assert_kind_of Admin::WidgetsController, @controller
181
+ end
182
+ end
183
+ end
184
+
185
+ describe Admin::WidgetsController, "unauthenticated users" do
186
+ describe "index" do
187
+ it "respond successful" do
188
+ assert_kind_of Admin::WidgetsController, @controller
189
+ end
190
+ end
191
+ end
192
+
193
+ describe "Admin::WidgetsController" do
194
+ describe "index" do
195
+ it "respond successful" do
196
+ assert_kind_of Admin::WidgetsController, @controller
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "Admin::WidgetsControllerTest" do
202
+ describe "index" do
203
+ it "respond successful" do
204
+ assert_kind_of Admin::WidgetsController, @controller
205
+ end
206
+ end
207
+ end
208
+
209
+ describe "Admin::WidgetsController", "unauthenticated users" do
210
+ describe "index" do
211
+ it "respond successful" do
212
+ assert_kind_of Admin::WidgetsController, @controller
213
+ end
214
+ end
215
+ end
216
+
217
+ describe "Admin::WidgetsControllerTest", "unauthenticated users" do
218
+ describe "index" do
219
+ it "respond successful" do
220
+ assert_kind_of Admin::WidgetsController, @controller
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,41 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "minitest/rails/action_controller"
5
+ require "action_controller"
6
+
7
+ class ApplicationController < ActionController::Base; end
8
+ class ModelsController < ApplicationController; end
9
+
10
+ class TestApplicationControllerSpecType < MiniTest::Unit::TestCase
11
+ def assert_controller actual
12
+ assert_equal MiniTest::Rails::ActionController::TestCase, actual
13
+ end
14
+
15
+ def refute_controller actual
16
+ refute_equal MiniTest::Rails::ActionController::TestCase, actual
17
+ end
18
+
19
+ def test_spec_type_resolves_for_class_constants
20
+ assert_controller MiniTest::Spec.spec_type(ApplicationController)
21
+ assert_controller MiniTest::Spec.spec_type(ModelsController)
22
+ end
23
+
24
+ def test_spec_type_resolves_for_matching_strings
25
+ assert_controller MiniTest::Spec.spec_type("WidgetController")
26
+ assert_controller MiniTest::Spec.spec_type("WidgetControllerTest")
27
+ assert_controller MiniTest::Spec.spec_type("Widget Controller Test")
28
+ # And is not case sensitive
29
+ assert_controller MiniTest::Spec.spec_type("widgetcontroller")
30
+ assert_controller MiniTest::Spec.spec_type("widgetcontrollertest")
31
+ assert_controller MiniTest::Spec.spec_type("widget controller test")
32
+ end
33
+
34
+ def test_spec_type_wont_match_non_space_characters
35
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\tTest")
36
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\rTest")
37
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\nTest")
38
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\fTest")
39
+ refute_controller MiniTest::Spec.spec_type("Widget ControllerXTest")
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "minitest/rails/action_dispatch"
5
+
6
+ class TestActionDispatchSpecType < MiniTest::Unit::TestCase
7
+ def assert_dispatch actual
8
+ assert_equal MiniTest::Rails::ActionDispatch::IntegrationTest, actual
9
+ end
10
+
11
+ def refute_dispatch actual
12
+ refute_equal MiniTest::Rails::ActionDispatch::IntegrationTest, actual
13
+ end
14
+
15
+ def test_spec_type_resolves_for_matching_acceptance_strings
16
+ assert_dispatch MiniTest::Spec.spec_type("WidgetAcceptanceTest")
17
+ assert_dispatch MiniTest::Spec.spec_type("Widget Acceptance Test")
18
+ # And is not case sensitive
19
+ assert_dispatch MiniTest::Spec.spec_type("widgetacceptancetest")
20
+ assert_dispatch MiniTest::Spec.spec_type("widget acceptance test")
21
+ end
22
+
23
+ def test_spec_type_wont_match_non_space_characters_acceptance
24
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\tTest")
25
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\rTest")
26
+ # TODO: Update regex so that new lines don't match.
27
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\nTest")
28
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\fTest")
29
+ refute_dispatch MiniTest::Spec.spec_type("Widget AcceptanceXTest")
30
+ end
31
+
32
+ def test_spec_type_resolves_for_matching_integration_strings
33
+ assert_dispatch MiniTest::Spec.spec_type("WidgetIntegrationTest")
34
+ assert_dispatch MiniTest::Spec.spec_type("Widget Integration Test")
35
+ # And is not case sensitive
36
+ assert_dispatch MiniTest::Spec.spec_type("widgetintegrationtest")
37
+ assert_dispatch MiniTest::Spec.spec_type("widget integration test")
38
+ end
39
+
40
+ 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
43
+ # 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
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "action_mailer/test_helper"
5
+ require "minitest/rails/action_mailer"
6
+ require "action_mailer"
7
+
8
+ class NotificationMailer < ActionMailer::Base; end
9
+ class Notifications < ActionMailer::Base; end
10
+
11
+ class TestActionMailerSpecType < MiniTest::Unit::TestCase
12
+ def assert_mailer actual
13
+ assert_equal MiniTest::Rails::ActionMailer::TestCase, actual
14
+ end
15
+
16
+ def refute_mailer actual
17
+ refute_equal MiniTest::Rails::ActionMailer::TestCase, actual
18
+ end
19
+
20
+ def test_spec_type_resolves_for_class_constants
21
+ assert_mailer MiniTest::Spec.spec_type(NotificationMailer)
22
+ assert_mailer MiniTest::Spec.spec_type(Notifications)
23
+ end
24
+
25
+ def test_spec_type_resolves_for_matching_strings
26
+ assert_mailer MiniTest::Spec.spec_type("WidgetMailer")
27
+ assert_mailer MiniTest::Spec.spec_type("WidgetMailerTest")
28
+ assert_mailer MiniTest::Spec.spec_type("Widget Mailer Test")
29
+ # And is not case sensitive
30
+ assert_mailer MiniTest::Spec.spec_type("widgetmailer")
31
+ assert_mailer MiniTest::Spec.spec_type("widgetmailertest")
32
+ assert_mailer MiniTest::Spec.spec_type("widget mailer test")
33
+ end
34
+
35
+ def test_spec_type_wont_match_non_space_characters
36
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\tTest")
37
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\rTest")
38
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\nTest")
39
+ refute_mailer MiniTest::Spec.spec_type("Widget Mailer\fTest")
40
+ refute_mailer MiniTest::Spec.spec_type("Widget MailerXTest")
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "minitest/rails/action_view"
5
+
6
+ class TestActionViewSpecType < MiniTest::Unit::TestCase
7
+ def assert_view actual
8
+ assert_equal MiniTest::Rails::ActionView::TestCase, actual
9
+ end
10
+
11
+ def refute_view actual
12
+ refute_equal MiniTest::Rails::ActionView::TestCase, actual
13
+ end
14
+
15
+ def test_spec_type_resolves_for_matching_helper_strings
16
+ assert_view MiniTest::Spec.spec_type("WidgetHelper")
17
+ assert_view MiniTest::Spec.spec_type("WidgetHelperTest")
18
+ assert_view MiniTest::Spec.spec_type("Widget Helper Test")
19
+ # And is not case sensitive
20
+ assert_view MiniTest::Spec.spec_type("widgethelper")
21
+ assert_view MiniTest::Spec.spec_type("widgethelpertest")
22
+ assert_view MiniTest::Spec.spec_type("widget helper test")
23
+ end
24
+
25
+ def test_spec_type_resolves_for_matching_view_strings
26
+ assert_view MiniTest::Spec.spec_type("WidgetView")
27
+ assert_view MiniTest::Spec.spec_type("WidgetViewTest")
28
+ assert_view MiniTest::Spec.spec_type("Widget View Test")
29
+ # And is not case sensitive
30
+ assert_view MiniTest::Spec.spec_type("widgetview")
31
+ assert_view MiniTest::Spec.spec_type("widgetviewtest")
32
+ assert_view MiniTest::Spec.spec_type("widget view test")
33
+ end
34
+
35
+ def test_spec_type_wont_match_non_space_characters
36
+ refute_view MiniTest::Spec.spec_type("Widget Helper\tTest")
37
+ refute_view MiniTest::Spec.spec_type("Widget Helper\rTest")
38
+ refute_view MiniTest::Spec.spec_type("Widget Helper\nTest")
39
+ refute_view MiniTest::Spec.spec_type("Widget Helper\fTest")
40
+ refute_view MiniTest::Spec.spec_type("Widget HelperXTest")
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "active_record"
5
+ load "minitest/rails/active_support.rb" # Force reload
6
+ # Not sure why we need to reload, but we do...
7
+
8
+ class SomeRandomModel < ActiveRecord::Base; end
9
+
10
+ class TestActiveSupportSpecType < MiniTest::Unit::TestCase
11
+
12
+ def assert_support actual
13
+ assert_equal MiniTest::Rails::ActiveSupport::TestCase, actual
14
+ end
15
+
16
+ def assert_spec actual
17
+ assert_equal MiniTest::Spec, actual
18
+ end
19
+
20
+ def test_spec_type_resolves_for_actitive_record_constants
21
+ assert_support MiniTest::Spec.spec_type(SomeRandomModel)
22
+ end
23
+
24
+ def test_spec_type_doesnt_resolve_random_strings
25
+ assert_spec MiniTest::Spec.spec_type("Unmatched String")
26
+ end
27
+ end