minitest-rails 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,47 @@ module MiniTest
14
14
  register_spec_type(/Controller( ?Test)?\z/i, self)
15
15
 
16
16
  include ::ActionController::TestCase::Behavior
17
+
18
+ def self.determine_default_controller_class(name)
19
+ # Override this method to support nested describes
20
+ #
21
+ # describe WidgetsController do
22
+ # describe "index" do
23
+ # it "is successful" do
24
+ # assert_response :success
25
+ # end
26
+ # end
27
+ # end
28
+ #
29
+ # Original implementation:
30
+ # name.sub(/Test$/, '').safe_constantize
31
+ # safe_constantize is not supported in Rails 3.0...
32
+ ControllerLookup.find name
33
+ end
34
+ end
35
+
36
+ module ControllerLookup
37
+ def self.find controller
38
+ # HACK: I don't love this implementation
39
+ # Please suggest a better one!
40
+ names = controller.split "::"
41
+ controller = while names.size > 0 do
42
+ # Remove "Test" if present
43
+ names.last.sub! /Test$/, ''
44
+ begin
45
+ constant = names.join("::").constantize
46
+ break(constant) if constant
47
+ rescue NameError
48
+ # do nothing
49
+ ensure
50
+ names.pop
51
+ end
52
+ end
53
+ if controller.nil?
54
+ raise ::NameError.new("Unable to resolve controller for #{name}")
55
+ end
56
+ controller
57
+ end
17
58
  end
18
59
  end
19
60
  end
@@ -1,4 +1,8 @@
1
1
  require 'minitest/spec'
2
+
3
+ # I hate this! Be sure you have installed minitest_tu_shim
4
+ require "test/unit" if RUBY_VERSION < "1.9"
5
+
2
6
  require 'active_support/testing/setup_and_teardown'
3
7
  require 'active_support/testing/assertions'
4
8
  require 'active_support/testing/deprecation'
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "minitest-rails"
5
- s.version = "0.1.2.20120726190745"
5
+ s.version = "0.1.3.20120802091804"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mike Moore"]
9
- s.date = "2012-07-27"
9
+ s.date = "2012-08-02"
10
10
  s.description = "Adds MiniTest as the default testing library in Rails 3.x"
