shoulda-matchers 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +8 -0
  5. data/Appraisals +82 -33
  6. data/Gemfile +18 -2
  7. data/Gemfile.lock +13 -1
  8. data/NEWS.md +27 -2
  9. data/README.md +83 -1329
  10. data/Rakefile +118 -1
  11. data/cucumber.yml +1 -0
  12. data/doc_config/gh-pages/index.html.erb +9 -0
  13. data/doc_config/yard/setup.rb +22 -0
  14. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
  15. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
  18. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
  19. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
  20. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
  21. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
  22. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +298 -0
  23. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
  24. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
  25. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
  26. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
  27. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
  28. data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
  29. data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
  30. data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
  31. data/doc_config/yard/templates/default/layout/html/setup.rb +40 -0
  32. data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
  33. data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
  34. data/docs.watchr +5 -0
  35. data/features/rails_integration.feature +32 -0
  36. data/features/step_definitions/rails_steps.rb +55 -9
  37. data/features/support/env.rb +1 -0
  38. data/gemfiles/3.0.gemfile +13 -1
  39. data/gemfiles/3.0.gemfile.lock +13 -1
  40. data/gemfiles/3.1.gemfile +17 -2
  41. data/gemfiles/3.1.gemfile.lock +31 -2
  42. data/gemfiles/3.1_1.9.2.gemfile +33 -0
  43. data/gemfiles/3.1_1.9.2.gemfile.lock +203 -0
  44. data/gemfiles/3.2.gemfile +18 -2
  45. data/gemfiles/3.2.gemfile.lock +32 -2
  46. data/gemfiles/3.2_1.9.2.gemfile +32 -0
  47. data/gemfiles/3.2_1.9.2.gemfile.lock +200 -0
  48. data/gemfiles/4.0.0.gemfile +20 -1
  49. data/gemfiles/4.0.0.gemfile.lock +46 -2
  50. data/gemfiles/4.0.1.gemfile +20 -1
  51. data/gemfiles/4.0.1.gemfile.lock +46 -2
  52. data/gemfiles/4.1.gemfile +21 -2
  53. data/gemfiles/4.1.gemfile.lock +47 -4
  54. data/lib/shoulda/matchers/action_controller.rb +0 -20
  55. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +119 -28
  56. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +22 -6
  57. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +43 -10
  58. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +40 -13
  59. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +63 -11
  60. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +34 -1
  61. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +84 -15
  62. data/lib/shoulda/matchers/action_controller/route_matcher.rb +84 -28
  63. data/lib/shoulda/matchers/action_controller/route_params.rb +4 -3
  64. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +76 -13
  65. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +147 -13
  66. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +148 -2
  67. data/lib/shoulda/matchers/active_model.rb +0 -25
  68. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +66 -9
  69. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +161 -19
  70. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -5
  71. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +92 -13
  72. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +218 -16
  73. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +198 -32
  74. data/lib/shoulda/matchers/active_model/errors.rb +5 -2
  75. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +1 -1
  76. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +29 -8
  77. data/lib/shoulda/matchers/active_model/helpers.rb +20 -8
  78. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  79. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +4 -6
  80. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
  81. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +3 -2
  82. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
  83. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +4 -3
  84. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +52 -14
  85. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +51 -13
  86. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +53 -7
  87. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +275 -19
  88. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +84 -14
  89. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +170 -41
  90. data/lib/shoulda/matchers/active_model/validation_matcher.rb +20 -15
  91. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -2
  92. data/lib/shoulda/matchers/active_record.rb +1 -12
  93. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +89 -15
  94. data/lib/shoulda/matchers/active_record/association_matcher.rb +726 -70
  95. data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  96. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +4 -3
  97. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -3
  98. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +4 -3
  99. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -1
  100. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +4 -3
  101. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +4 -5
  102. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +4 -3
  103. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +4 -3
  104. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +4 -3
  105. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +79 -15
  106. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +64 -15
  107. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +21 -7
  108. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +85 -10
  109. data/lib/shoulda/matchers/assertion_error.rb +7 -1
  110. data/lib/shoulda/matchers/doublespeak.rb +2 -1
  111. data/lib/shoulda/matchers/doublespeak/double.rb +3 -1
  112. data/lib/shoulda/matchers/doublespeak/double_collection.rb +2 -1
  113. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +1 -0
  114. data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
  115. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +2 -1
  116. data/lib/shoulda/matchers/doublespeak/structs.rb +2 -0
  117. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +2 -1
  118. data/lib/shoulda/matchers/doublespeak/world.rb +3 -4
  119. data/lib/shoulda/matchers/error.rb +1 -0
  120. data/lib/shoulda/matchers/independent/delegate_matcher.rb +108 -20
  121. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +4 -3
  122. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +3 -0
  123. data/lib/shoulda/matchers/rails_shim.rb +3 -2
  124. data/lib/shoulda/matchers/version.rb +2 -1
  125. data/lib/shoulda/matchers/warn.rb +1 -0
  126. data/script/SUPPORTED_VERSIONS +1 -0
  127. data/script/install_gems_in_all_appraisals +14 -0
  128. data/script/run_all_tests +14 -0
  129. data/shoulda-matchers.gemspec +0 -10
  130. data/spec/report_warnings.rb +7 -0
  131. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +1 -1
  132. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -0
  133. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -36
  134. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +2 -2
  135. data/spec/shoulda/matchers/doublespeak/double_spec.rb +1 -1
  136. data/spec/shoulda/matchers/doublespeak/world_spec.rb +11 -29
  137. data/spec/shoulda/matchers/doublespeak_spec.rb +3 -3
  138. data/spec/spec_helper.rb +17 -0
  139. data/spec/support/class_builder.rb +4 -0
  140. data/spec/support/test_application.rb +1 -1
  141. data/spec/warnings_spy.rb +64 -0
  142. data/spec/warnings_spy/filesystem.rb +45 -0
  143. data/spec/warnings_spy/partitioner.rb +29 -0
  144. data/spec/warnings_spy/reader.rb +64 -0
  145. data/spec/warnings_spy/reporter.rb +87 -0
  146. metadata +49 -134
