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.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +17 -14
  3. data/CHANGELOG.rdoc +66 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +1 -1
  6. data/Manifest.txt +36 -20
  7. data/README.rdoc +25 -27
  8. data/Rakefile +10 -7
  9. data/gemfiles/3.0.gemfile +2 -6
  10. data/gemfiles/3.1.gemfile +2 -6
  11. data/gemfiles/3.2.gemfile +2 -6
  12. data/gemfiles/4.0.gemfile +4 -0
  13. data/lib/generators/.document +0 -0
  14. data/lib/generators/mini_test/controller/controller_generator.rb +0 -1
  15. data/lib/generators/mini_test/controller/templates/controller_spec.rb +4 -4
  16. data/lib/generators/mini_test/controller/templates/controller_test.rb +6 -6
  17. data/lib/generators/mini_test/helper/helper_generator.rb +0 -2
  18. data/lib/generators/mini_test/helper/templates/helper_spec.rb +1 -1
  19. data/lib/generators/mini_test/helper/templates/helper_test.rb +2 -2
  20. data/lib/generators/mini_test/install/install_generator.rb +6 -1
  21. data/lib/generators/mini_test/install/templates/test_helper.rb +27 -0
  22. data/lib/generators/mini_test/integration/integration_generator.rb +2 -4
  23. data/lib/generators/mini_test/integration/templates/integration_spec.rb +6 -6
  24. data/lib/generators/mini_test/integration/templates/integration_test.rb +5 -5
  25. data/lib/generators/mini_test/mailer/mailer_generator.rb +2 -3
  26. data/lib/generators/mini_test/mailer/templates/mailer_spec.rb +1 -1
  27. data/lib/generators/mini_test/mailer/templates/mailer_test.rb +6 -6
  28. data/lib/generators/mini_test/model/model_generator.rb +3 -4
  29. data/lib/generators/mini_test/model/templates/model_spec.rb +3 -5
  30. data/lib/generators/mini_test/model/templates/model_test.rb +11 -5
  31. data/lib/generators/mini_test/route/route_generator.rb +28 -0
  32. data/lib/generators/mini_test/route/templates/route_spec.rb +10 -0
  33. data/lib/generators/mini_test/route/templates/route_test.rb +10 -0
  34. data/lib/generators/mini_test/scaffold/scaffold_generator.rb +15 -1
  35. data/lib/generators/mini_test/scaffold/templates/controller_spec.rb +14 -16
  36. data/lib/generators/mini_test/scaffold/templates/controller_test.rb +9 -9
  37. data/lib/generators/mini_test.rb +30 -14
  38. data/lib/minitest/rails/assertions.rb +1811 -0
  39. data/lib/minitest/rails/constant_lookup.rb +54 -0
  40. data/lib/minitest/rails/deprecated/action_controller.rb +2 -0
  41. data/lib/minitest/rails/deprecated/action_dispatch.rb +2 -0
  42. data/lib/minitest/rails/deprecated/action_mailer.rb +4 -0
  43. data/lib/minitest/rails/deprecated/action_view.rb +2 -0
  44. data/lib/minitest/rails/deprecated/active_support.rb +2 -0
  45. data/lib/minitest/rails/expectations.rb +659 -0
  46. data/lib/minitest/rails/generators.rb +18 -0
  47. data/lib/minitest/rails/railtie.rb +16 -0
  48. data/lib/minitest/rails/tasks/.document +0 -0
  49. data/lib/minitest/rails/tasks/minitest.rake +69 -54
  50. data/lib/minitest/rails/testing.rb +29 -0
  51. data/lib/minitest/rails/version.rb +5 -0
  52. data/lib/minitest/rails.rb +125 -35
  53. data/lib/minitest-rails.rb +2 -23
  54. data/minitest-rails.gemspec +26 -21
  55. data/tasks/test.rake +38 -0
  56. data/test/generators/test_controller_generator.rb +10 -39
  57. data/test/generators/test_helper_generator.rb +8 -35
  58. data/test/generators/test_install_generator.rb +24 -30
  59. data/test/generators/test_mailer_generator.rb +24 -29
  60. data/test/generators/test_model_generator.rb +31 -32
  61. data/test/generators/test_route_generator.rb +24 -0
  62. data/test/generators/test_scaffold_generator.rb +5 -29
  63. data/test/helper.rb +63 -0
  64. data/test/rails/action_controller/test_assertions.rb +46 -0
  65. data/test/rails/action_controller/test_controllers.rb +5 -26
  66. data/test/rails/action_controller/test_expectations.rb +45 -0
  67. data/test/rails/action_controller/test_spec_type.rb +3 -7
  68. data/test/rails/{test_action_dispatch_spec_type.rb → action_dispatch/test_spec_type.rb} +16 -11
  69. data/test/rails/action_mailer/test_mailers.rb +109 -0
  70. data/test/rails/{test_action_mailer_spec_type.rb → action_mailer/test_spec_type.rb} +3 -8
  71. data/test/rails/action_view/test_helpers.rb +73 -0
  72. data/test/rails/{test_action_view_spec_type.rb → action_view/test_spec_type.rb} +10 -10
  73. data/test/rails/active_support/test_assertions.rb +59 -0
  74. data/test/rails/active_support/test_expectations.rb +49 -0
  75. data/test/rails/{test_active_support_spec_type.rb → active_support/test_spec_type.rb} +2 -7
  76. data/test/rails/generators/test_spec_type.rb +36 -0
  77. data/test/rails/minitest_5_api_test.rb +8 -0
  78. data/test/rails/test_constant_lookup.rb +58 -0
  79. data/test/test_sanity.rb +1 -2
  80. metadata +84 -56
  81. data/gemfiles/3.0.gemfile.lock +0 -92
  82. data/gemfiles/3.1.gemfile.lock +0 -103
  83. data/gemfiles/3.2.gemfile.lock +0 -101
  84. data/lib/autotest/discover.rb +0 -5
  85. data/lib/autotest/fixtures.rb +0 -7
  86. data/lib/autotest/migrate.rb +0 -5
  87. data/lib/autotest/minitest_rails.rb +0 -62
  88. data/lib/generators/mini_test/install/templates/test/minitest_helper.rb +0 -25
  89. data/lib/minitest/rails/action_controller.rb +0 -61
  90. data/lib/minitest/rails/action_dispatch.rb +0 -36
  91. data/lib/minitest/rails/action_mailer.rb +0 -19
  92. data/lib/minitest/rails/action_view.rb +0 -20
  93. data/lib/minitest/rails/active_support.rb +0 -68
  94. data/lib/minitest/rails/declarative.rb +0 -27
  95. data/lib/minitest/rails/mochaing.rb +0 -11
  96. data/test/rails/action_controller/test_controller_lookup.rb +0 -49
