minitest-rails 0.2 → 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 (65) hide show
  1. data/.travis.yml +4 -4
  2. data/CHANGELOG.rdoc +11 -0
  3. data/LICENSE +1 -1
  4. data/Manifest.txt +16 -13
  5. data/README.rdoc +11 -29
  6. data/Rakefile +6 -4
  7. data/gemfiles/3.0.gemfile +1 -2
  8. data/gemfiles/3.0.gemfile.lock +37 -38
  9. data/gemfiles/3.1.gemfile +1 -2
  10. data/gemfiles/3.1.gemfile.lock +40 -41
  11. data/gemfiles/3.2.gemfile +1 -2
  12. data/gemfiles/3.2.gemfile.lock +45 -45
  13. data/gemfiles/4.0.gemfile +8 -0
  14. data/gemfiles/4.0.gemfile.lock +104 -0
  15. data/lib/autotest/minitest_rails.rb +2 -1
  16. data/lib/generators/mini_test/controller/templates/controller_test.rb +1 -1
  17. data/lib/generators/mini_test/helper/templates/helper_test.rb +2 -2
  18. data/lib/generators/mini_test/install/install_generator.rb +1 -1
  19. data/lib/generators/mini_test/install/templates/test/minitest_helper.rb +3 -9
  20. data/lib/generators/mini_test/integration/integration_generator.rb +2 -2
  21. data/lib/generators/mini_test/integration/templates/integration_spec.rb +2 -2
  22. data/lib/generators/mini_test/integration/templates/integration_test.rb +1 -1
  23. data/lib/generators/mini_test/mailer/templates/mailer_test.rb +1 -1
  24. data/lib/generators/mini_test/model/templates/model_test.rb +1 -1
  25. data/lib/generators/mini_test/scaffold/scaffold_generator.rb +15 -0
  26. data/lib/generators/mini_test/scaffold/templates/controller_spec.rb +6 -6
  27. data/lib/generators/mini_test/scaffold/templates/controller_test.rb +7 -7
  28. data/lib/generators/mini_test.rb +25 -12
  29. data/lib/minitest/rails/constant_lookup.rb +54 -0
  30. data/lib/minitest/rails/tasks/minitest.rake +22 -51
  31. data/lib/minitest/rails/test_case.rb +93 -0
  32. data/lib/minitest/rails/testing.rb +39 -0
  33. data/lib/minitest/rails/version.rb +5 -0
  34. data/lib/minitest/rails.rb +109 -20
  35. data/lib/minitest-rails.rb +1 -1
  36. data/minitest-rails.gemspec +16 -16
  37. data/tasks/gemfiles.rake +24 -0
  38. data/tasks/test.rake +26 -0
  39. data/test/generators/test_controller_generator.rb +10 -39
  40. data/test/generators/test_helper_generator.rb +8 -35
  41. data/test/generators/test_install_generator.rb +4 -27
  42. data/test/generators/test_mailer_generator.rb +5 -29
  43. data/test/generators/test_model_generator.rb +7 -32
  44. data/test/generators/test_scaffold_generator.rb +5 -29
  45. data/test/helper.rb +35 -0
  46. data/test/rails/action_controller/test_controllers.rb +4 -14
  47. data/test/rails/action_controller/test_spec_type.rb +3 -7
  48. data/test/rails/{test_action_dispatch_spec_type.rb → action_dispatch/test_spec_type.rb} +16 -11
  49. data/test/rails/action_mailer/test_mailers.rb +109 -0
  50. data/test/rails/{test_action_mailer_spec_type.rb → action_mailer/test_spec_type.rb} +3 -8
  51. data/test/rails/action_view/test_helpers.rb +73 -0
  52. data/test/rails/{test_action_view_spec_type.rb → action_view/test_spec_type.rb} +3 -10
  53. data/test/rails/{test_active_support_spec_type.rb → active_support/test_spec_type.rb} +2 -7
  54. data/test/rails/test_constant_lookup.rb +58 -0
  55. data/test/test_sanity.rb +1 -2
  56. metadata +54 -49
  57. data/gemfiles/minitest_tu_shim.rb +0 -4
  58. data/lib/minitest/rails/action_controller.rb +0 -61
  59. data/lib/minitest/rails/action_dispatch.rb +0 -36
  60. data/lib/minitest/rails/action_mailer.rb +0 -19
  61. data/lib/minitest/rails/action_view.rb +0 -20
  62. data/lib/minitest/rails/active_support.rb +0 -68
  63. data/lib/minitest/rails/declarative.rb +0 -27
  64. data/lib/minitest/rails/mochaing.rb +0 -11
  65. data/test/rails/action_controller/test_controller_lookup.rb +0 -49
