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
data/gemfiles/4.1.gemfile CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "appraisal", "~> 1.0.0.beta2"
6
+ gem "aruba"
7
+ gem "bourne", "~> 1.3"
8
+ gem "bundler", "~> 1.1"
9
+ gem "cucumber", "~> 1.1"
10
+ gem "pry"
11
+ gem "rake", ">= 0.9.2"
12
+ gem "rspec-rails", ">= 2.13.1", "< 3"
13
+ gem "yard"
14
+ gem "redcarpet"
15
+ gem "pygments.rb"
16
+ gem "watchr"
5
17
  gem "shoulda-context", "~> 1.2.0"
6
18
  gem "sqlite3", :platform=>:ruby
7
19
  gem "activerecord-jdbc-adapter", :platform=>:jruby
@@ -9,11 +21,18 @@ gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
9
21
  gem "jdbc-sqlite3", :platform=>:jruby
10
22
  gem "jruby-openssl", :platform=>:jruby
11
23
  gem "therubyrhino", :platform=>:jruby
24
+ gem "spring-commands-rspec"
25
+ gem "uglifier", ">= 1.3.0"
26
+ gem "coffee-rails", "~> 4.0.0"
12
27
  gem "jquery-rails"
28
+ gem "turbolinks"
13
29
  gem "activeresource", "4.0.0"
14
30
  gem "rails", "~> 4.1.0"
15
- gem "sass-rails", "4.0.3"
16
- gem "bcrypt-ruby", "~> 3.1.2"
31
+ gem "jbuilder", "~> 2.0"
32
+ gem "sass-rails", "~> 4.0.3"
33
+ gem "sdoc", "~> 0.4.0"
34
+ gem "bcrypt", "~> 3.1.7"
17
35
  gem "protected_attributes", "~> 1.0.6"
36
+ gem "spring"
18
37
 
19
38
  gemspec :path=>".././"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .././
3
3
  specs:
4
- shoulda-matchers (2.6.1)
4
+ shoulda-matchers (2.6.2)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -46,13 +46,20 @@ GEM
46
46
  childprocess (>= 0.3.6)
47
47
  cucumber (>= 1.1.1)
48
48
  rspec-expectations (>= 2.7.0)
49
- bcrypt-ruby (3.1.2)
49
+ bcrypt (3.1.7)
50
50
  bourne (1.5.0)
51
51
  mocha (>= 0.13.2, < 0.15)
52
52
  builder (3.2.2)
53
53
  childprocess (0.4.0)
54
54
  ffi (~> 1.0, >= 1.0.11)
55
55
  coderay (1.1.0)
56
+ coffee-rails (4.0.1)
57
+ coffee-script (>= 2.2.0)
58
+ railties (>= 4.0.0, < 5.0)
59
+ coffee-script (2.2.0)
60
+ coffee-script-source
61
+ execjs
62
+ coffee-script-source (1.7.0)
56
63
  cucumber (1.3.10)
57
64
  builder (>= 2.1.2)
58
65
  diff-lcs (>= 1.1.3)
@@ -61,11 +68,15 @@ GEM
61
68
  multi_test (>= 0.0.2)
62
69
  diff-lcs (1.2.5)
63
70
  erubis (2.7.0)
71
+ execjs (2.0.2)
64
72
  ffi (1.9.3)
65
73
  gherkin (2.12.2)
66
74
  multi_json (~> 1.3)
67
75
  hike (1.2.3)
68
76
  i18n (0.6.9)
77
+ jbuilder (2.0.6)
78
+ activesupport (>= 3.0.0, < 5)
79
+ multi_json (~> 1.2)
69
80
  jquery-rails (3.1.0)
70
81
  railties (>= 3.0, < 5.0)
71
82
  thor (>= 0.14, < 2.0)
@@ -82,12 +93,16 @@ GEM
82
93
  multi_json (1.9.2)
83
94
  multi_test (0.0.3)
