mcmire-shoulda-matchers 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +32 -0
  4. data/.yardopts +7 -0
  5. data/Appraisals +45 -0
  6. data/CONTRIBUTING.md +41 -0
  7. data/Gemfile +31 -0
  8. data/Gemfile.lock +166 -0
  9. data/MIT-LICENSE +22 -0
  10. data/NEWS.md +299 -0
  11. data/README.md +163 -0
  12. data/Rakefile +116 -0
  13. data/doc_config/gh-pages/index.html.erb +9 -0
  14. data/doc_config/yard/setup.rb +22 -0
  15. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
  18. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
  19. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
  20. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
  21. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
  22. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
  23. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +300 -0
  24. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
  25. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
  26. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
  27. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
  28. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
  29. data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
  30. data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
  31. data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
  32. data/doc_config/yard/templates/default/layout/html/setup.rb +8 -0
  33. data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
  34. data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
  35. data/features/rails_integration.feature +113 -0
  36. data/features/step_definitions/rails_steps.rb +162 -0
  37. data/features/support/env.rb +5 -0
  38. data/gemfiles/3.0.gemfile +24 -0
  39. data/gemfiles/3.0.gemfile.lock +150 -0
  40. data/gemfiles/3.1.gemfile +27 -0
  41. data/gemfiles/3.1.gemfile.lock +173 -0
  42. data/gemfiles/3.2.gemfile +27 -0
  43. data/gemfiles/3.2.gemfile.lock +171 -0
  44. data/gemfiles/4.0.0.gemfile +28 -0
  45. data/gemfiles/4.0.0.gemfile.lock +172 -0
  46. data/gemfiles/4.0.1.gemfile +28 -0
  47. data/gemfiles/4.0.1.gemfile.lock +172 -0
  48. data/lib/shoulda-matchers.rb +1 -0
  49. data/lib/shoulda/matchers.rb +11 -0
  50. data/lib/shoulda/matchers/action_controller.rb +17 -0
  51. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +64 -0
  52. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +97 -0
  53. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +81 -0
  54. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +117 -0
  55. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +114 -0
  56. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +154 -0
  57. data/lib/shoulda/matchers/action_controller/route_matcher.rb +116 -0
  58. data/lib/shoulda/matchers/action_controller/route_params.rb +48 -0
  59. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +164 -0
  60. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +296 -0
  61. data/lib/shoulda/matchers/active_model.rb +30 -0
  62. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +167 -0
  63. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +314 -0
  64. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +46 -0
  65. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +160 -0
  66. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +417 -0
  67. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +337 -0
  68. data/lib/shoulda/matchers/active_model/errors.rb +10 -0
  69. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +58 -0
  70. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +92 -0
  71. data/lib/shoulda/matchers/active_model/helpers.rb +46 -0
  72. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  73. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +75 -0
  74. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +27 -0
  75. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +41 -0
  76. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +27 -0
  77. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +26 -0
  78. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +112 -0
  79. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +77 -0
  80. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +121 -0
  81. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +380 -0
  82. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +89 -0
  83. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +372 -0
  84. data/lib/shoulda/matchers/active_model/validation_matcher.rb +97 -0
  85. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +69 -0
  86. data/lib/shoulda/matchers/active_record.rb +22 -0
  87. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +204 -0
  88. data/lib/shoulda/matchers/active_record/association_matcher.rb +901 -0
  89. data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  90. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +41 -0
  91. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +41 -0
  92. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +81 -0
  93. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +65 -0
  94. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +94 -0
  95. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
  96. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +41 -0
  97. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +63 -0
  98. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +261 -0
  99. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +149 -0
  100. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +72 -0
  101. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +181 -0
  102. data/lib/shoulda/matchers/assertion_error.rb +19 -0
  103. data/lib/shoulda/matchers/error.rb +6 -0
  104. data/lib/shoulda/matchers/integrations/rspec.rb +20 -0
  105. data/lib/shoulda/matchers/integrations/test_unit.rb +30 -0
  106. data/lib/shoulda/matchers/rails_shim.rb +50 -0
  107. data/lib/shoulda/matchers/version.rb +6 -0
  108. data/lib/shoulda/matchers/warn.rb +8 -0
  109. data/shoulda-matchers.gemspec +23 -0
  110. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
  111. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
  112. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
  113. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +63 -0
  114. data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +63 -0
  115. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
  116. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +70 -0
  117. data/spec/shoulda/matchers/action_controller/route_params_spec.rb +30 -0
  118. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
  119. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
  120. data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
  121. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +170 -0
  122. data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +81 -0
  123. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +95 -0
  124. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +320 -0
  125. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +166 -0
  126. data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +111 -0
  127. data/spec/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +20 -0
  128. data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
  129. data/spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +169 -0
  130. data/spec/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +59 -0
  131. data/spec/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +59 -0
  132. data/spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +57 -0
  133. data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +139 -0
  134. data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
  135. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +47 -0
  136. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +331 -0
  137. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +180 -0
  138. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +398 -0
  139. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +127 -0
  140. data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +107 -0
  141. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +860 -0
  142. data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +247 -0
  143. data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
  144. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
  145. data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
  146. data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
  147. data/spec/spec_helper.rb +26 -0
  148. data/spec/support/active_model_versions.rb +13 -0
  149. data/spec/support/active_resource_builder.rb +29 -0
  150. data/spec/support/activemodel_helpers.rb +19 -0
  151. data/spec/support/capture_helpers.rb +19 -0
  152. data/spec/support/class_builder.rb +42 -0
  153. data/spec/support/controller_builder.rb +74 -0
  154. data/spec/support/fail_with_message_including_matcher.rb +33 -0
  155. data/spec/support/fail_with_message_matcher.rb +32 -0
  156. data/spec/support/i18n_faker.rb +10 -0
  157. data/spec/support/mailer_builder.rb +10 -0
  158. data/spec/support/model_builder.rb +81 -0
  159. data/spec/support/rails_versions.rb +18 -0
  160. data/spec/support/shared_examples/numerical_submatcher.rb +19 -0
  161. data/spec/support/shared_examples/numerical_type_submatcher.rb +17 -0
  162. data/spec/support/test_application.rb +120 -0
  163. data/yard.watchr +5 -0
  164. metadata +281 -0