11
11
  s.email = ["mike@blowmage.com"]
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "Manifest.txt", "README.rdoc"]
13
- s.files = [".autotest", ".gemtest", ".travis.yml", "CHANGELOG.rdoc", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "gemfiles/3.0.gemfile", "gemfiles/3.1.gemfile", "gemfiles/3.2.gemfile", "lib/generators/mini_test.rb", "lib/generators/mini_test/controller/controller_generator.rb", "lib/generators/mini_test/controller/templates/controller_spec.rb", "lib/generators/mini_test/controller/templates/controller_test.rb", "lib/generators/mini_test/helper/helper_generator.rb", "lib/generators/mini_test/helper/templates/helper_spec.rb", "lib/generators/mini_test/helper/templates/helper_test.rb", "lib/generators/mini_test/install/install_generator.rb", "lib/generators/mini_test/install/templates/test/minitest_helper.rb", "lib/generators/mini_test/integration/integration_generator.rb", "lib/generators/mini_test/integration/templates/integration_spec.rb", "lib/generators/mini_test/integration/templates/integration_test.rb", "lib/generators/mini_test/mailer/mailer_generator.rb", "lib/generators/mini_test/mailer/templates/mailer_spec.rb", "lib/generators/mini_test/mailer/templates/mailer_test.rb", "lib/generators/mini_test/model/model_generator.rb", "lib/generators/mini_test/model/templates/fixtures.yml", "lib/generators/mini_test/model/templates/model_spec.rb", "lib/generators/mini_test/model/templates/model_test.rb", "lib/generators/mini_test/scaffold/scaffold_generator.rb", "lib/generators/mini_test/scaffold/templates/controller_spec.rb", "lib/generators/mini_test/scaffold/templates/controller_test.rb", "lib/minitest-rails.rb", "lib/minitest/rails.rb", "lib/minitest/rails/action_controller.rb", "lib/minitest/rails/action_dispatch.rb", "lib/minitest/rails/action_mailer.rb", "lib/minitest/rails/action_view.rb", "lib/minitest/rails/active_support.rb", "lib/minitest/rails/declarative.rb", "lib/minitest/rails/mochaing.rb", "lib/minitest/rails/tasks/minitest.rake", "lib/minitest/rails/tasks/sub_test_task.rb", "minitest-rails.gemspec", "test/generators/test_controller_generator.rb", "test/generators/test_helper_generator.rb", "test/generators/test_install_generator.rb", "test/generators/test_mailer_generator.rb", "test/generators/test_model_generator.rb", "test/generators/test_scaffold_generator.rb", "test/rails/test_action_controller_spec_type.rb", "test/rails/test_action_dispatch_spec_type.rb", "test/rails/test_action_mailer_spec_type.rb", "test/rails/test_action_view_spec_type.rb", "test/test_minitest.rb"]
13
+ s.files = [".autotest", ".gemtest", ".travis.yml", "CHANGELOG.rdoc", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "gemfiles/3.0.gemfile", "gemfiles/3.0.gemfile.lock", "gemfiles/3.1.gemfile", "gemfiles/3.1.gemfile.lock", "gemfiles/3.2.gemfile", "gemfiles/3.2.gemfile.lock", "gemfiles/minitest_tu_shim.rb", "lib/generators/mini_test.rb", "lib/generators/mini_test/controller/controller_generator.rb", "lib/generators/mini_test/controller/templates/controller_spec.rb", "lib/generators/mini_test/controller/templates/controller_test.rb", "lib/generators/mini_test/helper/helper_generator.rb", "lib/generators/mini_test/helper/templates/helper_spec.rb", "lib/generators/mini_test/helper/templates/helper_test.rb", "lib/generators/mini_test/install/install_generator.rb", "lib/generators/mini_test/install/templates/test/minitest_helper.rb", "lib/generators/mini_test/integration/integration_generator.rb", "lib/generators/mini_test/integration/templates/integration_spec.rb", "lib/generators/mini_test/integration/templates/integration_test.rb", "lib/generators/mini_test/mailer/mailer_generator.rb", "lib/generators/mini_test/mailer/templates/mailer_spec.rb", "lib/generators/mini_test/mailer/templates/mailer_test.rb", "lib/generators/mini_test/model/model_generator.rb", "lib/generators/mini_test/model/templates/fixtures.yml", "lib/generators/mini_test/model/templates/model_spec.rb", "lib/generators/mini_test/model/templates/model_test.rb", "lib/generators/mini_test/scaffold/scaffold_generator.rb", "lib/generators/mini_test/scaffold/templates/controller_spec.rb", "lib/generators/mini_test/scaffold/templates/controller_test.rb", "lib/minitest-rails.rb", "lib/minitest/rails.rb", "lib/minitest/rails/action_controller.rb", "lib/minitest/rails/action_dispatch.rb", "lib/minitest/rails/action_mailer.rb", "lib/minitest/rails/action_view.rb", "lib/minitest/rails/active_support.rb", "lib/minitest/rails/declarative.rb", "lib/minitest/rails/mochaing.rb", "lib/minitest/rails/tasks/minitest.rake", "lib/minitest/rails/tasks/sub_test_task.rb", "minitest-rails.gemspec", "test/generators/test_controller_generator.rb", "test/generators/test_helper_generator.rb", "test/generators/test_install_generator.rb", "test/generators/test_mailer_generator.rb", "test/generators/test_model_generator.rb", "test/generators/test_scaffold_generator.rb", "test/rails/action_controller/test_controller_lookup.rb", "test/rails/action_controller/test_controllers.rb", "test/rails/action_controller/test_spec_type.rb", "test/rails/test_action_dispatch_spec_type.rb", "test/rails/test_action_mailer_spec_type.rb", "test/rails/test_action_view_spec_type.rb", "test/test_minitest.rb"]
14
14
  s.homepage = "http://blowmage.com/minitest-rails"