84
95
  polyglot (0.3.4)
96
+ posix-spawn (0.3.8)
85
97
  protected_attributes (1.0.7)
86
98
  activemodel (>= 4.0.1, < 5.0)
87
99
  pry (0.9.12.6)
88
100
  coderay (~> 1.0)
89
101
  method_source (~> 0.8)
90
102
  slop (~> 3.4)
103
+ pygments.rb (0.6.0)
104
+ posix-spawn (~> 0.3.6)
105
+ yajl-ruby (~> 1.1.0)
91
106
  rack (1.5.2)
92
107
  rack-test (0.6.2)
93
108
  rack (>= 1.0)
@@ -109,6 +124,9 @@ GEM
109
124
  rake (>= 0.8.7)
110
125
  thor (>= 0.18.1, < 2.0)
111
126
  rake (10.2.2)
127
+ rdoc (4.1.1)
128
+ json (~> 1.4)
129
+ redcarpet (3.1.2)
112
130
  rspec-core (2.14.7)
113
131
  rspec-expectations (2.14.4)
114
132
  diff-lcs (>= 1.1.3, < 2.0)
@@ -127,8 +145,14 @@ GEM
127
145
  sass (~> 3.2.0)
128
146
  sprockets (~> 2.8, <= 2.11.0)
129
147
  sprockets-rails (~> 2.0)
148
+ sdoc (0.4.0)
149
+ json (~> 1.8)
150
+ rdoc (~> 4.0, < 5.0)
130
151
  shoulda-context (1.2.0)
131
152
  slop (3.4.7)
153
+ spring (1.1.2)
154
+ spring-commands-rspec (1.0.2)
155
+ spring (>= 0.9.1)
132
156
  sprockets (2.11.0)
133
157
  hike (~> 1.2)
134
158
  multi_json (~> 1.0)
@@ -145,8 +169,16 @@ GEM
145
169
  treetop (1.4.15)
146
170
  polyglot
147
171
  polyglot (>= 0.3.1)
172
+ turbolinks (2.2.2)
173
+ coffee-rails
148
174
  tzinfo (1.1.0)
149
175
  thread_safe (~> 0.1)
176
+ uglifier (2.5.0)
177
+ execjs (>= 0.3.0)
178
+ json (>= 1.8.0)
179
+ watchr (0.7)
180
+ yajl-ruby (1.1.0)
181
+ yard (0.8.7.3)
150
182
 
151
183
  PLATFORMS
152
184
  ruby
@@ -157,20 +189,31 @@ DEPENDENCIES
157
189
  activeresource (= 4.0.0)
158
190
  appraisal (~> 1.0.0.beta2)
159
191
  aruba
160
- bcrypt-ruby (~> 3.1.2)
192
+ bcrypt (~> 3.1.7)
161
193
  bourne (~> 1.3)
162
194
  bundler (~> 1.1)
195
+ coffee-rails (~> 4.0.0)
163
196
  cucumber (~> 1.1)
197
+ jbuilder (~> 2.0)
164
198
  jdbc-sqlite3
165
199
  jquery-rails
166
200
  jruby-openssl
167
201
  protected_attributes (~> 1.0.6)
168
202
  pry
203
+ pygments.rb
169
204
  rails (~> 4.1.0)
170
205
  rake (>= 0.9.2)
206
+ redcarpet
171
207
  rspec-rails (>= 2.13.1, < 3)
172
- sass-rails (= 4.0.3)
208
+ sass-rails (~> 4.0.3)
209
+ sdoc (~> 0.4.0)
173
210
  shoulda-context (~> 1.2.0)
174
211
  shoulda-matchers!
212
+ spring
213
+ spring-commands-rspec
175
214
  sqlite3
176
215
  therubyrhino
216
+ turbolinks
217
+ uglifier (>= 1.3.0)
218
+ watchr
219
+ yard
@@ -13,26 +13,6 @@ require 'shoulda/matchers/action_controller/strong_parameters_matcher'
13
13
 