@@ -0,0 +1,104 @@
1
+ GIT
2
+ remote: git://github.com/rails/rails.git
3
+ revision: 0fe64f4273d055f4fbca866ea6e05bf05a76a31c
4
+ specs:
5
+ actionmailer (4.0.0.beta)
6
+ actionpack (= 4.0.0.beta)
7
+ mail (~> 2.5.3)
8
+ actionpack (4.0.0.beta)
9
+ activesupport (= 4.0.0.beta)
10
+ builder (~> 3.1.0)
11
+ erubis (~> 2.7.0)
12
+ rack (~> 1.4.3)
13
+ rack-test (~> 0.6.1)
14
+ activemodel (4.0.0.beta)
15
+ activesupport (= 4.0.0.beta)
16
+ builder (~> 3.1.0)
17
+ activerecord (4.0.0.beta)
18
+ activemodel (= 4.0.0.beta)
19
+ activerecord-deprecated_finders (= 0.0.1)
20
+ activesupport (= 4.0.0.beta)
21
+ arel (~> 3.0.2)
22
+ activesupport (4.0.0.beta)
23
+ i18n (~> 0.6)
24
+ minitest (~> 4.1)
25
+ multi_json (~> 1.3)
26
+ thread_safe (~> 0.1)
27
+ tzinfo (~> 0.3.33)
28
+ rails (4.0.0.beta)
29
+ actionmailer (= 4.0.0.beta)
30
+ actionpack (= 4.0.0.beta)
31
+ activerecord (= 4.0.0.beta)
32
+ activesupport (= 4.0.0.beta)
33
+ bundler (>= 1.3.0.pre.4, < 2.0)
34
+ railties (= 4.0.0.beta)
35
+ sprockets-rails (~> 2.0.0.rc1)
36
+ railties (4.0.0.beta)
37
+ actionpack (= 4.0.0.beta)
38
+ activesupport (= 4.0.0.beta)
39
+ rake (>= 0.8.7)
40
+ rdoc (~> 3.4)
41
+ thor (>= 0.15.4, < 2.0)
42
+
43
+ PATH
44
+ remote: /Users/blowmage/codez/minitest-rails
45
+ specs:
46
+ minitest-rails (0.5.20130110235401)
47
+ minitest (~> 4.0)
48
+ rails (>= 3.0)
49
+
50
+ GEM
51
+ remote: http://rubygems.org/
52
+ specs:
53
+ activerecord-deprecated_finders (0.0.1)
54
+ arel (3.0.2)
55
+ atomic (1.0.1)
56
+ builder (3.1.4)
57
+ erubis (2.7.0)
58
+ fakefs (0.4.2)
59
+ hike (1.2.1)
60
+ hoe (3.4.0)
61
+ rake (>= 0.8, < 11.0)
62
+ i18n (0.6.1)
63
+ json (1.7.6)
64
+ mail (2.5.3)
65
+ i18n (>= 0.4.0)
66
+ mime-types (~> 1.16)
67
+ treetop (~> 1.4.8)
68
+ mime-types (1.19)
69
+ minitest (4.4.0)
70
+ multi_json (1.5.0)
71
+ polyglot (0.3.3)
72
+ rack (1.4.3)
73
+ rack-test (0.6.2)
74
+ rack (>= 1.0)
75
+ rake (10.0.3)
76
+ rdoc (3.12)
77
+ json (~> 1.4)
78
+ sprockets (2.8.2)
79
+ hike (~> 1.2)
80
+ multi_json (~> 1.0)
81
+ rack (~> 1.0)
82
+ tilt (~> 1.1, != 1.3.0)
83
+ sprockets-rails (2.0.0.rc1)
84
+ actionpack (>= 3.0)
85
+ activesupport (>= 3.0)
86
+ sprockets (~> 2.8)
87
+ thor (0.16.0)
88
+ thread_safe (0.1.0)
89
+ atomic
90
+ tilt (1.3.3)
91
+ treetop (1.4.12)
92
+ polyglot
93
+ polyglot (>= 0.3.1)
94
+ tzinfo (0.3.35)
95
+
96
+ PLATFORMS
97
+ ruby
98
+
99
+ DEPENDENCIES
100
+ fakefs (~> 0.4)
101
+ hoe (~> 3.0)
102
+ minitest-rails!
103
+ rails!
104
+ rdoc (~> 3.10)
@@ -1,7 +1,8 @@
1
1
  require 'autotest'