@@ -1,25 +1,49 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
- # Ensures a controller rendered the given template.
3
+ module ActionController
4
+ # The `render_template` matcher tests that an action renders a template
5
+ # or partial. In RSpec, it is very similar to rspec-rails's
6
+ # `render_template` matcher. In Test::Unit, it provides a more expressive
7
+ # syntax over `assert_template`.
5
8
  #
6
- # Example:
9
+ # class PostsController < ApplicationController
10
+ # def show
11
+ # end
12
+ # end
7
13
  #
8
- # it { should render_template(:show) }
14
+ # # app/views/posts/show.html.erb
15
+ # <%= render 'sidebar' %>
9
16
  #
10
- # assert that the "_customer" partial was rendered
11
- # it { should render_template(partial: '_customer') }
17
+ # # RSpec
18
+ # describe PostsController do
19
+ # describe 'GET #show' do
20
+ # before { get :show }
12
21
  #
13
- # assert that the "_customer" partial was rendered twice
14
- # it { should render_template(partial: '_customer', count: 2) }
22
+ # it { should render_template('show') }
23
+ # it { should render_template(partial: 'sidebar') }
24
+ # end
25
+ # end
26
+ #
27
+ # # Test::Unit
28
+ # class PostsControllerTest < ActionController::TestCase
29
+ # context 'GET #show' do
30
+ # setup { get :show }
31
+ #
32
+ # should render_template('show')
33
+ # should render_template(partial: 'sidebar')
34
+ # end
35
+ # end
36
+ #
37
+ #
38
+ #
39
+ # @return [RenderTemplateMatcher]
15
40
  #
16
- # assert that no partials were rendered
17
- # it { should render_template(partial: false) }
18
41
  def render_template(options = {}, message = nil)
19
42
  RenderTemplateMatcher.new(options, message, self)
20
43
  end
21
44
 
22
- class RenderTemplateMatcher # :nodoc:
45
+ # @private
46
+ class RenderTemplateMatcher
23
47
  attr_reader :failure_message, :failure_message_when_negated
24
48
 
25
49
  alias failure_message_for_should failure_message
@@ -29,7 +53,10 @@ module Shoulda # :nodoc:
29
53
  @options = options
30
54
  @message = message