14
14
  module Shoulda
15
15
  module Matchers
16
- # By using the matchers you can quickly and easily create concise and
17
- # easy to read test suites.
18
- #
19
- # This code segment:
20
- #
21
- # describe UsersController, 'on GET to show with a valid id' do
22
- # before(:each) do
23
- # get :show, id: User.first.to_param
24
- # end
25
- #
26
- # it { should respond_with(:success) }
27
- # it { should render_template(:show) }
28
- # it { should not_set_the_flash) }
29
- #
30
- # it 'does something else really cool' do
31
- # expect(assigns[:user].id).to eq 1
32
- # end
33
- # end
34
- #
35
- # Would produce 5 tests for the show action
36
16
  module ActionController
37
17
  end
38
18
  end
@@ -1,67 +1,158 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
- # Ensure a controller uses a given before_filter
3
+ module ActionController
4
+ # The `use_before_filter` matcher is used to test that a before_filter
5
+ # callback is defined within your controller.
5
6
  #
6
- # Example:
7
+ # class UsersController < ApplicationController
8
+ # before_filter :authenticate_user!
9
+ # end
10
+ #
11
+ # # RSpec
12
+ # describe UsersController do
13
+ # it { should use_before_filter(:authenticate_user!) }
14
+ # it { should_not use_before_filter(:prevent_ssl) }
15
+ # end
16
+ #
17
+ # # Test::Unit
18
+ # class UsersControllerTest < ActionController::TestCase
19
+ # should use_before_filter(:authenticate_user!)
20
+ # should_not use_before_filter(:prevent_ssl)
21
+ # end
22
+ #
23
+ # @return [CallbackMatcher]
7
24
  #
8
- # it { should use_before_filter(:authenticate_user!) }
9
- # it { should_not use_before_filter(:prevent_ssl) }
10
25
  def use_before_filter(callback)
11
26
  CallbackMatcher.new(callback, :before, :filter)
12
27
  end
13
28
 
14
- # Ensure a controller uses a given before_filter
29
+ # The `use_after_filter` matcher is used to test that an after_filter
30
+ # callback is defined within your controller.
31
+ #
32
+ # class IssuesController < ApplicationController
33
+ # after_filter :log_activity
34
+ # end
35
+ #
36
+ # # RSpec
37
+ # describe IssuesController do
38
+ # it { should use_after_filter(:log_activity) }
39
+ # it { should_not use_after_filter(:destroy_user) }
40
+ # end
15
41
  #
16
- # Example:
42
+ # # Test::Unit
43
+ # class IssuesControllerTest < ActionController::TestCase
44
+ # should use_after_filter(:log_activity)
45
+ # should_not use_after_filter(:destroy_user)
46
+ # end
47
+ #
48
+ # @return [CallbackMatcher]
17
49
  #
18
- # it { should use_after_filter(:log_activity) }
19
- # it { should_not use_after_filter(:destroy_user) }
20
50
  def use_after_filter(callback)
21
51
  CallbackMatcher.new(callback, :after, :filter)
22
52
  end
23
53
 
24
- # Ensure a controller uses a given before_action
54
+ # The `use_before_action` matcher is used to test that a before_action
55
+ # callback is defined within your controller.
56
+ #
57
+ # class UsersController < ApplicationController
58
+ # before_action :authenticate_user!
59
+ # end
60
+ #
61
+ # # RSpec
62
+ # describe UsersController do
63
+ # it { should use_before_action(:authenticate_user!) }
64
+ # it { should_not use_before_action(:prevent_ssl) }
65
+ # end
66
+ #
67
+ # # Test::Unit
68
+ # class UsersControllerTest < ActionController::TestCase
69
+ # should use_before_action(:authenticate_user!)
70
+ # should_not use_before_action(:prevent_ssl)
71
+ # end
25
72
  #
26
- # Example:
73
+ # @return [CallbackMatcher]
27
74
  #