2
+ require "minitest/rails/version"
2
3
 
3
4
  class Autotest::MinitestRails < Autotest
4
- VERSION = "0.2"
5
+ VERSION = MiniTest::Rails::VERSION
5
6
 
6
7
  def initialize # :nodoc:
7
8
  super
@@ -1,7 +1,7 @@
1
1
  require "minitest_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= class_name %>ControllerTest < MiniTest::Rails::ActionController::TestCase
4
+ class <%= class_name %>ControllerTest < ActionController::TestCase
5
5
  <% if actions.empty? -%>
6
6
  # test "the truth" do
7
7
  # assert true
@@ -1,10 +1,10 @@
1
1
  require "minitest_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= class_name %>HelperTest < MiniTest::Rails::ActionView::TestCase
4
+ class <%= class_name %>HelperTest < ActionView::TestCase
5
5
 
6
6
  def test_sanity
7
- flunk "Need real tests"
7
+ assert true
8
8
  end
9
9
 
10
10
  end
@@ -14,7 +14,7 @@ DESC
14
14
  end
15
15
 
16
16
  def copy_minitest_files
17
- directory 'test'
17
+ template 'test/minitest_helper.rb', File.join("test", "minitest_helper.rb")
18
18
  end
19
19
 
20
20
  end
@@ -4,22 +4,16 @@ require File.expand_path('../../config/environment', __FILE__)
4
4
  require "minitest/autorun"
5
5
  require "minitest/rails"
6
6
 
7
- # Uncomment if you want Capybara in accceptance/integration tests
7
+ # Add `gem "minitest/rails/capybara"` to the test group of your Gemfile
8
+ # and uncomment the following if you want Capybara feature tests
8
9
  # require "minitest/rails/capybara"
9
10
 
10
11
  # Uncomment if you want awesome colorful output
11
12
  # require "minitest/pride"
12
13
 
13
- class MiniTest::Rails::ActiveSupport::TestCase
14
+ class ActiveSupport::TestCase
14
15
  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
15
16
  fixtures :all
16
17
 
17
18
  # Add more helper methods to be used by all tests here...
18
19
  end
19
-
20
- # Do you want all existing Rails tests to use MiniTest::Rails?
21
- # Comment out the following and either:
22
- # A) Change the require on the existing tests to `require "minitest_helper"`
23
- # B) Require this file's code in test_helper.rb
24
-
25
- # MiniTest::Rails.override_testunit!
@@ -9,9 +9,9 @@ module MiniTest
9
9
 
10
10
  def create_test_files
11
11
  if options[:spec]
12
- template 'integration_spec.rb', File.join('test/acceptance', class_path, "#{file_name}_test.rb")
12
+ template 'integration_spec.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
13
13
  else
14
- template 'integration_test.rb', File.join('test/acceptance', class_path, "#{file_name}_test.rb")
14
+ template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
15
15
  end
16
16
  end
17
17
  end
@@ -1,7 +1,7 @@
1
1
  require "minitest_helper"
2
2
 
3
- # To be handled correctly this spec must end with "Acceptance Test"
4
- describe "<%= class_name %> Acceptance Test" do
3
+ # To be handled correctly this spec must end with "Integration Test"
4
+ describe "<%= class_name %> Integration Test" do
5
5
  # it "must be a real test" do
6
6
  # flunk "Need real tests"
7
7
  # end
@@ -1,6 +1,6 @@
1
1
  require "minitest_helper"
2
2
 