31
55
  @template = options.is_a?(Hash) ? options[:partial] : options
32
- @context = context
56
+ @context = context
57
+ @controller = nil
58
+ @failure_message = nil
59
+ @failure_message_when_negated = nil
33
60
  end
34
61
 
35
62
  def matches?(controller)
@@ -1,24 +1,76 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
-
5
- # Ensures that the controller rendered with the given layout.
3
+ module ActionController
4
+ # The `render_with_layout` matcher asserts that an action is rendered with
5
+ # a particular layout.
6
+ #
7
+ # class PostsController < ApplicationController
8
+ # def show
9
+ # render layout: 'posts'
10
+ # end
11
+ # end
12
+ #
13
+ # # RSpec
14
+ # describe PostsController do
15
+ # describe 'GET #show' do
16
+ # before { get :show }
17
+ #
18
+ # it { should render_with_layout('posts') }
19
+ # end
20
+ # end
21
+ #
22
+ # # Test::Unit
23
+ # class PostsControllerTest < ActionController::TestCase
24
+ # context 'GET #show' do
25
+ # setup { get :show }
26
+ #
27
+ # should render_with_layout('posts')
28
+ # end
29
+ # end
30
+ #
31
+ # It can also be used to assert that the action is not rendered with a
32
+ # layout at all:
33
+ #
34
+ # class PostsController < ApplicationController
35
+ # def sidebar
36
+ # render layout: false
37
+ # end
38
+ # end
6
39
  #
7
- # Example:
40
+ # # RSpec
41
+ # describe PostsController do
42
+ # describe 'GET #sidebar' do
43
+ # before { get :sidebar }
44
+ #
45
+ # it { should_not render_with_layout }
46
+ # end
47
+ # end
48
+ #
49
+ # # Test::Unit
50
+ # class PostsControllerTest < ActionController::TestCase
51
+ # context 'GET #sidebar' do
52
+ # setup { get :sidebar }
53
+ #
54
+ # should_not render_with_layout
55
+ # end
56
+ # end
57
+ #
58
+ # @return [RenderWithLayoutMatcher]
8
59
  #
9
- # it { should render_with_layout }
10
- # it { should render_with_layout(:special) }
11
- # it { should_not render_with_layout }
12
60
  def render_with_layout(expected_layout = nil)
13
61
  RenderWithLayoutMatcher.new(expected_layout).in_context(self)
14
62
  end
15
63
 
16
- class RenderWithLayoutMatcher # :nodoc:
17
-
64
+ # @private
65
+ class RenderWithLayoutMatcher
18
66
  def initialize(expected_layout)
19
- unless expected_layout.nil?
67
+ if expected_layout
20
68
  @expected_layout = expected_layout.to_s
69
+ else
70
+ @expected_layout = nil
21
71
  end
72
+
73
+ @controller = nil
22
74
  end
23
75
 
24
76
  # Used to provide access to layouts recorded by
@@ -1,13 +1,46 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  module ActionController
4
+ # The `rescue_from` matcher tests usage of the `rescue_from` macro. It
5
+ # asserts that an exception and method are present in the list of
6
+ # exception handlers, and that the handler method exists.
7
+ #
8
+ # class ApplicationController < ActionController::Base
9
+ # rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
10
+ #
11
+ # private
12
+ #
13
+ # def handle_not_found
14
+ # # ...
15
+ # end
16
+ # end
17
+ #
18
+ # # RSpec
19
+ # describe ApplicationController do
20
+ # it do
21
+ # should rescue_from(ActiveRecord::RecordNotFound).
22
+ # with(:handle_not_found)
23
+ # end
24
+ # end
25
+ #
26
+ # # Test::Unit
27
+ # class ApplicationControllerTest < ActionController::TestCase
28
+ # should rescue_from(ActiveRecord::RecordNotFound).
29
+ # with(:handle_not_found)
30
+ # end
31
+ #
32
+ # @return [RescueFromMatcher]
33
+ #
4
34
  def rescue_from(exception)
5
35
  RescueFromMatcher.new exception
6
36
  end
7
37
 
38
+ # @private
8
39
  class RescueFromMatcher
9
40
  def initialize(exception)
10
41
  @exception = exception
42
+ @expected_method = nil
43
+ @controller = nil
11
44
  end