@@ -5,15 +5,14 @@ module MiniTest
5
5
  class ModelGenerator < Base
6
6
  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
7
7
  class_option :fixture, :type => :boolean, :default => true, :desc => "Create fixture file"
8
- class_option :spec, :type => :boolean, :default => false, :desc => "Use MiniTest::Spec DSL"
9
8
 
10
9
  check_class_collision :suffix => "Test"
11
10
 
12
11
  def create_test_file
13
12
  if options[:spec]
14
- template "model_spec.rb", "test/models/#{file_name}_test.rb"
13
+ template "model_spec.rb", File.join("test","models", class_path, "#{file_name}_test.rb")
15
14
  else
16
- template "model_test.rb", "test/models/#{file_name}_test.rb"
15
+ template "model_test.rb", File.join("test","models", class_path, "#{file_name}_test.rb")
17
16
  end
18
17
  end
19
18
 
@@ -21,7 +20,7 @@ module MiniTest
21
20
 
22
21
  def create_fixture_file
23
22
  if options[:fixture] && options[:fixture_replacement].nil?
24
- template "fixtures.yml", "test/fixtures/#{plural_file_name}.yml"
23
+ template "fixtures.yml", File.join("test","fixtures", class_path, "#{plural_file_name}.yml")
25
24
  end