3
- class <%= class_name %>Test < MiniTest::Rails::ActionDispatch::IntegrationTest
3
+ class <%= class_name %>Test < ActionDispatch::IntegrationTest
4
4
  # test "the truth" do
5
5
  # assert true
6
6
  # end
@@ -1,7 +1,7 @@
1
1
  require "minitest_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= class_name %>Test < MiniTest::Rails::ActionMailer::TestCase
4
+ class <%= class_name %>Test < ActionMailer::TestCase
5
5
  <% actions.each do |action| -%>
6
6
  test "<%= action %>" do
7
7
  mail = <%= class_name %>.<%= action %>
@@ -1,7 +1,7 @@
1
1
  require "minitest_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= class_name %>Test < MiniTest::Rails::ActiveSupport::TestCase
4
+ class <%= class_name %>Test < ActiveSupport::TestCase
5
5
  # test "the truth" do
6
6
  # assert true
7
7
  # end
@@ -10,6 +10,8 @@ module MiniTest
10
10
 
11
11
  check_class_collision :suffix => "ControllerTest"
12
12
 
13
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
14
+
13
15
  def create_test_files
14
16
  if options[:spec]
15
17
  template "controller_spec.rb",
@@ -23,6 +25,19 @@ module MiniTest
23
25
  "#{controller_file_name}_controller_test.rb")
24
26
  end
25
27
  end
28
+
29
+ def accessible_attributes
30
+ attributes.reject(&:reference?)
31
+ end
32
+
33
+ def attributes_hash
34
+ return if accessible_attributes.empty?
35
+
36
+ accessible_attributes.map do |a|
37
+ name = a.name
38
+ key_value name, "@#{singular_table_name}.#{name}"
39
+ end.sort.join(', ')
40
+ end
26
41
  end
27
42
  end
28
43
  end
@@ -4,7 +4,7 @@ require "minitest_helper"
4
4
  describe <%= controller_class_name %>Controller do
5
5
 
6
6
  before do
7
- @<%= singular_table_name %> = <%= class_name %>.new
7
+ @<%= singular_table_name %> = <%= table_name %>(:one)
8
8
  end
9
9
 
10
10
  it "must get index" do
@@ -20,30 +20,30 @@ describe <%= controller_class_name %>Controller do
20
20
 
21
21
  it "must create <%= singular_table_name %>" do
22
22
  assert_difference('<%= class_name %>.count') do
23
- post :create, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
23
+ post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
24
24
  end
25
25
 
26
26
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
27
27
  end
28
28
 
29
29
  it "must show <%= singular_table_name %>" do
30
- get :show, <%= key_value :id, "@#{singular_table_name}.to_param" %>
30
+ get :show, <%= key_value :id, "@#{singular_table_name}" %>
31
31
  assert_response :success
32
32
  end
33
33
 
34
34
  it "must get edit" do
35
- get :edit, <%= key_value :id, "@#{singular_table_name}.to_param" %>
35
+ get :edit, <%= key_value :id, "@#{singular_table_name}" %>
36
36
  assert_response :success
37
37
  end
38
38
 
39
39
  it "must update <%= singular_table_name %>" do
40
- put :update, <%= key_value :id, "@#{singular_table_name}.to_param" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
40
+ put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
41
41
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
42
42
  end
43
43
 
44
44
  it "must destroy <%= singular_table_name %>" do
45
45
  assert_difference('<%= class_name %>.count', -1) do
46
- delete :destroy, <%= key_value :id, "@#{singular_table_name}.to_param" %>
46
+ delete :destroy, <%= key_value :id, "@#{singular_table_name}" %>
47
47
  end
48
48
 
49
49
  assert_redirected_to <%= index_helper %>_path
@@ -1,10 +1,10 @@
1
1
  require "minitest_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= controller_class_name %>ControllerTest < MiniTest::Rails::ActionController::TestCase
4
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
5
5
 
6
6
  before do
7
- @<%= singular_table_name %> = <%= class_name %>.new
7
+ @<%= singular_table_name %> = <%= table_name %>(:one)
8
8
  end
9
9
 
10
10
  def test_index
@@ -20,30 +20,30 @@ class <%= controller_class_name %>ControllerTest < MiniTest::Rails::ActionContro
20
20
 