15
15
  s.rdoc_options = ["--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "minitest-rails"
18
18
  s.rubygems_version = "1.8.24"
19
19
  s.summary = "MiniTest integration for Rails 3.x"
20
- s.test_files = ["test/generators/test_controller_generator.rb", "test/generators/test_helper_generator.rb", "test/generators/test_install_generator.rb", "test/generators/test_mailer_generator.rb", "test/generators/test_model_generator.rb", "test/generators/test_scaffold_generator.rb", "test/rails/test_action_controller_spec_type.rb", "test/rails/test_action_dispatch_spec_type.rb", "test/rails/test_action_mailer_spec_type.rb", "test/rails/test_action_view_spec_type.rb", "test/test_minitest.rb"]
20
+ s.test_files = ["test/generators/test_controller_generator.rb", "test/generators/test_helper_generator.rb", "test/generators/test_install_generator.rb", "test/generators/test_mailer_generator.rb", "test/generators/test_model_generator.rb", "test/generators/test_scaffold_generator.rb", "test/rails/action_controller/test_controller_lookup.rb", "test/rails/action_controller/test_controllers.rb", "test/rails/action_controller/test_spec_type.rb", "test/rails/test_action_dispatch_spec_type.rb", "test/rails/test_action_mailer_spec_type.rb", "test/rails/test_action_view_spec_type.rb", "test/test_minitest.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
@@ -26,17 +26,20 @@ Gem::Specification.new do |s|
26
26
  s.add_runtime_dependency(%q<minitest>, ["~> 3.0"])
27
27
  s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
28
28
  s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
29
+ s.add_development_dependency(%q<fakefs>, ["~> 0.4"])
29
30
  s.add_development_dependency(%q<hoe>, ["~> 3.0"])
30
31
  else
31
32
  s.add_dependency(%q<minitest>, ["~> 3.0"])
32
33
  s.add_dependency(%q<rails>, ["~> 3.0"])
33
34
  s.add_dependency(%q<rdoc>, ["~> 3.10"])
35
+ s.add_dependency(%q<fakefs>, ["~> 0.4"])
34
36
  s.add_dependency(%q<hoe>, ["~> 3.0"])
35
37
  end
36
38
  else
37
39
  s.add_dependency(%q<minitest>, ["~> 3.0"])
38
40
  s.add_dependency(%q<rails>, ["~> 3.0"])
39
41
  s.add_dependency(%q<rdoc>, ["~> 3.10"])
42
+ s.add_dependency(%q<fakefs>, ["~> 0.4"])
40
43
  s.add_dependency(%q<hoe>, ["~> 3.0"])
41
44
  end
42
45
  end
@@ -6,59 +6,66 @@ require "rails/generators"
6
6
 
7
7
  require "generators/mini_test/controller/controller_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 TestControllerGenerator < 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_controller_generator
15
- text = capture(:stdout) do
30
+ out, err = capture_io do
16
31
  MiniTest::Generators::ControllerGenerator.start ["user"]
17
32
  end
18
- assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
33
+ assert_match(/create test\/controllers\/user_controller_test.rb/m, out)
19
34
  assert File.exists? "test/controllers/user_controller_test.rb"
20
- contents = open("test/controllers/user_controller_test.rb").read
35
+ contents = File.read "test/controllers/user_controller_test.rb"
21
36
  assert_match(/class UserControllerTest/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/controllers"
26
37
  end
27
38
 
28
39
  def test_namespaced_controller_generator
29
- text = capture(:stdout) do
40
+ out, err = capture_io do
30
41
  MiniTest::Generators::ControllerGenerator.start ["admin/user"]
31
42
  end
32
- assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, text)
43
+ assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, out)
33
44
  assert File.exists? "test/controllers/admin/user_controller_test.rb"
34
- contents = open("test/controllers/admin/user_controller_test.rb").read
45
+ contents = File.read "test/controllers/admin/user_controller_test.rb"
35
46
  assert_match(/class Admin::UserControllerTest/m, contents)
36
- ensure
37
- FileUtils.rm_r "test/controllers"
38
47
  end
39
48
 
40
49
  def test_controller_generator_spec
41
- text = capture(:stdout) do
50
+ out, err = capture_io do
42
51
  MiniTest::Generators::ControllerGenerator.start ["user", "--spec"]
43
52
  end
44
- assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
53
+ assert_match(/create test\/controllers\/user_controller_test.rb/m, out)
45
54
  assert File.exists? "test/controllers/user_controller_test.rb"
46
- contents = open("test/controllers/user_controller_test.rb").read
55
+ contents = File.read "test/controllers/user_controller_test.rb"
47
56
  assert_match(/describe UserController do/m, contents)
48
- ensure
49
- FileUtils.rm_r "test/controllers"
50
57
  end
51
58
 
52
59
  def test_namespaced_controller_generator_spec
53
- text = capture(:stdout) do
54
- MiniTest::Generators::ControllerGenerator.start ["admin/user", "--spec"]
60
+ FakeFS do
61
+ out, err = capture_io do
62
+ MiniTest::Generators::ControllerGenerator.start ["admin/user", "--spec"]
63
+ end
64
+ assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, out)
65
+ assert File.exists? "test/controllers/admin/user_controller_test.rb"
66
+ contents = File.read "test/controllers/admin/user_controller_test.rb"
67
+ assert_match(/describe Admin::UserController do/m, contents)
55
68
  end