@@ -0,0 +1,28 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 0.4"
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 "shoulda-context", "~> 1.1.2"
15
+ gem "sqlite3", :platform=>:ruby
16
+ gem "activerecord-jdbc-adapter", :platform=>:jruby
17
+ gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
18
+ gem "jdbc-sqlite3", :platform=>:jruby
19
+ gem "jruby-openssl", :platform=>:jruby
20
+ gem "therubyrhino", :platform=>:jruby
21
+ gem "jquery-rails"
22
+ gem "activeresource", "4.0.0"
23
+ gem "protected_attributes"
24
+ gem "rails", "4.0.1"
25
+ gem "sass-rails", "4.0.1"
26
+ gem "bcrypt-ruby", "~> 3.1.2"
27
+
28
+ gemspec :path=>".././"
@@ -0,0 +1,172 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ shoulda-matchers (2.5.0)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.1)
11
+ actionpack (= 4.0.1)
12
+ mail (~> 2.5.4)
13
+ actionpack (4.0.1)
14
+ activesupport (= 4.0.1)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.1)
20
+ activesupport (= 4.0.1)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.1)
23
+ activemodel (= 4.0.1)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.1)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.3)
28
+ activeresource (4.0.0)
29
+ activemodel (~> 4.0)
30
+ activesupport (~> 4.0)
31
+ rails-observers (~> 0.1.1)
32
+ activesupport (4.0.1)
33
+ i18n (~> 0.6, >= 0.6.4)
34
+ minitest (~> 4.2)
35
+ multi_json (~> 1.3)
36
+ thread_safe (~> 0.1)
37
+ tzinfo (~> 0.3.37)
38
+ appraisal (1.0.0.beta2)
39
+ bundler
40
+ rake
41
+ thor (>= 0.14.0)
42
+ arel (4.0.1)
43
+ aruba (0.5.3)
44
+ childprocess (>= 0.3.6)
45
+ cucumber (>= 1.1.1)
46
+ rspec-expectations (>= 2.7.0)
47
+ atomic (1.1.14)
48
+ bcrypt-ruby (3.1.2)
49
+ bourne (1.5.0)
50
+ mocha (>= 0.13.2, < 0.15)
51
+ builder (3.1.4)
52
+ childprocess (0.3.9)
53
+ ffi (~> 1.0, >= 1.0.11)
54
+ coderay (1.1.0)
55
+ cucumber (1.3.10)
56
+ builder (>= 2.1.2)
57
+ diff-lcs (>= 1.1.3)
58
+ gherkin (~> 2.12)
59
+ multi_json (>= 1.7.5, < 2.0)
60
+ multi_test (>= 0.0.2)
61
+ diff-lcs (1.2.5)
62
+ erubis (2.7.0)
63
+ ffi (1.9.3)
64
+ gherkin (2.12.2)
65
+ multi_json (~> 1.3)
66
+ hike (1.2.3)
67
+ i18n (0.6.5)
68
+ jquery-rails (3.0.4)
69
+ railties (>= 3.0, < 5.0)
70
+ thor (>= 0.14, < 2.0)
71
+ mail (2.5.4)
72
+ mime-types (~> 1.16)
73
+ treetop (~> 1.4.8)
74
+ metaclass (0.0.1)
75
+ method_source (0.8.2)
76
+ mime-types (1.25.1)
77
+ minitest (4.7.5)
78
+ mocha (0.14.0)
79
+ metaclass (~> 0.0.1)
80
+ multi_json (1.8.2)
81
+ multi_test (0.0.2)
82
+ polyglot (0.3.3)
83
+ protected_attributes (1.0.5)
84
+ activemodel (>= 4.0.1, < 5.0)
85
+ pry (0.9.12.6)
86
+ coderay (~> 1.0)
87
+ method_source (~> 0.8)
88
+ slop (~> 3.4)
89
+ rack (1.5.2)
90
+ rack-test (0.6.2)
91
+ rack (>= 1.0)
92
+ rails (4.0.1)
93
+ actionmailer (= 4.0.1)
94
+ actionpack (= 4.0.1)
95
+ activerecord (= 4.0.1)
96
+ activesupport (= 4.0.1)
97
+ bundler (>= 1.3.0, < 2.0)
98
+ railties (= 4.0.1)
99
+ sprockets-rails (~> 2.0.0)
100
+ rails-observers (0.1.2)
101
+ activemodel (~> 4.0)
102
+ railties (4.0.1)
103
+ actionpack (= 4.0.1)
104
+ activesupport (= 4.0.1)
105
+ rake (>= 0.8.7)
106
+ thor (>= 0.18.1, < 2.0)
107
+ rake (10.1.1)
108
+ rspec-core (2.14.7)
109
+ rspec-expectations (2.14.4)
110
+ diff-lcs (>= 1.1.3, < 2.0)
111
+ rspec-mocks (2.14.4)
112
+ rspec-rails (2.14.0)
113
+ actionpack (>= 3.0)
114
+ activesupport (>= 3.0)
115
+ railties (>= 3.0)
116
+ rspec-core (~> 2.14.0)
117
+ rspec-expectations (~> 2.14.0)
118
+ rspec-mocks (~> 2.14.0)
119
+ sass (3.2.12)
120
+ sass-rails (4.0.1)
121
+ railties (>= 4.0.0, < 5.0)
122
+ sass (>= 3.1.10)
123
+ sprockets-rails (~> 2.0.0)
124
+ shoulda-context (1.1.6)
125
+ slop (3.4.7)
126
+ sprockets (2.10.1)
127
+ hike (~> 1.2)
128
+ multi_json (~> 1.0)
129
+ rack (~> 1.0)
130
+ tilt (~> 1.1, != 1.3.0)
131
+ sprockets-rails (2.0.1)
132
+ actionpack (>= 3.0)
133
+ activesupport (>= 3.0)
134
+ sprockets (~> 2.8)
135
+ sqlite3 (1.3.8)
136
+ thor (0.18.1)
137
+ thread_safe (0.1.3)
138
+ atomic
139
+ tilt (1.4.1)
140
+ treetop (1.4.15)
141
+ polyglot
142
+ polyglot (>= 0.3.1)
143
+ tzinfo (0.3.38)
144
+ yard (0.8.7.3)
145
+
146
+ PLATFORMS
147
+ ruby
148
+
149
+ DEPENDENCIES
150
+ activerecord-jdbc-adapter
151
+ activerecord-jdbcsqlite3-adapter
152
+ activeresource (= 4.0.0)
153
+ appraisal (~> 1.0.0.beta2)
154
+ aruba
155
+ bcrypt-ruby (~> 3.1.2)
156
+ bourne (~> 1.3)
157
+ bundler (~> 1.1)
158
+ cucumber (~> 1.1)
159
+ jdbc-sqlite3
160
+ jquery-rails
161
+ jruby-openssl
162
+ protected_attributes
163
+ pry
164
+ rails (= 4.0.1)
165
+ rake (>= 0.9.2)
166
+ rspec-rails (>= 2.13.1, < 3)
167
+ sass-rails (= 4.0.1)
168
+ shoulda-context (~> 1.1.2)
169
+ shoulda-matchers!
170
+ sqlite3
171
+ therubyrhino
172
+ yard
@@ -0,0 +1 @@
1
+ require 'shoulda/matchers'
@@ -0,0 +1,11 @@
1
+ require 'shoulda/matchers/assertion_error'
2
+ require 'shoulda/matchers/error'
3
+ require 'shoulda/matchers/rails_shim'
4
+ require 'shoulda/matchers/warn'
5
+ require 'shoulda/matchers/version'
6
+
7
+ if defined?(RSpec)
8
+ require 'shoulda/matchers/integrations/rspec'
9
+ end
10
+
11
+ require 'shoulda/matchers/integrations/test_unit'
@@ -0,0 +1,17 @@
1
+ require 'shoulda/matchers/action_controller/filter_param_matcher'
2
+ require 'shoulda/matchers/action_controller/route_params'
3
+ require 'shoulda/matchers/action_controller/set_the_flash_matcher'
4
+ require 'shoulda/matchers/action_controller/render_with_layout_matcher'
5
+ require 'shoulda/matchers/action_controller/respond_with_matcher'
6
+ require 'shoulda/matchers/action_controller/set_session_matcher'
7
+ require 'shoulda/matchers/action_controller/route_matcher'
8
+ require 'shoulda/matchers/action_controller/redirect_to_matcher'
9
+ require 'shoulda/matchers/action_controller/render_template_matcher'
10
+ require 'shoulda/matchers/action_controller/rescue_from_matcher'
11
+
12
+ module Shoulda
13
+ module Matchers
14
+ module ActionController
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,64 @@
1
+ module Shoulda
2
+ module Matchers
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`.
7
+ #
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]
23
+ #
24
+ def filter_param(key)
25
+ FilterParamMatcher.new(key)
26
+ end
27
+
28
+ # @private
29
+ class FilterParamMatcher
30
+ def initialize(key)
31
+ @key = key.to_s
32
+ end
33
+
34
+ def matches?(controller)
35
+ filters_key?
36
+ end
37
+
38
+ def failure_message
39
+ "Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}"
40
+ end
41
+ alias failure_message_for_should failure_message
42
+
43
+ def failure_message_when_negated
44
+ "Did not expect #{@key} to be filtered"
45
+ end
46
+ alias failure_message_for_should_not failure_message_when_negated
47
+
48
+ def description
49
+ "filter #{@key}"
50
+ end
51
+
52
+ private
53
+
54
+ def filters_key?
55
+ filtered_keys.include?(@key)
56
+ end
57
+
58
+ def filtered_keys
59
+ Rails.application.config.filter_parameters.map(&:to_s)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,97 @@
1
+ module Shoulda
2
+ module Matchers
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`.
9
+ #
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 #list' do
19
+ # before { get :list }
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 #list' do
29
+ # setup { get :list }
30
+ #
31
+ # should redirect_to { posts_path }
32
+ # should redirect_to(action: :index)
33
+ # end
34
+ # end
35
+ #
36
+ # @return [RedirectToMatcher]
37
+ #
38
+ def redirect_to(url_or_description, &block)
39
+ RedirectToMatcher.new(url_or_description, self, &block)
40
+ end
41
+
42
+ # @private
43
+ class RedirectToMatcher
44
+ attr_reader :failure_message, :failure_message_when_negated
45
+
46
+ alias failure_message_for_should failure_message
47
+ alias failure_message_for_should_not failure_message_when_negated
48
+
49
+ def initialize(url_or_description, context, &block)
50
+ if block
51
+ @url_block = block
52
+ @location = url_or_description
53
+ else
54
+ @url = url_or_description
55
+ @location = @url
56
+ end
57
+ @context = context
58
+ end
59
+
60
+ def in_context(context)
61
+ @context = context
62
+ self
63
+ end
64
+
65
+ def matches?(controller)
66
+ @controller = controller
67
+ redirects_to_url?
68
+ end
69
+
70
+ def description
71
+ "redirect to #{@location}"
72
+ end
73
+
74
+ private
75
+
76
+ def redirects_to_url?
77
+ begin
78
+ @context.__send__(:assert_redirected_to, url)
79
+ @failure_message_when_negated = "Didn't expect to redirect to #{url}"
80
+ true
81
+ rescue Shoulda::Matchers::AssertionError => error
82
+ @failure_message = error.message
83
+ false
84
+ end
85
+ end
86
+
87
+ def url
88
+ if @url_block
89
+ @context.instance_eval(&@url_block)
90
+ else
91
+ @url
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,81 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module ActionController
4
+ # The `render_template` matcher tests that an action renders a template.
5
+ # In RSpec, it is very similar to rspec-rails's `render_template`
6
+ # matcher. In Test::Unit, it provides a more expressive syntax over
7
+ # `assert_template`.
8
+ #
9
+ # class PostsController < ApplicationController
10
+ # def show
11
+ # end
12
+ # end
13
+ #
14
+ # # RSpec
15
+ # describe PostsController do
16
+ # describe 'GET #show' do
17
+ # before { get :show }
18
+ #
19
+ # it { should render_template('show') }
20
+ # end
21
+ # end
22
+ #
23
+ # # Test::Unit
24
+ # class PostsControllerTest < ActionController::TestCase
25
+ # context 'GET #show' do
26
+ # setup { get :show }
27
+ #
28
+ # should render_template('show')
29
+ # end
30
+ # end
31
+ #
32
+ # @return [RenderTemplateMatcher]
33
+ #
34
+ def render_template(options = {}, message = nil)
35
+ RenderTemplateMatcher.new(options, message, self)
36
+ end
37
+
38
+ # @private
39
+ class RenderTemplateMatcher
40
+ attr_reader :failure_message, :failure_message_when_negated
41
+
42
+ alias failure_message_for_should failure_message
43
+ alias failure_message_for_should_not failure_message_when_negated
44
+
45
+ def initialize(options, message, context)
46
+ @options = options
47
+ @message = message
48
+ @template = options.is_a?(Hash) ? options[:partial] : options
49
+ @context = context
50
+ end
51
+
52
+ def matches?(controller)
53
+ @controller = controller
54
+ renders_template?
55
+ end
56
+
57
+ def description
58
+ "render template #{@template}"
59
+ end
60
+
61
+ def in_context(context)
62
+ @context = context
63
+ self
64
+ end
65
+
66
+ private
67
+
68
+ def renders_template?
69
+ begin
70
+ @context.__send__(:assert_template, @options, @message)
71
+ @failure_message_when_negated = "Didn't expect to render #{@template}"
72
+ true
73
+ rescue Shoulda::Matchers::AssertionError => error
74
+ @failure_message = error.message
75
+ false
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end