26
25
  end
27
26
  end
@@ -1,13 +1,11 @@
1
- require "minitest_helper"
1
+ require "test_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  describe <%= class_name %> do
5
- before do
6
- @<%= file_name %> = <%= class_name %>.new
7
- end
5
+ let(:<%= file_name %>) { <%= class_name %>.new }
8
6
 
9
7
  it "must be valid" do
10
- @<%= file_name %>.valid?.must_equal true
8
+ <%= file_name %>.must_be :valid?
11
9
  end
12
10
  end
13
11
  <% end -%>
@@ -1,9 +1,15 @@
1
- require "minitest_helper"
1
+ require "test_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- class <%= class_name %>Test < MiniTest::Rails::ActiveSupport::TestCase
5
- # test "the truth" do
6
- # assert true
7
- # end
4
+ class <%= class_name %>Test < ActiveSupport::TestCase
5
+
6
+ def <%= file_name %>
7
+ @<%= file_name %> ||= <%= class_name %>.new
8
+ end
9
+
10
+ def test_valid
11
+ assert <%= file_name %>.valid?
12
+ end
13
+
8
14
  end
9
15
  <% end -%>
@@ -0,0 +1,28 @@
1
+ require "generators/mini_test"
2
+
3
+ module MiniTest
4
+ module Generators
5
+ class RouteGenerator < ::Rails::Generators::Base
6
+
7
+ class_option :spec, :type => :boolean, :default => false,
8
+ :desc => "Use MiniTest::Spec DSL"
9
+
10
+ desc <<DESC
11
+ Description:
12
+ Creates a route test.
13
+ DESC
14
+
15
+ def self.source_root
16
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
17
+ end
18
+
19
+ def create_test_files
20
+ if options[:spec]
21
+ template "route_spec.rb", File.join("test", "routes", "route_test.rb")
22
+ else
23
+ template "route_test.rb", File.join("test", "routes", "route_test.rb")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+
3
+ # Add the following to your Rake file to test routes by default:
4
+ # MiniTest::Rails::Testing.default_tasks << "routes"
5
+
6
+ describe "Route Integration Test" do
7
+ it "route root" do
8
+ assert_routing "/", controller: "home", action: "show"
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+
3
+ # Add the following to your Rake file to test routes by default:
4
+ # MiniTest::Rails::Testing.default_tasks << "routes"
5
+
6
+ class RouteTest < ActionDispatch::IntegrationTest
7
+ def test_root
8
+ assert_routing "/", controller: "home", action: "show"
9
+ end
10
+ end
@@ -6,10 +6,11 @@ module MiniTest
6
6
  class ScaffoldGenerator < Base
7
7
  include ::Rails::Generators::ResourceHelpers
8
8
  argument :actions, :type => :array, :default => [], :banner => "action action"
9
- class_option :spec, :type => :boolean, :default => false, :desc => "Use MiniTest::Spec DSL"
10
9
 
11
10
  check_class_collision :suffix => "ControllerTest"
12
11
 
12
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
13
+
13
14
  def create_test_files
14
15
  if options[:spec]
15
16
  template "controller_spec.rb",
@@ -23,6 +24,19 @@ module MiniTest
23
24
  "#{controller_file_name}_controller_test.rb")
24
25
  end
25
26
  end
27
+
28
+ def accessible_attributes
29
+ attributes.reject(&:reference?)
30
+ end
31
+
32
+ def attributes_hash
33
+ return if accessible_attributes.empty?
34
+
35
+ accessible_attributes.map do |a|
36
+ name = a.name
37
+ key_value name, "@#{singular_table_name}.#{name}"
38
+ end.sort.join(', ')
39
+ end
26
40
  end
27
41
  end
28
42
  end
