minitest-rails 0.2 → 1.0.0.beta1
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.
- checksums.yaml +7 -0
- data/.travis.yml +17 -14
- data/CHANGELOG.rdoc +66 -0
- data/Gemfile +7 -0
- data/LICENSE +1 -1
- data/Manifest.txt +36 -20
- data/README.rdoc +25 -27
- data/Rakefile +10 -7
- data/gemfiles/3.0.gemfile +2 -6
- data/gemfiles/3.1.gemfile +2 -6
- data/gemfiles/3.2.gemfile +2 -6
- data/gemfiles/4.0.gemfile +4 -0
- data/lib/generators/.document +0 -0
- data/lib/generators/mini_test/controller/controller_generator.rb +0 -1
- data/lib/generators/mini_test/controller/templates/controller_spec.rb +4 -4
- data/lib/generators/mini_test/controller/templates/controller_test.rb +6 -6
- data/lib/generators/mini_test/helper/helper_generator.rb +0 -2
- data/lib/generators/mini_test/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/mini_test/helper/templates/helper_test.rb +2 -2
- data/lib/generators/mini_test/install/install_generator.rb +6 -1
- data/lib/generators/mini_test/install/templates/test_helper.rb +27 -0
- data/lib/generators/mini_test/integration/integration_generator.rb +2 -4
- data/lib/generators/mini_test/integration/templates/integration_spec.rb +6 -6
- data/lib/generators/mini_test/integration/templates/integration_test.rb +5 -5
- data/lib/generators/mini_test/mailer/mailer_generator.rb +2 -3
- data/lib/generators/mini_test/mailer/templates/mailer_spec.rb +1 -1
- data/lib/generators/mini_test/mailer/templates/mailer_test.rb +6 -6
- data/lib/generators/mini_test/model/model_generator.rb +3 -4
- data/lib/generators/mini_test/model/templates/model_spec.rb +3 -5
- data/lib/generators/mini_test/model/templates/model_test.rb +11 -5
- data/lib/generators/mini_test/route/route_generator.rb +28 -0
- data/lib/generators/mini_test/route/templates/route_spec.rb +10 -0
- data/lib/generators/mini_test/route/templates/route_test.rb +10 -0
- data/lib/generators/mini_test/scaffold/scaffold_generator.rb +15 -1
- data/lib/generators/mini_test/scaffold/templates/controller_spec.rb +14 -16
- data/lib/generators/mini_test/scaffold/templates/controller_test.rb +9 -9
- data/lib/generators/mini_test.rb +30 -14
- data/lib/minitest/rails/assertions.rb +1811 -0
- data/lib/minitest/rails/constant_lookup.rb +54 -0
- data/lib/minitest/rails/deprecated/action_controller.rb +2 -0
- data/lib/minitest/rails/deprecated/action_dispatch.rb +2 -0
- data/lib/minitest/rails/deprecated/action_mailer.rb +4 -0
- data/lib/minitest/rails/deprecated/action_view.rb +2 -0
- data/lib/minitest/rails/deprecated/active_support.rb +2 -0
- data/lib/minitest/rails/expectations.rb +659 -0
- data/lib/minitest/rails/generators.rb +18 -0
- data/lib/minitest/rails/railtie.rb +16 -0
- data/lib/minitest/rails/tasks/.document +0 -0
- data/lib/minitest/rails/tasks/minitest.rake +69 -54
- data/lib/minitest/rails/testing.rb +29 -0
- data/lib/minitest/rails/version.rb +5 -0
- data/lib/minitest/rails.rb +125 -35
- data/lib/minitest-rails.rb +2 -23
- data/minitest-rails.gemspec +26 -21
- data/tasks/test.rake +38 -0
- data/test/generators/test_controller_generator.rb +10 -39
- data/test/generators/test_helper_generator.rb +8 -35
- data/test/generators/test_install_generator.rb +24 -30
- data/test/generators/test_mailer_generator.rb +24 -29
- data/test/generators/test_model_generator.rb +31 -32
- data/test/generators/test_route_generator.rb +24 -0
- data/test/generators/test_scaffold_generator.rb +5 -29
- data/test/helper.rb +63 -0
- data/test/rails/action_controller/test_assertions.rb +46 -0
- data/test/rails/action_controller/test_controllers.rb +5 -26
- data/test/rails/action_controller/test_expectations.rb +45 -0
- data/test/rails/action_controller/test_spec_type.rb +3 -7
- data/test/rails/{test_action_dispatch_spec_type.rb → action_dispatch/test_spec_type.rb} +16 -11
- data/test/rails/action_mailer/test_mailers.rb +109 -0
- data/test/rails/{test_action_mailer_spec_type.rb → action_mailer/test_spec_type.rb} +3 -8
- data/test/rails/action_view/test_helpers.rb +73 -0
- data/test/rails/{test_action_view_spec_type.rb → action_view/test_spec_type.rb} +10 -10
- data/test/rails/active_support/test_assertions.rb +59 -0
- data/test/rails/active_support/test_expectations.rb +49 -0
- data/test/rails/{test_active_support_spec_type.rb → active_support/test_spec_type.rb} +2 -7
- data/test/rails/generators/test_spec_type.rb +36 -0
- data/test/rails/minitest_5_api_test.rb +8 -0
- data/test/rails/test_constant_lookup.rb +58 -0
- data/test/test_sanity.rb +1 -2
- metadata +84 -56
- data/gemfiles/3.0.gemfile.lock +0 -92
- data/gemfiles/3.1.gemfile.lock +0 -103
- data/gemfiles/3.2.gemfile.lock +0 -101
- data/lib/autotest/discover.rb +0 -5
- data/lib/autotest/fixtures.rb +0 -7
- data/lib/autotest/migrate.rb +0 -5
- data/lib/autotest/minitest_rails.rb +0 -62
- data/lib/generators/mini_test/install/templates/test/minitest_helper.rb +0 -25
- data/lib/minitest/rails/action_controller.rb +0 -61
- data/lib/minitest/rails/action_dispatch.rb +0 -36
- data/lib/minitest/rails/action_mailer.rb +0 -19
- data/lib/minitest/rails/action_view.rb +0 -20
- data/lib/minitest/rails/active_support.rb +0 -68
- data/lib/minitest/rails/declarative.rb +0 -27
- data/lib/minitest/rails/mochaing.rb +0 -11
- data/test/rails/action_controller/test_controller_lookup.rb +0 -49
|
@@ -1,66 +1,39 @@
|
|
|
1
|
-
require "
|
|
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
|
-
|
|
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
|
-
|
|
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 <
|
|
12
|
+
assert_match(/class UserHelperTest < ActionView::TestCase/m, contents)
|
|
37
13
|
end
|
|
38
14
|
|
|
39
15
|
def test_namespaced_helper_generator
|
|
40
|
-
|
|
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 <
|
|
21
|
+
assert_match(/class Admin::UserHelperTest < ActionView::TestCase/m, contents)
|
|
47
22
|
end
|
|
48
23
|
|
|
49
24
|
def test_helper_generator_spec
|
|
50
|
-
|
|
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
|
-
|
|
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,33 @@
|
|
|
1
|
-
require "
|
|
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
|
-
|
|
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
|
-
|
|
7
|
+
assert_output(/create test\/test_helper.rb/m) do
|
|
31
8
|
MiniTest::Generators::InstallGenerator.start
|
|
32
9
|
end
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
assert_match(/require "minitest\/
|
|
10
|
+
assert File.exists? "test/test_helper.rb"
|
|
11
|
+
contents = File.read "test/test_helper.rb"
|
|
12
|
+
assert_match(/require "rails\/test_help"/m, contents)
|
|
13
|
+
assert_match(/require "minitest\/rails"/m, contents)
|
|
14
|
+
assert_match(/fixtures :all/m, contents)
|
|
15
|
+
if Rails::VERSION::STRING >= "4.0"
|
|
16
|
+
assert_match(/ActiveRecord::Migration.check_pending\!/m, contents)
|
|
17
|
+
else
|
|
18
|
+
refute_match(/ActiveRecord::Migration.check_pending\!/m, contents)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_install_generator_without_active_record
|
|
23
|
+
assert_output(/create test\/test_helper.rb/m) do
|
|
24
|
+
MiniTest::Generators::InstallGenerator.start ["--skip-active-record"]
|
|
25
|
+
end
|
|
26
|
+
assert File.exists? "test/test_helper.rb"
|
|
27
|
+
contents = File.read "test/test_helper.rb"
|
|
28
|
+
assert_match(/require "rails\/test_help"/m, contents)
|
|
37
29
|
assert_match(/require "minitest\/rails"/m, contents)
|
|
30
|
+
refute_match(/fixtures :all/m, contents)
|
|
31
|
+
refute_match(/ActiveRecord::Migration.check_pending\!/m, contents)
|
|
38
32
|
end
|
|
39
33
|
end
|
|
@@ -1,48 +1,43 @@
|
|
|
1
|
-
require "
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
15
|
+
def test_namespaced_mailer_generator
|
|
16
|
+
assert_output(/create test\/mailers\/admin\/notification_test.rb/m) do
|
|
17
|
+
MiniTest::Generators::MailerGenerator.start ["admin/notification"]
|
|
18
|
+
end
|
|
19
|
+
assert File.exists? "test/mailers/admin/notification_test.rb"
|
|
20
|
+
contents = File.read "test/mailers/admin/notification_test.rb"
|
|
21
|
+
assert_match(/class Admin::NotificationTest/m, contents)
|
|
22
|
+
end
|
|
23
|
+
|
|
39
24
|
def test_mailer_generator_spec
|
|
40
|
-
|
|
25
|
+
assert_output(/create test\/mailers\/notification_test.rb/m) do
|
|
41
26
|
MiniTest::Generators::MailerGenerator.start ["notification", "welcome", "--spec"]
|
|
42
27
|
end
|
|
43
|
-
assert_match(/create test\/mailers\/notification_test.rb/m, out)
|
|
44
28
|
assert File.exists? "test/mailers/notification_test.rb"
|
|
45
29
|
contents = File.read "test/mailers/notification_test.rb"
|
|
46
30
|
assert_match(/describe Notification do/m, contents)
|
|
47
31
|
end
|
|
32
|
+
|
|
33
|
+
def test_namespaced_mailer_generator_spec
|
|
34
|
+
assert_output(/create test\/mailers\/admin\/notification_test.rb/m) do
|
|
35
|
+
MiniTest::Generators::MailerGenerator.start ["admin/notification", "welcome", "--spec"]
|
|
36
|
+
end
|
|
37
|
+
assert File.exists? "test/mailers/admin/notification_test.rb"
|
|
38
|
+
contents = File.read "test/mailers/admin/notification_test.rb"
|
|
39
|
+
assert_match(/describe Admin::Notification do/m, contents)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
48
43
|
end
|
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
require "
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
15
|
+
def test_namespaced_model_generator
|
|
16
|
+
assert_output(/create test\/models\/admin\/user_test.rb/m) do
|
|
17
|
+
MiniTest::Generators::ModelGenerator.start ["admin/user"]
|
|
18
|
+
end
|
|
19
|
+
assert File.exists? "test/models/admin/user_test.rb"
|
|
20
|
+
contents = File.read "test/models/admin/user_test.rb"
|
|
21
|
+
assert_match(/class Admin::UserTest/m, contents)
|
|
22
|
+
end
|
|
23
|
+
|
|
39
24
|
def test_model_generator_spec
|
|
40
|
-
|
|
25
|
+
assert_output(/create test\/models\/user_test.rb/m) do
|
|
41
26
|
MiniTest::Generators::ModelGenerator.start ["user", "--spec"]
|
|
42
27
|
end
|
|
43
|
-
assert_match(/create test\/models\/user_test.rb/m, out)
|
|
44
28
|
assert File.exists? "test/models/user_test.rb"
|
|
45
29
|
assert File.exists? "test/fixtures/users.yml"
|
|
46
30
|
contents = File.read "test/models/user_test.rb"
|
|
47
31
|
assert_match(/describe User do/m, contents)
|
|
48
32
|
end
|
|
49
33
|
|
|
34
|
+
def test_namespaced_model_generator_spec
|
|
35
|
+
assert_output(/create test\/models\/admin\/user_test.rb/m) do
|
|
36
|
+
MiniTest::Generators::ModelGenerator.start ["admin/user", "--spec"]
|
|
37
|
+
end
|
|
38
|
+
assert File.exists? "test/models/admin/user_test.rb"
|
|
39
|
+
contents = File.read "test/models/admin/user_test.rb"
|
|
40
|
+
assert_match(/describe Admin::User do/m, contents)
|
|
41
|
+
end
|
|
42
|
+
|
|
50
43
|
def test_model_generator_fixture
|
|
51
|
-
|
|
44
|
+
assert_output(/create test\/fixtures\/users.yml/m) do
|
|
52
45
|
MiniTest::Generators::ModelGenerator.start ["user"]
|
|
53
46
|
end
|
|
54
|
-
assert_match(/create test\/fixtures\/users.yml/m, out)
|
|
55
47
|
assert File.exists? "test/fixtures/users.yml"
|
|
56
48
|
end
|
|
57
49
|
|
|
50
|
+
def test_namespaced_model_generator_fixture
|
|
51
|
+
assert_output(/create test\/fixtures\/admin\/users.yml/m) do
|
|
52
|
+
MiniTest::Generators::ModelGenerator.start ["admin/user"]
|
|
53
|
+
end
|
|
54
|
+
assert File.exists? "test/fixtures/admin/users.yml"
|
|
55
|
+
end
|
|
56
|
+
|
|
58
57
|
def test_model_generator_skip_fixture
|
|
59
|
-
out,
|
|
58
|
+
out, _ = capture_io do
|
|
60
59
|
MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
|
|
61
60
|
end
|
|
62
61
|
refute_match(/create test\/fixtures\/users.yml/m, out)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
require "generators/mini_test/route/route_generator"
|
|
3
|
+
|
|
4
|
+
class TestRouteGenerator < GeneratorTest
|
|
5
|
+
|
|
6
|
+
def test_route_generator
|
|
7
|
+
assert_output(/create test\/routes\/route_test.rb/m) do
|
|
8
|
+
MiniTest::Generators::RouteGenerator.start
|
|
9
|
+
end
|
|
10
|
+
assert File.exists? "test/routes/route_test.rb"
|
|
11
|
+
contents = File.read "test/routes/route_test.rb"
|
|
12
|
+
assert_match(/class RouteTest/m, contents)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_route_generator_spec
|
|
16
|
+
assert_output(/create test\/routes\/route_test.rb/m) do
|
|
17
|
+
MiniTest::Generators::RouteGenerator.start ["--spec"]
|
|
18
|
+
end
|
|
19
|
+
assert File.exists? "test/routes/route_test.rb"
|
|
20
|
+
contents = File.read "test/routes/route_test.rb"
|
|
21
|
+
assert_match(/describe "Route Integration Test" do/m, contents)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -1,48 +1,24 @@
|
|
|
1
|
-
require "
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,63 @@
|
|
|
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 "rails/test_help"
|
|
15
|
+
require "minitest/rails"
|
|
16
|
+
|
|
17
|
+
require "fakefs/safe"
|
|
18
|
+
|
|
19
|
+
class FakeFS::File
|
|
20
|
+
def self.binread file
|
|
21
|
+
File.open(file, "rb") { |f| f.read }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class GeneratorTest < MiniTest::Unit::TestCase
|
|
26
|
+
def setup
|
|
27
|
+
Rails::Generators.no_color!
|
|
28
|
+
FakeFS.activate!
|
|
29
|
+
FakeFS::FileSystem.clone "lib/generators"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def teardown
|
|
33
|
+
FakeFS::FileSystem.clear
|
|
34
|
+
FakeFS.deactivate!
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
require "rails/test_help"
|
|
39
|
+
|
|
40
|
+
module TestApp
|
|
41
|
+
class Application < ::Rails::Application
|
|
42
|
+
config.secret_key_base = "abc123"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
TestApp::Application.initialize!
|
|
47
|
+
|
|
48
|
+
class ApplicationController < ActionController::Base; end
|
|
49
|
+
class ModelsController < ApplicationController
|
|
50
|
+
def index; render :text => "<html><head><title>Models</title></head><body><h1>All Models</h1></body></html>"; end
|
|
51
|
+
def new; redirect_to "/models"; end
|
|
52
|
+
end
|
|
53
|
+
module Admin
|
|
54
|
+
class WidgetsController < ApplicationController; end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
TestApp::Application.routes.draw do
|
|
58
|
+
# root :to => "models#index"
|
|
59
|
+
resources :models
|
|
60
|
+
namespace :admin do
|
|
61
|
+
resources :widgets
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
class TestActionControllerAssertions < ActionController::TestCase
|
|
4
|
+
tests ModelsController
|
|
5
|
+
|
|
6
|
+
def test_assert_response
|
|
7
|
+
get :index
|
|
8
|
+
assert_response :success
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_assert_redirected_to
|
|
12
|
+
get :new
|
|
13
|
+
assert_redirected_to :models
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_assert_template
|
|
17
|
+
get :index
|
|
18
|
+
assert_template :layout => false
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_routing_assertions
|
|
22
|
+
params = { :controller => "models", :action => "index" }
|
|
23
|
+
path = "/models"
|
|
24
|
+
assert_generates path, params
|
|
25
|
+
assert_recognizes params, path
|
|
26
|
+
assert_routing path, params
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_assert_dom_equal
|
|
30
|
+
apple_link = '<a href="http://www.example.com" target="_blank">Apples</a>'
|
|
31
|
+
apple_link2 = '<a target="_blank" href="http://www.example.com">Apples</a>'
|
|
32
|
+
orange_link = '<a href="http://www.example.com">Oranges</a>'
|
|
33
|
+
|
|
34
|
+
assert_dom_equal apple_link, apple_link2
|
|
35
|
+
refute_dom_equal apple_link, orange_link
|
|
36
|
+
assert_dom_not_equal apple_link, orange_link
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_assert_select
|
|
40
|
+
get :index
|
|
41
|
+
assert_select "body h1"
|
|
42
|
+
assert_select "body" do
|
|
43
|
+
assert_select "h1"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
require "
|
|
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
|
|
1
|
+
require "helper"
|
|
23
2
|
|
|
24
3
|
# ApplicationController
|
|
25
4
|
describe ApplicationController do
|
|
@@ -145,8 +124,8 @@ end
|
|
|
145
124
|
|
|
146
125
|
# Nested Admin::WidgetsControllerTest
|
|
147
126
|
module Admin
|
|
148
|
-
class WidgetsControllerTest <
|
|
149
|
-
|
|
127
|
+
class WidgetsControllerTest < ActionController::TestCase
|
|
128
|
+
def test_exists
|
|
150
129
|
assert_kind_of Admin::WidgetsController, @controller
|
|
151
130
|
end
|
|
152
131
|
end
|
|
@@ -168,8 +147,8 @@ module Admin
|
|
|
168
147
|
end
|
|
169
148
|
end
|
|
170
149
|
|
|
171
|
-
class Admin::WidgetsControllerTest <
|
|
172
|
-
|
|
150
|
+
class Admin::WidgetsControllerTest < ActionController::TestCase
|
|
151
|
+
def test_exists_here_too
|
|
173
152
|
assert_kind_of Admin::WidgetsController, @controller
|
|
174
153
|
end
|
|
175
154
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
class TestActionControllerExpectations < ActionController::TestCase
|
|
4
|
+
tests ModelsController
|
|
5
|
+
|
|
6
|
+
def test_must_respond_with
|
|
7
|
+
get :index
|
|
8
|
+
must_respond_with :success
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_must_redirect_to
|
|
12
|
+
get :new
|
|
13
|
+
must_redirect_to :models
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_must_render_template
|
|
17
|
+
get :index
|
|
18
|
+
must_render_template :layout => false
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_routing_expectations
|
|
22
|
+
params = { :controller => "models", :action => "index" }
|
|
23
|
+
path = "/models"
|
|
24
|
+
params.must_route_to path
|
|
25
|
+
path.must_route_from params
|
|
26
|
+
params.must_route_for path
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_must_dom_equal
|
|
30
|
+
apple_link = '<a href="http://www.example.com" target="_blank">Apples</a>'
|
|
31
|
+
apple_link2 = '<a target="_blank" href="http://www.example.com">Apples</a>'
|
|
32
|
+
orange_link = '<a href="http://www.example.com">Oranges</a>'
|
|
33
|
+
|
|
34
|
+
apple_link.must_dom_equal apple_link2
|
|
35
|
+
apple_link.wont_dom_equal orange_link
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_must_select
|
|
39
|
+
get :index
|
|
40
|
+
must_select "body h1"
|
|
41
|
+
must_select "body" do
|
|
42
|
+
must_select "h1"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
require "
|
|
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
|
|
8
|
+
assert_equal ActionController::TestCase, actual
|
|
13
9
|
end
|
|
14
10
|
|
|
15
11
|
def refute_controller actual
|
|
16
|
-
refute_equal
|
|
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 "
|
|
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
|
|
5
|
+
assert_equal ActionDispatch::IntegrationTest, actual
|
|
9
6
|
end
|
|
10
7
|
|
|
11
8
|
def refute_dispatch actual
|
|
12
|
-
refute_equal
|
|
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"),
|
|
42
|
-
refute_equal MiniTest::Spec.spec_type("Widget Integration\rTest"),
|
|
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"),
|
|
45
|
-
refute_equal MiniTest::Spec.spec_type("Widget Integration\fTest"),
|
|
46
|
-
refute_equal MiniTest::Spec.spec_type("Widget IntegrationXTest"),
|
|
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
|