21
21
  def test_create
22
22
  assert_difference('<%= class_name %>.count') do
23
- post :create, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
23
+ post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
24
24
  end
25
25
 
26
26
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
27
27
  end
28
28
 
29
29
  def test_show
30
- get :show, <%= key_value :id, "@#{singular_table_name}.to_param" %>
30
+ get :show, <%= key_value :id, "@#{singular_table_name}" %>
31
31
  assert_response :success
32
32
  end
33
33
 
34
34
  def test_edit
35
- get :edit, <%= key_value :id, "@#{singular_table_name}.to_param" %>
35
+ get :edit, <%= key_value :id, "@#{singular_table_name}" %>
36
36
  assert_response :success
37
37
  end
38
38
 
39
39
  def test_update
40
- put :update, <%= key_value :id, "@#{singular_table_name}.to_param" %>, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
40
+ put :update, <%= key_value :id, "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
41
41
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
42
42
  end
43
43
 
44
44
  def test_destroy
45
45
  assert_difference('<%= class_name %>.count', -1) do
46
- delete :destroy, <%= key_value :id, "@#{singular_table_name}.to_param" %>
46
+ delete :destroy, <%= key_value :id, "@#{singular_table_name}" %>
47
47
  end
48
48
 
49
49
  assert_redirected_to <%= index_helper %>_path
@@ -3,24 +3,37 @@ require 'rails/generators/named_base'
3
3
  module MiniTest
4
4
  module Generators
5
5
  class Base < ::Rails::Generators::NamedBase #:nodoc:
6
+
7
+ class_option :old_style_hash, :type => :boolean, :default => false,
8
+ :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9"
9
+
6
10
  def self.source_root
7
11
  @_minitest_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'mini_test', generator_name, 'templates'))
8
12
  end
9
13
 
10
- if ::Rails.version.to_f < 3.1
11
- protected
12
- # These methods don't exist in Rails 3.0
13
- def module_namespacing(&block)
14
- yield if block_given?
14
+ protected
15
+
16
+ # Fill in methods that might be missing depending on the version of Rails
17
+
18
+ def module_namespacing(&block)
19
+ yield if block_given?
20
+ end unless respond_to? :module_namespacing
21
+
22
+ def key_value(key, value)
23
+ if options[:old_style_hash] || RUBY_VERSION < '1.9'
24
+ ":#{key} => #{value}"
25
+ else
26
+ "#{key}: #{value}"
15
27
  end
16
- def key_value(key, value)
17
- if options[:old_style_hash] || RUBY_VERSION < '1.9'
18
- ":#{key} => #{value}"
19
- else
20
- "#{key}: #{value}"
21
- end
28
+ end unless respond_to? :key_value
29
+
30
+ def attributes_names
31
+ @attributes_names ||= attributes.each_with_object([]) do |a, names|
32
+ names << a.column_name
33
+ names << "#{a.name}_type" if a.polymorphic?
22
34
  end
23
- end
35
+ end unless respond_to? :attributes_names
36
+
24
37
  end
25
38
  end
26
39
  end