28
- # it { should use_before_action(:authenticate_user!) }
29
- # it { should_not use_before_action(:prevent_ssl) }
30
75
  def use_before_action(callback)
31
76
  CallbackMatcher.new(callback, :before, :action)
32
77
  end
33
78
 
34
- # Ensure a controller uses a given after_action
79
+ # The `use_after_action` matcher is used to test that an after_action
80
+ # callback is defined within your controller.
35
81
  #
36
- # Example:
82
+ # class IssuesController < ApplicationController
83
+ # after_action :log_activity
84
+ # end
85
+ #
86
+ # # RSpec
87
+ # describe IssuesController do
88
+ # it { should use_after_action(:log_activity) }
89
+ # it { should_not use_after_action(:destroy_user) }
90
+ # end
91
+ #
92
+ # # Test::Unit
93
+ # class IssuesControllerTest < ActionController::TestCase
94
+ # should use_after_action(:log_activity)
95
+ # should_not use_after_action(:destroy_user)
96
+ # end
97
+ #
98
+ # @return [CallbackMatcher]
37
99
  #
38
- # it { should use_after_action(:log_activity) }
39
- # it { should_not use_after_action(:destroy_user) }
40
100
  def use_after_action(callback)
41
101
  CallbackMatcher.new(callback, :after, :action)
42
102
  end
43
103
 
44
- # Ensure a controller uses a given around_filter
104
+ # The `use_around_filter` matcher is used to test that an around_filter
105
+ # callback is defined within your controller.
106
+ #
107
+ # class ChangesController < ApplicationController
108
+ # around_filter :wrap_in_transaction
109
+ # end
110
+ #
111
+ # # RSpec
112
+ # describe ChangesController do
113
+ # it { should use_around_filter(:wrap_in_transaction) }
114
+ # it { should_not use_around_filter(:save_view_context) }
115
+ # end
45
116
  #
46
- # Example:
117
+ # # Test::Unit
118
+ # class ChangesControllerTest < ActionController::TestCase
119
+ # should use_around_filter(:wrap_in_transaction)
120
+ # should_not use_around_filter(:save_view_context)
121
+ # end
122
+ #
123
+ # @return [CallbackMatcher]
47
124
  #
48
- # it { should use_around_filter(:log_activity) }
49
- # it { should_not use_around_filter(:destroy_user) }
50
125
  def use_around_filter(callback)
51
126
  CallbackMatcher.new(callback, :around, :filter)
52
127
  end
53
128
 
54
- # Ensure a controller uses a given around_action
129
+ # The `use_around_action` matcher is used to test that an around_action
130
+ # callback is defined within your controller.
131
+ #
132
+ # class ChangesController < ApplicationController
133
+ # around_action :wrap_in_transaction
134
+ # end
135
+ #
136
+ # # RSpec
137
+ # describe ChangesController do
138
+ # it { should use_around_action(:wrap_in_transaction) }
139
+ # it { should_not use_around_action(:save_view_context) }
140
+ # end
141
+ #
142
+ # # Test::Unit
143
+ # class ChangesControllerTest < ActionController::TestCase
144
+ # should use_around_action(:wrap_in_transaction)
145
+ # should_not use_around_action(:save_view_context)
146
+ # end
55
147
  #
56
- # Example:
148
+ # @return [CallbackMatcher]
57
149
  #
58
- # it { should use_around_action(:log_activity) }
59
- # it { should_not use_around_action(:destroy_user) }
60
150
  def use_around_action(callback)
61
151
  CallbackMatcher.new(callback, :around, :action)
62
152
  end
63
153
 
64
- class CallbackMatcher # :nodoc:
154
+ # @private
155
+ class CallbackMatcher
65
156
  def initialize(method_name, kind, callback_type)
66
157
  @method_name = method_name
67
158
  @kind = kind