12
45
 
13
46
  def with(method)
@@ -36,7 +69,7 @@ module Shoulda
36
69
  end
37
70
  alias failure_message_for_should_not failure_message_when_negated
38
71
 
39
- private
72
+ protected
40
73
 
41
74
  attr_reader :controller, :exception, :expected_method, :handlers
42
75
 
@@ -1,26 +1,95 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
-
5
- # Ensures a controller responded with expected 'response' status code.
3
+ module ActionController
4
+ # The `respond_with` matcher tests that an action responds with a certain
5
+ # status code.
6
+ #
7
+ # You can specify that the status should be a number:
8
+ #
9
+ # class PostsController < ApplicationController
10
+ # def index
11
+ # render status: 403
12
+ # end
13
+ # end
14
+ #
15
+ # # RSpec
16
+ # describe PostsController do
17
+ # describe 'GET #index' do
18
+ # before { get :index }
19
+ #
20
+ # it { should respond_with(403) }
21
+ # end
22
+ # end
23
+ #
24
+ # # Test::Unit
25
+ # class PostsControllerTest < ActionController::TestCase
26
+ # context 'GET #index' do
27
+ # setup { get :index }
28
+ #
29
+ # should respond_with(403)
30
+ # end
31
+ # end
32
+ #
33
+ # You can specify that the status should be within a range of numbers:
34
+ #
35
+ # class PostsController < ApplicationController
36
+ # def destroy
37
+ # render status: 508
38
+ # end
39
+ # end
40
+ #
41
+ # # RSpec
42
+ # describe PostsController do
43
+ # describe 'DELETE #destroy' do
44
+ # before { delete :destroy }
6
45
  #
7
- # You can pass an explicit status number like 200, 301, 404, 500
8
- # or its symbolic equivalent :success, :redirect, :missing, :error.
9
- # See ActionController::StatusCodes for a full list.
46
+ # it { should respond_with(500..600) }
47
+ # end
48
+ # end
10
49
  #
11
- # Example:
50
+ # # Test::Unit
51
+ # class PostsControllerTest < ActionController::TestCase
52
+ # context 'DELETE #destroy' do
53
+ # setup { delete :destroy }
54
+ #
55
+ # should respond_with(500..600)
56
+ # end
57
+ # end
58
+ #
59
+ # Finally, you can specify that the status should be a symbol:
60
+ #
61
+ # class PostsController < ApplicationController
62
+ # def show
63
+ # render status: :locked
64
+ # end
65
+ # end
66
+ #
67
+ # # RSpec
68
+ # describe PostsController do
69
+ # describe 'GET #show' do
70
+ # before { get :show }
71
+ #
72
+ # it { should respond_with(:locked) }
73
+ # end
74
+ # end
75
+ #
76
+ # # Test::Unit
77
+ # class PostsControllerTest < ActionController::TestCase
78
+ # context 'GET #show' do
79
+ # setup { get :show }
80
+ #
81
+ # should respond_with(:locked)
82
+ # end
83
+ # end
84
+ #
85
+ # @return [RespondWithMatcher]
12
86
  #
13
- # it { should respond_with(:success) }
14
- # it { should respond_with(:redirect) }
15
- # it { should respond_with(:missing) }
16
- # it { should respond_with(:error) }
17
- # it { should respond_with(501) }
18
87
  def respond_with(status)
19
88
  RespondWithMatcher.new(status)
20
89
  end
21
90
 
22
- class RespondWithMatcher # :nodoc:
23
-
91
+ # @private
92
+ class RespondWithMatcher
24
93
  def initialize(status)
25
94
  @status = symbol_to_status_code(status)
26
95
  end
