shoulda-matchers 2.8.0 → 3.0.0.rc1

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 (171) hide show
  1. checksums.yaml +4 -4
  2. data/.hound_config/ruby.yml +7 -0
  3. data/.travis.yml +11 -54
  4. data/Appraisals +45 -100
  5. data/CONTRIBUTING.md +51 -7
  6. data/Gemfile +7 -19
  7. data/Gemfile.lock +60 -134
  8. data/Guardfile +5 -0
  9. data/NEWS.md +203 -0
  10. data/README.md +95 -50
  11. data/Rakefile +1 -0
  12. data/doc_config/yard/templates/default/layout/html/setup.rb +1 -1
  13. data/gemfiles/4.0.0.gemfile +10 -7
  14. data/gemfiles/4.0.0.gemfile.lock +103 -79
  15. data/gemfiles/4.0.1.gemfile +10 -7
  16. data/gemfiles/4.0.1.gemfile.lock +109 -83
  17. data/gemfiles/4.1.gemfile +10 -7
  18. data/gemfiles/4.1.gemfile.lock +109 -85
  19. data/gemfiles/4.2.gemfile +10 -9
  20. data/gemfiles/4.2.gemfile.lock +86 -78
  21. data/lib/shoulda/matchers.rb +13 -18
  22. data/lib/shoulda/matchers/action_controller.rb +4 -1
  23. data/lib/shoulda/matchers/action_controller/flash_store.rb +95 -0
  24. data/lib/shoulda/matchers/action_controller/{strong_parameters_matcher.rb → permit_matcher.rb} +147 -30
  25. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  26. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
  27. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +1 -1
  28. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  29. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -1
  30. data/lib/shoulda/matchers/action_controller/route_params.rb +15 -6
  31. data/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
  32. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +30 -136
  33. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +28 -109
  34. data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +103 -0
  35. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +1 -12
  36. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +79 -10
  37. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +10 -0
  38. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +21 -0
  39. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +24 -0
  40. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -5
  41. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +29 -10
  42. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +27 -10
  43. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +27 -12
  44. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +56 -20
  45. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +3 -11
  46. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +65 -0
  47. data/lib/shoulda/matchers/active_record/association_matcher.rb +40 -6
  48. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +21 -7
  49. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +11 -40
  50. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
  51. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -6
  52. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +137 -22
  53. data/lib/shoulda/matchers/configuration.rb +20 -0
  54. data/lib/shoulda/matchers/doublespeak.rb +11 -1
  55. data/lib/shoulda/matchers/doublespeak/double.rb +29 -11
  56. data/lib/shoulda/matchers/doublespeak/double_collection.rb +4 -3
  57. data/lib/shoulda/matchers/doublespeak/method_call.rb +35 -0
  58. data/lib/shoulda/matchers/doublespeak/object_double.rb +7 -2
  59. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +4 -3
  60. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +3 -3
  61. data/lib/shoulda/matchers/doublespeak/world.rb +21 -1
  62. data/lib/shoulda/matchers/integrations.rb +43 -0
  63. data/lib/shoulda/matchers/integrations/configuration.rb +68 -0
  64. data/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
  65. data/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
  66. data/lib/shoulda/matchers/integrations/libraries.rb +15 -0
  67. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +31 -0
  68. data/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
  69. data/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
  70. data/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
  71. data/lib/shoulda/matchers/integrations/libraries/rails.rb +30 -0
  72. data/lib/shoulda/matchers/integrations/rails.rb +12 -0
  73. data/lib/shoulda/matchers/integrations/registry.rb +28 -0
  74. data/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
  75. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
  76. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
  77. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
  78. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
  79. data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
  80. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
  81. data/lib/shoulda/matchers/rails_shim.rb +0 -40
  82. data/lib/shoulda/matchers/version.rb +1 -1
  83. data/script/SUPPORTED_VERSIONS +1 -1
  84. data/script/update_gems_in_all_appraisals +14 -0
  85. data/shoulda-matchers.gemspec +2 -2
  86. data/spec/acceptance/active_model_integration_spec.rb +4 -1
  87. data/spec/acceptance/independent_matchers_spec.rb +6 -6
  88. data/spec/acceptance/multiple_libraries_integration_spec.rb +52 -0
  89. data/spec/acceptance/rails_integration_spec.rb +15 -5
  90. data/spec/acceptance_spec_helper.rb +8 -0
  91. data/spec/doublespeak_spec_helper.rb +14 -0
  92. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +110 -0
  93. data/spec/support/acceptance/helpers.rb +2 -0
  94. data/spec/support/acceptance/helpers/base_helpers.rb +6 -1
  95. data/spec/support/acceptance/helpers/command_helpers.rb +6 -2
  96. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -8
  97. data/spec/support/acceptance/helpers/n_unit_helpers.rb +25 -0
  98. data/spec/support/acceptance/helpers/rspec_helpers.rb +2 -0
  99. data/spec/support/acceptance/helpers/step_helpers.rb +13 -19
  100. data/spec/support/acceptance/matchers/have_output.rb +1 -1
  101. data/spec/support/tests/bundle.rb +1 -1
  102. data/spec/support/tests/command_runner.rb +25 -13
  103. data/spec/support/tests/current_bundle.rb +47 -0
  104. data/spec/support/tests/database.rb +28 -0
  105. data/spec/support/tests/database_adapters/postgresql.rb +25 -0
  106. data/spec/support/tests/database_adapters/sqlite3.rb +26 -0
  107. data/spec/support/tests/database_configuration.rb +33 -0
  108. data/spec/support/tests/database_configuration_registry.rb +28 -0
  109. data/spec/support/tests/filesystem.rb +25 -2
  110. data/spec/support/unit/helpers/active_record_versions.rb +12 -0
  111. data/spec/support/unit/helpers/class_builder.rb +6 -2
  112. data/spec/support/unit/helpers/column_type_helpers.rb +26 -0
  113. data/spec/support/unit/helpers/controller_builder.rb +0 -28
  114. data/spec/support/unit/helpers/database_helpers.rb +18 -0
  115. data/spec/support/unit/helpers/model_builder.rb +38 -6
  116. data/spec/support/unit/helpers/rails_versions.rb +2 -2
  117. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +9 -8
  118. data/spec/support/unit/matchers/fail_with_message_matcher.rb +1 -1
  119. data/spec/support/unit/rails_application.rb +29 -13
  120. data/spec/support/unit/record_validating_confirmation_builder.rb +1 -2
  121. data/spec/support/unit/shared_examples/set_session_or_flash.rb +355 -0
  122. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +433 -0
  123. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +1 -5
  124. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +37 -0
  125. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +23 -147
  126. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +8 -285
  127. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +562 -0
  128. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +81 -14
  129. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +16 -8
  130. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +101 -9
  131. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +39 -1
  132. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +39 -1
  133. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +39 -0
  134. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -17
  135. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -17
  136. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -17
  137. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +838 -271
  138. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -19
  139. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +93 -0
  140. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +3 -3
  141. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +25 -0
  142. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +905 -0
  143. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +17 -11
  144. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
  145. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +144 -43
  146. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +1 -1
  147. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +36 -11
  148. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +29 -16
  149. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +8 -5
  150. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +1 -1
  151. data/spec/unit_spec_helper.rb +15 -14
  152. data/spec/warnings_spy.rb +1 -1
  153. metadata +68 -29
  154. data/docs.watchr +0 -5
  155. data/gemfiles/3.0.gemfile +0 -26
  156. data/gemfiles/3.0.gemfile.lock +0 -173
  157. data/gemfiles/3.1.gemfile +0 -32
  158. data/gemfiles/3.1.gemfile.lock +0 -212
  159. data/gemfiles/3.1_1.9.2.gemfile +0 -32
  160. data/gemfiles/3.1_1.9.2.gemfile.lock +0 -212
  161. data/gemfiles/3.2.gemfile +0 -33
  162. data/gemfiles/3.2.gemfile.lock +0 -212
  163. data/gemfiles/3.2_1.9.2.gemfile +0 -31
  164. data/gemfiles/3.2_1.9.2.gemfile.lock +0 -207
  165. data/lib/shoulda/matchers/assertion_error.rb +0 -27
  166. data/lib/shoulda/matchers/doublespeak/structs.rb +0 -10
  167. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +0 -39
  168. data/lib/shoulda/matchers/integrations/rspec.rb +0 -19
  169. data/lib/shoulda/matchers/integrations/test_unit.rb +0 -34
  170. data/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -331
  171. data/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -564