56
- assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, text)
57
- assert File.exists? "test/controllers/admin/user_controller_test.rb"
58
- contents = open("test/controllers/admin/user_controller_test.rb").read
59
- assert_match(/describe Admin::UserController do/m, contents)
60
- ensure
61
- FileUtils.rm_r "test/controllers"
62
69
  end
63
70
 
64
71
  end
@@ -6,59 +6,64 @@ require "rails/generators"
6
6
 
7
7
  require "generators/mini_test/helper/helper_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 TestHelperGenerator < 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_helper_generator
15
- text = capture(:stdout) do
30
+ out, err = capture_io do
16
31
  MiniTest::Generators::HelperGenerator.start ["user"]
17
32
  end
18
- assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
33
+ assert_match(/create test\/helpers\/user_helper_test.rb/m, out)
19
34
  assert File.exists? "test/helpers/user_helper_test.rb"
20
- contents = open("test/helpers/user_helper_test.rb").read
35
+ contents = File.read "test/helpers/user_helper_test.rb"
21
36
  assert_match(/class UserHelperTest < MiniTest::Rails::ActionView::TestCase/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/helpers"
26
37
  end
27
38
 
28
39
  def test_namespaced_helper_generator
29
- text = capture(:stdout) do
40
+ out, err = capture_io do
30
41
  MiniTest::Generators::HelperGenerator.start ["admin/user"]
31
42
  end
32
- assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
43
+ assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, out)
33
44
  assert File.exists? "test/helpers/admin/user_helper_test.rb"
34
- contents = open("test/helpers/admin/user_helper_test.rb").read
45
+ contents = File.read "test/helpers/admin/user_helper_test.rb"
35
46
  assert_match(/class Admin::UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents)
36
- ensure
37
- FileUtils.rm_r "test/helpers"
38
47
  end
39
48
 
40
49
  def test_helper_generator_spec
41
- text = capture(:stdout) do
50
+ out, err = capture_io do
42
51
  MiniTest::Generators::HelperGenerator.start ["user", "--spec"]
43
52
  end
44
- assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
53
+ assert_match(/create test\/helpers\/user_helper_test.rb/m, out)
45
54
  assert File.exists? "test/helpers/user_helper_test.rb"
46
- contents = open("test/helpers/user_helper_test.rb").read
55
+ contents = File.read "test/helpers/user_helper_test.rb"
47
56
  assert_match(/describe UserHelper do/m, contents)
48
- ensure
49
- FileUtils.rm_r "test/helpers"
50
57
  end
51
58
 
52
59
  def test_namespaced_helper_generator_spec