@@ -89,7 +180,7 @@ module Shoulda # :nodoc:
89
180
  "have :#{method_name} as a #{kind}_#{callback_type}"
90
181
  end
91
182
 
92
- private
183
+ protected
93
184
 
94
185
  def callbacks
95
186
  controller_class._process_action_callbacks.select do |callback|
@@ -1,16 +1,32 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
- # Ensures that filter_parameter_logging is set for the specified key.
3
+ module ActionController
4
+ # The `filter_param` matcher is used to test parameter filtering
5
+ # configuration. Specifically, it asserts that the given parameter is
6
+ # present in `config.filter_parameters`.
5
7
  #
6
- # Example:
8
+ # class MyApplication < Rails::Application
9
+ # config.filter_parameters << :secret_key
10
+ # end
11
+ #
12
+ # # RSpec
13
+ # describe ApplicationController do
14
+ # it { should filter_param(:secret_key) }
15
+ # end
16
+ #
17
+ # # Test::Unit
18
+ # class ApplicationControllerTest < ActionController::TestCase
19
+ # should filter_param(:secret_key)
20
+ # end
21
+ #
22
+ # @return [FilterParamMatcher]
7
23
  #
8
- # it { should filter_param(:password) }
9
24
  def filter_param(key)
10
25
  FilterParamMatcher.new(key)
11
26
  end
12
27
 
13
- class FilterParamMatcher # :nodoc:
28
+ # @private
29
+ class FilterParamMatcher
14
30
  def initialize(key)
15
31
  @key = key.to_s
16
32
  end
@@ -1,31 +1,64 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
- # Ensures a controller redirected to the given url.
3
+ module ActionController
4
+ # The `redirect_to` matcher tests that an action redirects to a certain
5
+ # location. In a test suite using RSpec, it is very similar to
6
+ # rspec-rails's `redirect_to` matcher. In a test suite using Test::Unit /
7
+ # Shoulda, it provides a more expressive syntax over
8
+ # `assert_redirected_to`.
5
9
  #
6
- # Example:
10
+ # class PostsController < ApplicationController
11
+ # def show
12
+ # redirect_to :index
13
+ # end
14
+ # end
15
+ #
16
+ # # RSpec
17
+ # describe PostsController do
18
+ # describe 'GET #show' do
19
+ # before { get :show }
20
+ #
21
+ # it { should redirect_to(posts_path) }
22
+ # it { should redirect_to(action: :index) }
23
+ # end
24
+ # end
25
+ #
26
+ # # Test::Unit
27
+ # class PostsControllerTest < ActionController::TestCase
28
+ # context 'GET #show' do
29
+ # setup { get :show }
30
+ #
31
+ # should redirect_to { posts_path }
32
+ # should redirect_to(action: :index)
33
+ # end
34
+ # end
35
+ #
36
+ # @return [RedirectToMatcher]
7
37
  #
8
- # it { should redirect_to('http://somewhere.com') }
9
- # it { should redirect_to(users_path) }
10
38
  def redirect_to(url_or_description, &block)
11
39
  RedirectToMatcher.new(url_or_description, self, &block)
12
40
  end
13
41
 
14
- class RedirectToMatcher # :nodoc:
42
+ # @private
43
+ class RedirectToMatcher
15
44
  attr_reader :failure_message, :failure_message_when_negated
16
45
 
17
46
  alias failure_message_for_should failure_message
18
47
  alias failure_message_for_should_not failure_message_when_negated
19
48
 
20
49
  def initialize(url_or_description, context, &block)
50
+ @url_block = nil
51
+ @url = nil
52
+ @context = context
53
+ @failure_message = nil
54
+ @failure_message_when_negated = nil
55
+
21
56
  if block
22
57
  @url_block = block
23
58
  @location = url_or_description
24
59
  else
25
- @url = url_or_description
26
- @location = @url
60
+ @location = @url = url_or_description
27
61
  end
28
- @context = context
29
62
  end
30
63
 
31
64
  def in_context(context)