@@ -1,36 +1,92 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
-
5
- # Ensures that requesting +path+ using +method+ routes to +options+.
6
- #
7
- # If you don't specify a controller, it will use the controller from the
8
- # example group.
9
- #
10
- # +to_param+ is called on the +options+ given.
11
- #
12
- # Examples:
13
- #
14
- # it { should route(:get, '/posts').
15
- # to(controller: :posts, action: :index) }
16
- # it { should route(:get, '/posts').to('posts#index') }
17
- # it { should route(:get, '/posts/new').to(action: :new) }
18
- # it { should route(:post, '/posts').to(action: :create) }
19
- # it { should route(:get, '/posts/1').to(action: :show, id: 1) }
20
- # it { should route(:get, '/posts/1').to('posts#show', id: 1) }
21
- # it { should route(:get, '/posts/1/edit').to(action: :edit, id: 1) }
22
- # it { should route(:put, '/posts/1').to(action: :update, id: 1) }
23
- # it { should route(:delete, '/posts/1').
24
- # to(action: :destroy, id: 1) }
25
- # it { should route(:get, '/users/1/posts/1').
26
- # to(action: :show, id: 1, user_id: 1) }
27
- # it { should route(:get, '/users/1/posts/1').
28
- # to('posts#show', id: 1, user_id: 1) }
3
+ module ActionController
4
+ # The `route` matcher tests that a route resolves to a controller,
5
+ # action, and params; and that the controller, action, and params
6
+ # generates the same route. For an RSpec suite, this is like using a
7
+ # combination of `route_to` and `be_routable`. For a Test::Unit suite, it
8
+ # provides a more expressive syntax over `assert_routing`.
9
+ #
10
+ # You can use this matcher either in a controller test case or in a
11
+ # routing test case. For instance, given these routes:
12
+ #
13
+ # My::Application.routes.draw do
14
+ # get '/posts', controller: 'posts', action: 'index'
15
+ # get '/posts/:id' => 'posts#show'
16
+ # end
17
+ #
18
+ # You could choose to write tests for these routes alongside other tests
19
+ # for PostsController:
20
+ #
21
+ # class PostsController < ApplicationController
22
+ # # ...
23
+ # end
24
+ #
25
+ # # RSpec
26
+ # describe PostsController do
27
+ # it { should route(:get, '/posts').to(action: :index) }
28
+ # it { should route(:get, '/posts/1').to(action: :show, id: 1) }
29
+ # end
30
+ #
31
+ # # Test::Unit
32
+ # class PostsControllerTest < ActionController::TestCase
33
+ # should route(:get, '/posts').to(action: 'index')
34
+ # should route(:get, '/posts/1').to(action: :show, id: 1)
35
+ # end
36
+ #
37
+ # Or you could place the tests along with other route tests:
38
+ #
39
+ # # RSpec
40
+ # describe 'Routing' do
41
+ # it do
42
+ # should route(:get, '/posts').
43
+ # to(controller: :posts, action: :index)
44
+ # end
45
+ #
46
+ # it do
47
+ # should route(:get, '/posts/1').
48
+ # to('posts#show', id: 1)
49
+ # end
50
+ # end
51
+ #
52
+ # # Test::Unit
53
+ # class RoutesTest < ActionController::IntegrationTest
54
+ # should route(:get, '/posts').
55
+ # to(controller: :posts, action: :index)
56
+ #
57
+ # should route(:get, '/posts/1').
58
+ # to('posts#show', id: 1)
59
+ # end
60
+ #
61
+ # Notice that in the former case, as we are inside of a test case for
62
+ # PostsController, we do not have to specify that the routes resolve to
63
+ # this controller. In the latter case we specify this using the
64
+ # `controller` key passed to the `to` qualifier.
65
+ #
66
+ # #### Qualifiers
67
+ #
68
+ # ##### to
69
+ #
70
+ # Use `to` to specify the action (along with the controller, if needed)
71
+ # that the route resolves to.
72
+ #
73
+ # # Three ways of saying the same thing (using the example above)
74
+ # route(:get, '/posts').to(action: index)
75
+ # route(:get, '/posts').to(controller: :posts, action: index)
76
+ # route(:get, '/posts').to('posts#index')
77
+ #
78
+ # If there are parameters in your route, then specify those too:
79
+ #
80
+ # route(:get, '/posts/1').to('posts#show', id: 1)
81
+ #
82
+ # @return [RouteMatcher]
83
+ #
29
84
  def route(method, path)
30
85
  RouteMatcher.new(method, path, self)
31
86
  end
32
87
 
33
- class RouteMatcher # :nodoc:
88
+ # @private
89
+ class RouteMatcher
34
90
  def initialize(method, path, context)
35
91
  @method = method
36
92
  @path = path