@@ -0,0 +1,54 @@
1
+ require "active_support/concern"
2
+ require "active_support/inflector"
3
+
4
+ module MiniTest
5
+ module Rails
6
+ module Testing
7
+ # Resolves a constant from a minitest spec name.
8
+ #
9
+ # Given the following spec-style test:
10
+ #
11
+ # describe WidgetsController, :index do
12
+ # describe "authenticated user" do
13
+ # describe "returns widgets" do
14
+ # it "has a controller that exists" do
15
+ # assert_kind_of WidgetsController, @controller
16
+ # end
17
+ # end
18
+ # end
19
+ # end
20
+ #
21
+ # The test will have the following name:
22
+ #
23
+ # "WidgetsController::index::authenticated user::returns widgets"
24
+ #
25
+ # The constant WidgetsController can be resolved from the name.
26
+ # The following code will resolve the constant:
27
+ #
28
+ # controller = determine_constant_from_test_name(name) do |constant|
29
+ # Class === constant && constant < ::ActionController::Metal
30
+ # end
31
+ module ConstantLookup
32
+ extend ::ActiveSupport::Concern
33
+
34
+ module ClassMethods # :nodoc:
35
+ def determine_constant_from_test_name(test_name)
36
+ names = test_name.split "::"
37
+ while names.size > 0 do
38
+ names.last.sub!(/Test$/, "")
39
+ begin
40
+ constant = names.join("::").constantize
41
+ break(constant) if yield(constant)
42
+ rescue NameError
43
+ # Constant wasn't found, move on
44
+ ensure
45
+ names.pop
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,81 +1,52 @@
1
- require 'rake/testtask'
2
- require 'minitest/rails/tasks/sub_test_task'
3
-
4
- # The default tests to run, update this list to change behavior
5
- MINITEST_TASKS = %w(models helpers controllers mailers acceptance) #views
6
-
7
- def all_directories_under_test
8
- Dir['test/*/'].map {|dir| /test\/(.+?)\//.match(dir)[1] }
9
- end
10
-
11
- def all_minitest_directories
12
- (MINITEST_TASKS + all_directories_under_test).uniq
13
- end
1
+ require "rake/testtask"
2
+ require "minitest/rails/testing"
3
+ require "minitest/rails/tasks/sub_test_task"
14
4
 
15
5
  desc "Runs minitest"
16
6
  task :test do
17
7
  # Add to existing task if exists, or create new task otherwise
18
- Rake::Task['minitest'].invoke
8
+ Rake::Task["minitest"].invoke
19
9
  end
20
10
 
21
- namespace 'test' do
11
+ namespace "test" do
22
12
  task :prepare do
23
13
  # Define here in case test_unit isn't loaded
24
14
  end
25
15
  end
26
16
 
27
- desc "Runs #{MINITEST_TASKS.join(", ")} together"
17
+ # desc "Runs default tests (#{MiniTest::Rails::Testing.default_tasks.join(', ')})"
28
18
  task :minitest do
29
- Rake::Task['minitest:default'].invoke
19
+ Rake::Task["minitest:default"].invoke
30
20
  end
31
21
 
32
- namespace 'minitest' do
22
+ namespace "minitest" do
33
23
 
34
- # Only run the default tasks defined in MINITEST_TASKS
24
+ # Only run the default tasks defined in MiniTest::Rails::Testing.default_tasks
35
25
  task :default do
36
- errors = MINITEST_TASKS.collect do |task|
37
- begin
38
- Rake::Task["minitest:#{task}"].invoke
39
- nil
40
- rescue => e
41
- { :task => "minitest:#{task}", :exception => e }
42
- end
43
- end.compact
44
-
45
- if errors.any?
46
- puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
47
- abort
48
- end
26
+ MiniTest::Rails::Testing.run_tests MiniTest::Rails::Testing.default_tasks
49
27
  end
50
28
 
51
29
  # Run all tests in all the test directories
30
+ # desc "Runs all tests"
52
31
  task :all do
53
- errors = all_minitest_directories.collect do |task|
54
- begin
55
- Rake::Task["minitest:#{task}"].invoke
56
- nil
57
- rescue => e
58
- { :task => "minitest:#{task}", :exception => e }
59
- end
60
- end.compact
61
-
62
- if errors.any?
63
- puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
64
- abort
65
- end
32
+ MiniTest::Rails::Testing.run_tests MiniTest::Rails::Testing.all_tasks
66
33
  end
67
34
 
68
- all_minitest_directories.each do |task|
69
- MiniTest::Rails::Tasks::SubTestTask.new(task => 'test:prepare') do |t|
70
- t.libs.push 'test'
71
- t.pattern = "test/#{task}/**/*_test.rb"
35
+ MiniTest::Rails::Testing.all_tasks.each do |task_dir|
36
+ unless Rake::Task.task_defined? "minitest:#{task_dir}"
37
+ # desc "Runs tests under test/#{task_dir}"
38
+ MiniTest::Rails::Tasks::SubTestTask.new(task_dir => "test:prepare") do |t|
39
+ t.libs.push "test"
40
+ t.pattern = "test/#{task_dir}/**/*_test.rb"
41
+ t.options = MiniTest::Rails::Testing.task_opts[task_dir] if MiniTest::Rails::Testing.task_opts[task_dir]
42
+ end
72
43
  end
73
44
  end
74
45
 
75
46
  end
76
47
 
77
48
  # Override the default task
78
- task :default => [] # Just in case it hasn't already been set
49
+ task :default => [] # Just in case it hasn"t already been set
79
50
  Rake::Task[:default].clear
80
- desc "Runs minitest"
51
+ desc "Runs default tests"
81
52
  task :default => "minitest"
@@ -0,0 +1,93 @@
1
+ gem "minitest" # make sure we get the gem, not stdlib
2
+ require "minitest/spec"
3
+
4
+ # I hate this! Be sure you have installed minitest_tu_shim
5
+ require "test/unit" if RUBY_VERSION < "1.9"
6
+
7
+ begin
8
+ require "active_support/testing/tagged_logging"
9
+ rescue LoadError; end
10
+ require "active_support/testing/setup_and_teardown"
11
+ require "active_support/testing/assertions"
12
+ require "active_support/testing/deprecation"
13
+ require "active_support/testing/pending"
14
+ require "active_support/testing/isolation"
15
+ require "active_support/core_ext/kernel/reporting"
16
+
17
+ begin
18
+ require 'active_support/testing/constant_lookup'
19
+ rescue LoadError; end
20
+ require "minitest/rails/constant_lookup"
21
+
22
+ begin
23
+ silence_warnings { require "mocha/setup" }
24
+ rescue LoadError
25
+ end
26
+
27
+ module MiniTest
28
+ module Rails
29
+ class TestCase < MiniTest::Spec
30
+
31
+ # This is deprecated in minitest, but I don't want to change the Rails calls to it.
32
+ # Keep it here for now, until a better way presents itself...
33
+ def assert_block msg = nil
34
+ msg = message(msg) { "Expected block to return true value" }
35
+ assert yield, msg
36
+ end
37
+
38
+ # For backward compatibility with Test::Unit
39
+ def build_message(message, template = nil, *args)
40
+ template = template.gsub('<?>', '<%s>')
41
+ message || sprintf(template, *args)
42
+ end
43
+
44
+ Assertion = MiniTest::Assertion
45
+ alias_method :method_name, :name if method_defined? :name
46
+ alias_method :method_name, :__name__ if method_defined? :__name__
47
+
48
+ $tags = {}
49
+ def self.for_tag(tag)
50
+ yield if $tags[tag]
51
+ end
52
+
53
+ include ::ActiveSupport::Testing::TaggedLogging if defined? ActiveSupport::Testing::TaggedLogging
54
+ include ::ActiveSupport::Testing::SetupAndTeardown
55
+ include ::ActiveSupport::Testing::Assertions
56
+ include ::ActiveSupport::Testing::Deprecation
57
+ include ::ActiveSupport::Testing::Pending
58
+
59
+ # Alias `it` instead of extending ActiveSupport::Testing::Declarative
60
+ class << self
61
+ alias :test :it
62
+ end
63
+
64
+ # Resolve constants from the test name when using the spec DSL
65
+ include Testing::ConstantLookup
66
+
67
+ # test/unit backwards compatibility methods
68
+ alias :assert_raise :assert_raises
69
+ alias :assert_not_empty :refute_empty
70
+ alias :assert_not_equal :refute_equal
71
+ alias :assert_not_in_delta :refute_in_delta
72
+ alias :assert_not_in_epsilon :refute_in_epsilon
73
+ alias :assert_not_includes :refute_includes
74
+ alias :assert_not_instance_of :refute_instance_of
75
+ alias :assert_not_kind_of :refute_kind_of
76
+ alias :assert_no_match :refute_match
77
+ alias :assert_not_nil :refute_nil
78
+ alias :assert_not_operator :refute_operator
79
+ alias :assert_not_predicate :refute_predicate
80
+ alias :assert_not_respond_to :refute_respond_to
81
+ alias :assert_not_same :refute_same
82
+
83
+ # Fails if the block raises an exception.
84
+ #
85
+ # assert_nothing_raised do
86
+ # ...
87
+ # end
88
+ def assert_nothing_raised(*args)
89
+ yield
90
+ end
91
+ end
92
+ end
93
+ end