@@ -1,31 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal", "~> 1.0"
6
- gem "aruba"
7
- gem "bourne", "~> 1.3"
8
- gem "bundler", "~> 1.1"
9
- gem "pry-nav"
10
- gem "rails", "~> 3.2.13"
11
- gem "rake", ">= 0.9.2"
12
- gem "rspec-rails", "2.99.0"
13
- gem "yard"
14
- gem "redcarpet"
15
- gem "pygments.rb"
16
- gem "watchr"
17
- gem "shoulda-context", "~> 1.2.0"
18
- gem "sqlite3", :platform => :ruby
19
- gem "activerecord-jdbc-adapter", :platform => :jruby
20
- gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
21
- gem "jdbc-sqlite3", :platform => :jruby
22
- gem "jruby-openssl", :platform => :jruby
23
- gem "therubyrhino", :platform => :jruby
24
- gem "strong_parameters"
25
- gem "minitest", "~> 4.0"
26
- gem "minitest-reporters"
27
- gem "bcrypt-ruby", "~> 3.0.0"
28
- gem "jquery-rails"
29
- gem "sass-rails", "~> 3.2.3"
30
- gem "coffee-rails", "~> 3.2.1"
31
- gem "uglifier", ">= 1.0.3"
@@ -1,207 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- actionmailer (3.2.18)
5
- actionpack (= 3.2.18)
6
- mail (~> 2.5.4)
7
- actionpack (3.2.18)
8
- activemodel (= 3.2.18)
9
- activesupport (= 3.2.18)
10
- builder (~> 3.0.0)
11
- erubis (~> 2.7.0)
12
- journey (~> 1.0.4)
13
- rack (~> 1.4.5)
14
- rack-cache (~> 1.2)
15
- rack-test (~> 0.6.1)
16
- sprockets (~> 2.2.1)
17
- activemodel (3.2.18)
18
- activesupport (= 3.2.18)
19
- builder (~> 3.0.0)
20
- activerecord (3.2.18)
21
- activemodel (= 3.2.18)
22
- activesupport (= 3.2.18)
23
- arel (~> 3.0.2)
24
- tzinfo (~> 0.3.29)
25
- activeresource (3.2.18)
26
- activemodel (= 3.2.18)
27
- activesupport (= 3.2.18)
28
- activesupport (3.2.18)
29
- i18n (~> 0.6, >= 0.6.4)
30
- multi_json (~> 1.0)
31
- ansi (1.4.3)
32
- appraisal (1.0.0)
33
- bundler
34
- rake
35
- thor (>= 0.14.0)
36
- arel (3.0.3)
37
- aruba (0.6.0)
38
- childprocess (>= 0.3.6)
39
- cucumber (>= 1.1.1)
40
- rspec-expectations (>= 2.7.0)
41
- bcrypt-ruby (3.0.1)
42
- bourne (1.5.0)
43
- mocha (>= 0.13.2, < 0.15)
44
- builder (3.0.4)
45
- childprocess (0.5.3)
46
- ffi (~> 1.0, >= 1.0.11)
47
- coderay (1.1.0)
48
- coffee-rails (3.2.2)
49
- coffee-script (>= 2.2.0)
50
- railties (~> 3.2.0)
51
- coffee-script (2.2.0)
52
- coffee-script-source
53
- execjs
54
- coffee-script-source (1.7.0)
55
- cucumber (1.3.16)
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.1.1)
61
- diff-lcs (1.2.5)
62
- erubis (2.7.0)
63
- execjs (2.2.0)
64
- ffi (1.9.3)
65
- gherkin (2.12.2)
66
- multi_json (~> 1.3)
67
- hashie (3.3.1)
68
- hike (1.2.3)
69
- i18n (0.6.11)
70
- journey (1.0.4)
71
- jquery-rails (3.1.0)
72
- railties (>= 3.0, < 5.0)
73
- thor (>= 0.14, < 2.0)
74
- json (1.8.1)
75
- mail (2.5.4)
76
- mime-types (~> 1.16)
77
- treetop (~> 1.4.8)
78
- metaclass (0.0.4)
79
- method_source (0.8.2)
80
- mime-types (1.25.1)
81
- minitest (4.7.5)
82
- minitest-reporters (0.14.24)
83
- ansi
84
- builder
85
- minitest (>= 2.12, < 5.0)
86
- powerbar
87
- mocha (0.14.0)
88
- metaclass (~> 0.0.1)
89
- multi_json (1.10.1)
90
- multi_test (0.1.1)
91
- polyglot (0.3.5)
92
- posix-spawn (0.3.8)
93
- powerbar (1.0.11)
94
- ansi (~> 1.4.0)
95
- hashie (>= 1.1.0)
96
- pry (0.10.1)
97
- coderay (~> 1.1.0)
98
- method_source (~> 0.8.1)
99
- slop (~> 3.4)
100
- pry-nav (0.2.4)
101
- pry (>= 0.9.10, < 0.11.0)
102
- pygments.rb (0.6.0)
103
- posix-spawn (~> 0.3.6)
104
- yajl-ruby (~> 1.1.0)
105
- rack (1.4.5)
106
- rack-cache (1.2)
107
- rack (>= 0.4)
108
- rack-ssl (1.3.4)
109
- rack
110
- rack-test (0.6.2)
111
- rack (>= 1.0)
112
- rails (3.2.18)
113
- actionmailer (= 3.2.18)
114
- actionpack (= 3.2.18)
115
- activerecord (= 3.2.18)
116
- activeresource (= 3.2.18)
117
- activesupport (= 3.2.18)
118
- bundler (~> 1.0)
119
- railties (= 3.2.18)
120
- railties (3.2.18)
121
- actionpack (= 3.2.18)
122
- activesupport (= 3.2.18)
123
- rack-ssl (~> 1.3.2)
124
- rake (>= 0.8.7)
125
- rdoc (~> 3.4)
126
- thor (>= 0.14.6, < 2.0)
127
- rake (10.3.2)
128
- rdoc (3.12.2)
129
- json (~> 1.4)
130
- redcarpet (3.1.2)
131
- rspec-collection_matchers (1.0.0)
132
- rspec-expectations (>= 2.99.0.beta1)
133
- rspec-core (2.99.1)
134
- rspec-expectations (2.99.2)
135
- diff-lcs (>= 1.1.3, < 2.0)
136
- rspec-mocks (2.99.2)
137
- rspec-rails (2.99.0)
138
- actionpack (>= 3.0)
139
- activemodel (>= 3.0)
140
- activesupport (>= 3.0)
141
- railties (>= 3.0)
142
- rspec-collection_matchers
143
- rspec-core (~> 2.99.0)
144
- rspec-expectations (~> 2.99.0)
145
- rspec-mocks (~> 2.99.0)
146
- sass (3.3.8)
147
- sass-rails (3.2.6)
148
- railties (~> 3.2.0)
149
- sass (>= 3.1.10)
150
- tilt (~> 1.3)
151
- shoulda-context (1.2.1)
152
- slop (3.6.0)
153
- sprockets (2.2.2)
154
- hike (~> 1.2)
155
- multi_json (~> 1.0)
156
- rack (~> 1.0)
157
- tilt (~> 1.1, != 1.3.0)
158
- sqlite3 (1.3.9)
159
- strong_parameters (0.2.3)
160
- actionpack (~> 3.0)
161
- activemodel (~> 3.0)
162
- activesupport (~> 3.0)
163
- railties (~> 3.0)
164
- thor (0.19.1)
165
- tilt (1.4.1)
166
- treetop (1.4.15)
167
- polyglot
168
- polyglot (>= 0.3.1)
169
- tzinfo (0.3.39)
170
- uglifier (2.5.1)
171
- execjs (>= 0.3.0)
172
- json (>= 1.8.0)
173
- watchr (0.7)
174
- yajl-ruby (1.1.0)
175
- yard (0.8.7.4)
176
-
177
- PLATFORMS
178
- ruby
179
-
180
- DEPENDENCIES
181
- activerecord-jdbc-adapter
182
- activerecord-jdbcsqlite3-adapter
183
- appraisal (~> 1.0)
184
- aruba
185
- bcrypt-ruby (~> 3.0.0)
186
- bourne (~> 1.3)
187
- bundler (~> 1.1)
188
- coffee-rails (~> 3.2.1)
189
- jdbc-sqlite3
190
- jquery-rails
191
- jruby-openssl
192
- minitest (~> 4.0)
193
- minitest-reporters
194
- pry-nav
195
- pygments.rb
196
- rails (~> 3.2.13)
197
- rake (>= 0.9.2)
198
- redcarpet
199
- rspec-rails (= 2.99.0)
200
- sass-rails (~> 3.2.3)
201
- shoulda-context (~> 1.2.0)
202
- sqlite3
203
- strong_parameters
204
- therubyrhino
205
- uglifier (>= 1.0.3)
206
- watchr
207
- yard
@@ -1,27 +0,0 @@
1
- module Shoulda
2
- module Matchers
3
- if defined?(ActiveSupport::TestCase)
4
- # @private
5
- AssertionError = ActiveSupport::TestCase::Assertion
6
- elsif Gem.ruby_version >= Gem::Version.new('1.8') && Gem.ruby_version < Gem::Version.new('1.9')
7
- require 'test/unit'
8
- # @private
9
- AssertionError = Test::Unit::AssertionFailedError
10
- elsif defined?(Test::Unit::AssertionFailedError)
11
- # Test::Unit has been loaded already, so we use it
12
- # @private
13
- AssertionError = Test::Unit::AssertionFailedError
14
- elsif Gem.ruby_version >= Gem::Version.new("1.9")
15
- begin
16
- require 'minitest'
17
- rescue LoadError
18
- require 'minitest/unit'
19
- ensure
20
- # @private
21
- AssertionError = MiniTest::Assertion
22
- end
23
- else
24
- raise 'No unit test library available'
25
- end
26
- end
27
- end
@@ -1,10 +0,0 @@
1
- module Shoulda
2
- module Matchers
3
- module Doublespeak
4
- # @private
5
- MethodCall = Struct.new(:args, :block)
6
- # @private
7
- MethodCallWithName = Struct.new(:method_name, :args, :block)
8
- end
9
- end
10
- end
@@ -1,39 +0,0 @@
1
- module Shoulda
2
- module Matchers
3
- # @private
4
- module Integrations
5
- # @private
6
- module NUnitTestCaseDetection
7
- def self.possible_test_case_constants
8
- [
9
- -> { ActiveSupport::TestCase },
10
- -> { Minitest::Test },
11
- -> { MiniTest::Unit::TestCase },
12
- -> { Test::Unit::TestCase }
13
- ]
14
- end
15
-
16
- def self.resolve_constant(future_constant)
17
- future_constant.call
18
- rescue NameError
19
- nil
20
- end
21
-
22
- def self.detected_test_case_constants
23
- possible_test_case_constants.
24
- map { |future_constant| resolve_constant(future_constant) }.
25
- compact
26
- end
27
-
28
- def self.test_case_constants
29
- @_test_case_constants ||= detected_test_case_constants
30
- end
31
- end
32
- end
33
-
34
- # @private
35
- def self.nunit_test_case_constants
36
- Integrations::NUnitTestCaseDetection.test_case_constants
37
- end
38
- end
39
- end
@@ -1,19 +0,0 @@
1
- # :enddoc:
2
-
3
- if RSpec.respond_to?(:configure)
4
- RSpec.configure do |config|
5
- config.include Shoulda::Matchers::Independent
6
-
7
- if defined?(ActiveRecord)
8
- config.include Shoulda::Matchers::ActiveRecord
9
- end
10
-
11
- if defined?(ActiveModel)
12
- config.include Shoulda::Matchers::ActiveModel
13
- end
14
-
15
- if defined?(ActionController)
16
- config.include Shoulda::Matchers::ActionController
17
- end
18
- end
19
- end
@@ -1,34 +0,0 @@
1
- # :enddoc:
2
- require 'shoulda/matchers/integrations/nunit_test_case_detection'
3
-
4
- Shoulda::Matchers.nunit_test_case_constants.each do |constant|
5
- constant.class_eval do
6
- include Shoulda::Matchers::Independent
7
- extend Shoulda::Matchers::Independent
8
- end
9
- end
10
-
11
- if defined?(ActionController::TestCase)
12
- ActionController::TestCase.class_eval do
13
- include Shoulda::Matchers::ActionController
14
- extend Shoulda::Matchers::ActionController
15
-
16
- def subject
17
- @controller
18
- end
19
- end
20
- end
21
-
22
- if defined?(ActiveSupport::TestCase)
23
- ActiveSupport::TestCase.class_eval do
24
- if defined?(Shoulda::Matchers::ActiveRecord)
25
- include Shoulda::Matchers::ActiveRecord
26
- extend Shoulda::Matchers::ActiveRecord
27
- end
28
-
29
- if defined?(Shoulda::Matchers::ActiveModel)
30
- include Shoulda::Matchers::ActiveModel
31
- extend Shoulda::Matchers::ActiveModel
32
- end
33
- end
34
- end
@@ -1,331 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController, type: :controller do
4
- describe '#permit' do
5
- it 'matches when the sent parameter is allowed' do
6
- controller_for_resource_with_strong_parameters(action: :create) do
7
- params.require(:user).permit(:name)
8
- end
9
-
10
- expect(@controller).to permit(:name).for(:create)
11
- end
12
-
13
- it 'does not match when the sent parameter is not allowed' do
14
- controller_for_resource_with_strong_parameters(action: :create) do
15
- params.require(:user).permit(:name)
16
- end
17
-
18
- expect(@controller).not_to permit(:admin).for(:create)
19
- end
20
-
21
- it 'matches against multiple attributes' do
22
- controller_for_resource_with_strong_parameters(action: :create) do
23
- params.require(:user).permit(:name, :age)
24
- end
25
-
26
- expect(@controller).to permit(:name, :age).for(:create)
27
- end
28
-
29
- it 'can be used more than once in the same test' do
30
- controller_for_resource_with_strong_parameters(action: :create) do
31
- params.require(:user).permit(:name)
32
- end
33
-
34
- expect(@controller).to permit(:name).for(:create)
35
- expect(@controller).not_to permit(:admin).for(:create)
36
- end
37
- end
38
- end
39
-
40
- describe Shoulda::Matchers::ActionController::StrongParametersMatcher, type: :controller do
41
- describe '#description' do
42
- it 'returns the correct string' do
43
- options = { action: :create, method: :post }
44
- controller_for_resource_with_strong_parameters(options) do
45
- params.permit(:name, :age)
46
- end
47
-
48
- matcher = described_class.new([:name, :age, :height]).for(:create)
49
- expect(matcher.description).
50
- to eq 'permit POST #create to receive parameters :name, :age, and :height'
51
- end
52
-
53
- context 'when a verb is specified' do
54
- it 'returns the correct string' do
55
- options = { action: :some_action }
56
- controller_for_resource_with_strong_parameters(options) do
57
- params.permit(:name, :age)
58
- end
59
-
60
- matcher = described_class.new([:name]).
61
- for(:some_action, verb: :put)
62
- expect(matcher.description).
63
- to eq 'permit PUT #some_action to receive parameters :name'
64
- end
65
- end
66
- end
67
-
68
- describe '#matches?' do
69
- it 'is true for a subset of the allowable attributes' do
70
- controller_for_resource_with_strong_parameters(action: :create) do
71
- params.require(:user).permit(:name)
72
- end
73
-
74
- matcher = described_class.new([:name]).in_context(self).for(:create)
75
- expect(matcher.matches?(@controller)).to be true
76
- end
77
-
78
- it 'is true for all the allowable attributes' do
79
- controller_for_resource_with_strong_parameters(action: :create) do
80
- params.require(:user).permit(:name, :age)
81
- end
82
-
83
- matcher = described_class.new([:name, :age]).in_context(self).for(:create)
84
- expect(matcher.matches?(@controller)).to be true
85
- end
86
-
87
- it 'is false when any attributes are not allowed' do
88
- controller_for_resource_with_strong_parameters(action: :create) do
89
- params.require(:user).permit(:name)
90
- end
91
-
92
- matcher = described_class.new([:name, :admin]).in_context(self).for(:create)
93
- expect(matcher.matches?(@controller)).to be false
94
- end
95
-
96
- it 'is false when permit is not called' do
97
- controller_for_resource_with_strong_parameters(action: :create)
98
-
99
- matcher = described_class.new([:name]).in_context(self).for(:create)
100
- expect(matcher.matches?(@controller)).to be false
101
- end
102
-
103
- it 'requires an action' do
104
- controller_for_resource_with_strong_parameters
105
- matcher = described_class.new([:name])
106
- expect { matcher.matches?(@controller) }.
107
- to raise_error(described_class::ActionNotDefinedError)
108
- end
109
-
110
- it 'requires a verb for non-restful action' do
111
- controller_for_resource_with_strong_parameters
112
- matcher = described_class.new([:name]).for(:authorize)
113
- expect { matcher.matches?(@controller) }.
114
- to raise_error(described_class::VerbNotDefinedError)
115
- end
116
-
117
- it 'works with routes that require extra params' do
118
- options = {
119
- controller_name: 'Posts',
120
- action: :show,
121
- routes: -> {
122
- get '/posts/:slug', to: 'posts#show'
123
- }
124
- }
125
- controller_for_resource_with_strong_parameters(options) do
126
- params.require(:user).permit(:name)
127
- end
128
-
129
- matcher = described_class.new([:name]).
130
- in_context(self).
131
- for(:show, verb: :get, params: { slug: 'foo' })
132
- expect(matcher.matches?(@controller)).to be true
133
- end
134
-
135
- it 'works with #update specifically' do
136
- controller_for_resource_with_strong_parameters(action: :update) do
137
- params.require(:user).permit(:name)
138
- end
139
-
140
- matcher = described_class.new([:name]).
141
- in_context(self).
142
- for(:update, params: { id: 1 })
143
- expect(matcher.matches?(@controller)).to be true
144
- end
145
-
146
- it 'does not raise an error when #fetch was used instead of #require (issue #495)' do
147
- controller_for_resource_with_strong_parameters(action: :create) do
148
- params.fetch(:order, {}).permit(:eta, :diner_id)
149
- end
150
-
151
- matcher = described_class.new([:eta, :diner_id]).
152
- in_context(self).
153
- for(:create)
154
- expect(matcher.matches?(@controller)).to be true
155
- end
156
-
157
- it 'tracks multiple calls to #permit' do
158
- sets_of_attributes = [
159
- [:eta, :diner_id],
160
- [:phone_number, :address_1, :address_2, :city, :state, :zip]
161
- ]
162
- controller_for_resource_with_strong_parameters(action: :create) do
163
- params.require(:order).permit(sets_of_attributes[0])
164
- params.require(:diner).permit(sets_of_attributes[1])
165
- end
166
-
167
- matcher = described_class.new(sets_of_attributes[0]).
168
- in_context(self).
169
- for(:create)
170
- expect(matcher.matches?(@controller)).to be true
171
-
172
- matcher = described_class.new(sets_of_attributes[1]).
173
- in_context(self).
174
- for(:create)
175
- expect(matcher.matches?(@controller)).to be true
176
- end
177
-
178
- context 'stubbing params on the controller' do
179
- it 'still allows the original params to be set and accessed' do
180
- actual_user_params = nil
181
- actual_foo_param = nil
182
-
183
- controller_for_resource_with_strong_parameters(action: :create) do
184
- params[:foo] = 'bar'
185
- actual_foo_param = params[:foo]
186
-
187
- actual_user_params = params[:user]
188
-
189
- params.require(:user).permit(:name)
190
- end
191
-
192
- matcher = described_class.new([:name]).
193
- in_context(self).
194
- for(:create, params: { user: { some: 'params' } })
195
- matcher.matches?(@controller)
196
-
197
- expect(actual_user_params).to eq('some' => 'params')
198
- expect(actual_foo_param).to eq 'bar'
199
- end
200
-
201
- it 'stubs the params during the controller action' do
202
- controller_for_resource_with_strong_parameters(action: :create) do
203
- params.require(:user)
204
- end
205
-
206
- matcher = described_class.new([:name]).in_context(self).for(:create)
207
-
208
- expect { matcher.matches?(@controller) }.not_to raise_error
209
- end
210
-
211
- it 'does not permanently stub params' do
212
- controller_for_resource_with_strong_parameters(action: :create)
213
-
214
- matcher = described_class.new([:name]).in_context(self).for(:create)
215
- matcher.matches?(@controller)
216
-
217
- expect {
218
- @controller.params.require(:user)
219
- }.to raise_error(::ActionController::ParameterMissing)
220
- end
221
-
222
- it 'prevents permanently stubbing params on error' do
223
- stub_controller_with_exception
224
-
225
- begin
226
- matcher = described_class.new([:name]).in_context(self).for(:create)
227
- matcher.matches?(@controller)
228
- rescue SimulatedError
229
- end
230
-
231
- expect {
232
- @controller.params.require(:user)
233
- }.to raise_error(::ActionController::ParameterMissing)
234
- end
235
- end
236
- end
237
-
238
- describe 'failure message' do
239
- it 'includes all missing attributes' do
240
- controller_for_resource_with_strong_parameters(action: :create) do
241
- params.require(:user).permit(:name, :age)
242
- end
243
-
244
- expect {
245
- expect(@controller).to permit(:name, :age, :city, :country).for(:create)
246
- }.to fail_with_message('Expected controller to permit city and country, but it did not.')
247
- end
248
-
249
- it 'includes all attributes that should not have been allowed but were' do
250
- controller_for_resource_with_strong_parameters(action: :create) do
251
- params.require(:user).permit(:name, :age)
252
- end
253
-
254
- expect {
255
- expect(@controller).not_to permit(:name, :age).for(:create)
256
- }.to fail_with_message('Expected controller not to permit name and age, but it did.')
257
- end
258
- end
259
-
260
- describe '#for' do
261
- context 'when given :create' do
262
- it 'POSTs to the controller' do
263
- controller = ActionController::Base.new
264
- context = build_context
265
- matcher = described_class.new([:name]).in_context(context).for(:create)
266
-
267
- matcher.matches?(controller)
268
-
269
- expect(context).to have_received(:post).with(:create, {})
270
- end
271
- end
272
-
273
- context 'when given :update' do
274
- if rails_gte_4_1?
275
- it 'PATCHes to the controller' do
276
- controller = ActionController::Base.new
277
- context = build_context
278
- matcher = described_class.new([:name]).in_context(context).for(:update)
279
-
280
- matcher.matches?(controller)
281
-
282
- expect(context).to have_received(:patch).with(:update, {})
283
- end
284
- else
285
- it 'PUTs to the controller' do
286
- controller = ActionController::Base.new
287
- context = build_context
288
- matcher = described_class.new([:name]).in_context(context).for(:update)
289
-
290
- matcher.matches?(controller)
291
-
292
- expect(context).to have_received(:put).with(:update, {})
293
- end
294
- end
295
- end
296
-
297
- context 'when given a custom action and verb' do
298
- it 'calls the action with the verb' do
299
- controller = ActionController::Base.new
300
- context = build_context
301
- matcher = described_class.new([:name]).
302
- in_context(context).
303
- for(:hide, verb: :delete)
304
-
305
- matcher.matches?(controller)
306
-
307
- expect(context).to have_received(:delete).with(:hide, {})
308
- end
309
- end
310
- end
311
-
312
- def stub_controller_with_exception
313
- controller_class = define_controller('Examples') do
314
- def create
315
- raise SimulatedError
316
- end
317
- end
318
-
319
- setup_rails_controller_test(controller_class)
320
-
321
- define_routes do
322
- get 'examples', to: 'examples#create'
323
- end
324
- end
325
-
326
- def build_context
327
- double('context', post: nil, put: nil, patch: nil, delete: nil)
328
- end
329
-
330
- class SimulatedError < StandardError; end
331
- end