53
- text = capture(:stdout) do
60
+ out, err = capture_io do
54
61
  MiniTest::Generators::HelperGenerator.start ["admin/user", "--spec"]
55
62
  end
56
- assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
63
+ assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, out)
57
64
  assert File.exists? "test/helpers/admin/user_helper_test.rb"
58
- contents = open("test/helpers/admin/user_helper_test.rb").read
65
+ contents = File.read "test/helpers/admin/user_helper_test.rb"
59
66
  assert_match(/describe Admin::UserHelper do/m, contents)
60
- ensure
61
- FileUtils.rm_r "test/helpers"
62
67
  end
63
68
 
64
69
  end
@@ -6,23 +6,34 @@ require "rails/generators"
6
6
 
7
7
  require "generators/mini_test/install/install_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 TestInstallGenerator < 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_install_generator
15
- text = capture(:stdout) do
30
+ out, err = capture_io do
16
31
  MiniTest::Generators::InstallGenerator.start
17
32
  end
18
- assert_match(/create test\/minitest_helper.rb/m, text)
33
+ assert_match(/create test\/minitest_helper.rb/m, out)
19
34
  assert File.exists? "test/minitest_helper.rb"
20
- contents = open("test/minitest_helper.rb").read
35
+ contents = File.read "test/minitest_helper.rb"
21
36
  assert_match(/require "minitest\/autorun"/m, contents)
22
37
  assert_match(/require "minitest\/rails"/m, contents)
23
- ensure
24
- # TODO: Don"t write the files
25
- # I agree, it would be better to mock the file getting written
26
- FileUtils.rm "test/minitest_helper.rb"
27
38
  end
28
39
  end
@@ -6,34 +6,43 @@ require "rails/generators"
6
6
 
7
7
  require "generators/mini_test/mailer/mailer_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 TestMailerGenerator < 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_mailer_generator
15
- text = capture(:stdout) do
30
+ out, err = capture_io do
16
31
  MiniTest::Generators::MailerGenerator.start ["notification"]
17
32
  end
18
- assert_match(/create test\/mailers\/notification_test.rb/m, text)
33
+ assert_match(/create test\/mailers\/notification_test.rb/m, out)
19
34
  assert File.exists? "test/mailers/notification_test.rb"
20
- contents = open("test/mailers/notification_test.rb").read
35
+ contents = File.read "test/mailers/notification_test.rb"
21
36
  assert_match(/class NotificationTest/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/mailers"
26
37
  end
27
38
 
28
39
  def test_mailer_generator_spec
29
- text = capture(:stdout) do
40
+ out, err = capture_io do
30
41
  MiniTest::Generators::MailerGenerator.start ["notification", "welcome", "--spec"]
31
42
  end
32
- assert_match(/create test\/mailers\/notification_test.rb/m, text)
43
+ assert_match(/create test\/mailers\/notification_test.rb/m, out)
33
44
  assert File.exists? "test/mailers/notification_test.rb"
34
- contents = open("test/mailers/notification_test.rb").read
45
+ contents = File.read "test/mailers/notification_test.rb"
35
46
  assert_match(/describe Notification do/m, contents)
36
- ensure
37
- FileUtils.rm_r "test/mailers"
38
47
  end
39
48
  end
@@ -6,58 +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
47
- assert_match(/create test\/fixtures\/users.yml/m, text)
54
+ assert_match(/create test\/fixtures\/users.yml/m, out)
48
55
  assert File.exists? "test/fixtures/users.yml"
49
- ensure
50
- FileUtils.rm_r "test/models"
51
- FileUtils.rm_r "test/fixtures"
52
56
  end
53
57
 
54
58
  def test_model_generator_skip_fixture
55
- text = capture(:stdout) do
59
+ out, err = capture_io do
56
60
  MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
57
61
  end
58
- refute_match(/create test\/fixtures\/users.yml/m, text)
62
+ refute_match(/create test\/fixtures\/users.yml/m, out)
59
63
  refute File.exists? "test/fixtures/users.yml"
60
- ensure
61
- FileUtils.rm_r "test/models"
62
64
  end
63
65
  end