@@ -1,49 +1,47 @@
1
- require "minitest_helper"
1
+ require "test_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  describe <%= controller_class_name %>Controller do
5
5
 
6
- before do
7
- @<%= singular_table_name %> = <%= class_name %>.new
8
- end
6
+ let(:<%= singular_table_name %>) { <%= table_name %> :one }
9
7
 
10
- it "must get index" do
8
+ it "gets index" do
11
9
  get :index
12
10
  assert_response :success
13
11
  assert_not_nil assigns(:<%= table_name %>)
14
12
  end
15
13
 
16
- it "must get new" do
14
+ it "gets new" do
17
15
  get :new
18
16
  assert_response :success
19
17
  end
20
18
 
21
- it "must create <%= singular_table_name %>" do
19
+ it "creates <%= singular_table_name %>" do
22
20
  assert_difference('<%= class_name %>.count') do
23
- post :create, <%= key_value singular_table_name, "@#{singular_table_name}.attributes" %>
21
+ post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
24
22
  end
25
23
 
26
24
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
27
25
  end
28
26
 
29
- it "must show <%= singular_table_name %>" do
30
- get :show, <%= key_value :id, "@#{singular_table_name}.to_param" %>
27
+ it "shows <%= singular_table_name %>" do
28
+ get :show, <%= key_value :id, "#{singular_table_name}" %>
31
29
  assert_response :success
32
30
  end
33
31
 
34
- it "must get edit" do
35
- get :edit, <%= key_value :id, "@#{singular_table_name}.to_param" %>
32
+ it "gets edit" do
33
+ get :edit, <%= key_value :id, "#{singular_table_name}" %>
36
34
  assert_response :success
37
35
  end
38
36
 
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" %>
37
+ it "updates <%= singular_table_name %>" do
38
+ put :update, <%= key_value :id, "#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
41
39
  assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
42
40
  end
43
41
 
44
- it "must destroy <%= singular_table_name %>" do
42
+ it "destroys <%= singular_table_name %>" do
45
43
  assert_difference('<%= class_name %>.count', -1) do
46
- delete :destroy, <%= key_value :id, "@#{singular_table_name}.to_param" %>
44
+ delete :destroy, <%= key_value :id, "#{singular_table_name}" %>
47
45
  end
48
46
 
49
47
  assert_redirected_to <%= index_helper %>_path
@@ -1,10 +1,10 @@
1
- require "minitest_helper"
1
+ require "test_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
- before do
7
- @<%= singular_table_name %> = <%= class_name %>.new
6
+ def <%= singular_table_name %>
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,40 @@ require 'rails/generators/named_base'
3
3
  module MiniTest
4
4
  module Generators
5
5
  class Base < ::Rails::Generators::NamedBase #:nodoc:
6
- def self.source_root
7
- @_minitest_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'mini_test', generator_name, 'templates'))
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
+
10
+ class_option :spec, :type => :boolean, :default => false,
11
+ :desc => "Use MiniTest::Spec DSL"
12
+
13
+ def self.default_source_root
14
+ File.expand_path(File.join(File.dirname(__FILE__), 'mini_test', generator_name, 'templates'))
8
15
  end
9
16
 
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?
17
+ protected
18
+
19
+ # Fill in methods that might be missing depending on the version of Rails
20
+
21
+ def module_namespacing(&block)
22
+ yield if block_given?
23
+ end unless respond_to? :module_namespacing
24
+
25
+ def key_value(key, value)
26
+ if options[:old_style_hash] || RUBY_VERSION < '1.9'
27
+ ":#{key} => #{value}"
28
+ else
29
+ "#{key}: #{value}"
15
30
  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
31
+ end unless respond_to? :key_value
32
+
33
+ def attributes_names
34
+ @attributes_names ||= attributes.each_with_object([]) do |a, names|
35
+ names << a.column_name
36
+ names << "#{a.name}_type" if a.polymorphic?
22
37
  end
23
- end
38
+ end unless respond_to? :attributes_names
39
+
24
40
  end
25
41
  end
26
42
  end