shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
@@ -1,42 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::RedirectToMatcher, type: :controller do
4
- context 'a controller that redirects' do
5
- it 'accepts redirecting to that url' do
6
- expect(controller_redirecting_to('/some/url')).to redirect_to('/some/url')
7
- end
8
-
9
- it 'rejects redirecting to a different url' do
10
- expect(controller_redirecting_to('/some/url')).
11
- not_to redirect_to('/some/other/url')
12
- end
13
-
14
- it 'accepts redirecting to that url in a block' do
15
- expect(controller_redirecting_to('/some/url')).
16
- to redirect_to('somewhere') { '/some/url' }
17
- end
18
-
19
- it 'rejects redirecting to a different url in a block' do
20
- expect(controller_redirecting_to('/some/url')).
21
- not_to redirect_to('somewhere else') { '/some/other/url' }
22
- end
23
-
24
- def controller_redirecting_to(url)
25
- build_fake_response { redirect_to url }
26
- end
27
- end
28
-
29
- context 'a controller that does not redirect' do
30
- it 'rejects redirecting to a url' do
31
- controller = build_fake_response { render text: 'hello' }
32
-
33
- expect(controller).not_to redirect_to('/some/url')
34
- end
35
- end
36
-
37
- it 'provides the correct description when provided a block' do
38
- matcher = redirect_to('somewhere else') { '/some/other/url' }
39
-
40
- expect(matcher.description).to eq 'redirect to "somewhere else"'
41
- end
42
- end
@@ -1,76 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::RenderTemplateMatcher, type: :controller do
4
- context 'a controller that renders a template' do
5
- it 'accepts rendering that template' do
6
- expect(controller_with_show).to render_template(:show)
7
- end
8
-
9
- it 'rejects rendering a different template' do
10
- expect(controller_with_show).not_to render_template(:index)
11
- end
12
-
13
- it 'accepts rendering that template in the given context' do
14
- expect(controller_with_show).to render_template(:show).in_context(self)
15
- end
16
-
17
- it 'rejects rendering a different template in the given context' do
18
- expect(controller_with_show).not_to render_template(:index).in_context(self)
19
- end
20
-
21
- def controller_with_show
22
- build_fake_response(action: 'show') { render }
23
- end
24
- end
25
-
26
- context 'a controller that renders a partial' do
27
- it 'accepts rendering that partial' do
28
- expect(controller_with_customer_partial).
29
- to render_template(partial: '_customer')
30
- end
31
-
32
- it 'rejects rendering a different template' do
33
- expect(controller_with_customer_partial).
34
- not_to render_template(partial: '_client')
35
- end
36
-
37
- it 'accepts rendering that template in the given context' do
38
- expect(controller_with_customer_partial).
39
- to render_template(partial: '_customer').in_context(self)
40
- end
41
-
42
- it 'rejects rendering a different template in the given context' do
43
- expect(controller_with_customer_partial).
44
- not_to render_template(partial: '_client').in_context(self)
45
- end
46
-
47
- def controller_with_customer_partial
48
- build_fake_response(partial: '_customer') { render partial: 'customer' }
49
- end
50
- end
51
-
52
- context 'a controller that does not render partials' do
53
- it 'accepts not rendering a partial' do
54
- controller = build_fake_response(action: 'show') { render }
55
-
56
- expect(controller).to render_template(partial: false)
57
- end
58
- end
59
-
60
- context 'a controller that renders a partial several times' do
61
- it 'accepts rendering that partial twice' do
62
- controller = build_fake_response(partial: '_customer') do
63
- render partial: 'customer', collection: [1,2]
64
- end
65
-
66
- expect(controller).to render_template(partial: '_customer', count: 2)
67
- end
68
- end
69
-
70
- context 'a controller that does not render a template' do
71
- it 'rejects rendering a template' do
72
- expect(build_fake_response { head :ok }).
73
- not_to render_template(:show)
74
- end
75
- end
76
- end
@@ -1,62 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher, type: :controller do
4
- include ActionController::TemplateAssertions
5
-
6
- context 'a controller that renders with a layout' do
7
- it 'accepts rendering with any layout' do
8
- expect(controller_with_wide_layout).to render_with_layout
9
- end
10
-
11
- it 'accepts rendering with that layout' do
12
- expect(controller_with_wide_layout).to render_with_layout(:wide)
13
- end
14
-
15
- it 'rejects rendering with another layout' do
16
- expect(controller_with_wide_layout).not_to render_with_layout(:other)
17
- end
18
-
19
- def controller_with_wide_layout
20
- create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
21
- build_fake_response { render layout: 'wide' }
22
- end
23
- end
24
-
25
- context 'a controller that renders without a layout' do
26
-
27
- it 'rejects rendering with a layout' do
28
- controller_without_layout = build_fake_response { render layout: false }
29
-
30
- expect(controller_without_layout).not_to render_with_layout
31
- end
32
- end
33
-
34
- context 'a controller that renders a partial' do
35
- it 'rejects rendering with a layout' do
36
- controller_with_partial = build_fake_response { render partial: 'partial' }
37
-
38
- expect(controller_with_partial).not_to render_with_layout
39
- end
40
- end
41
-
42
- context 'given a context with layouts' do
43
- it 'accepts that layout in that context' do
44
- context = Object.new
45
- set_layout_in_context(context, 'happy')
46
-
47
- expect(controller_without_layout).
48
- to render_with_layout('happy').
49
- in_context(context)
50
- end
51
-
52
- def set_layout_in_context(context, layout)
53
- layouts = Hash.new(0)
54
- layouts[layout] = 1
55
- context.instance_variable_set('@_layouts', layouts)
56
- end
57
-
58
- def controller_without_layout
59
- build_fake_response { render layout: false }
60
- end
61
- end
62
- end
@@ -1,90 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::RescueFromMatcher, type: :controller do
4
- context 'a controller that rescues from RuntimeError' do
5
- it 'asserts controller is setup with rescue_from' do
6
- expect(controller_with_rescue_from).to rescue_from RuntimeError
7
- end
8
-
9
- context 'with a handler method' do
10
- it 'asserts rescue_from can find the handler when it is public' do
11
- controller = controller_with_rescue_from_and_method(:public)
12
- check_rescue_with_method_for(controller)
13
- end
14
-
15
- it 'asserts rescue_from can find the handler when it is protected' do
16
- controller = controller_with_rescue_from_and_method(:protected)
17
- check_rescue_with_method_for(controller)
18
- end
19
-
20
- it 'asserts rescue_from can find the handler when it is private' do
21
- controller = controller_with_rescue_from_and_method(:private)
22
- check_rescue_with_method_for(controller)
23
- end
24
-
25
- it 'asserts rescue_from was not set up with incorrect handler method' do
26
- expect(controller_with_rescue_from_and_method).not_to rescue_from(RuntimeError).with(:other_method)
27
- end
28
-
29
- it 'asserts the controller responds to the handler method' do
30
- matcher = rescue_from(RuntimeError).with(:error_method)
31
- expect(matcher.matches?(controller_with_rescue_from_and_invalid_method)).to eq false
32
- expect(matcher.failure_message).to match(/does not respond to/)
33
- end
34
- end
35
-
36
- context 'without a handler method' do
37
- it 'the handler method is not included in the description' do
38
- matcher = rescue_from(RuntimeError)
39
- expect(matcher.matches?(controller_with_rescue_from)).to eq true
40
- expect(matcher.description).not_to match(/with #/)
41
- end
42
- end
43
- end
44
-
45
- context 'a controller that does not rescue from RuntimeError' do
46
- it 'asserts controller is not setup with rescue_from' do
47
- matcher = rescue_from RuntimeError
48
- expect(define_controller('RandomController')).not_to matcher
49
- expect(matcher.failure_message_when_negated).to match(/Did not expect \w+ to rescue from/)
50
- end
51
- end
52
-
53
- def check_rescue_with_method_for(controller)
54
- expect(controller).to rescue_from(RuntimeError).with(:error_method)
55
- end
56
-
57
- def controller_with_rescue_from
58
- define_controller 'RescueRuntimeError' do
59
- rescue_from(RuntimeError) {}
60
- end
61
- end
62
-
63
- def controller_with_rescue_from_and_invalid_method
64
- define_controller 'RescueRuntimeErrorWithMethod' do
65
- rescue_from RuntimeError, with: :error_method
66
- end
67
- end
68
-
69
- def controller_with_rescue_from_and_method(access = :public)
70
- controller = controller_with_rescue_from_and_invalid_method
71
- class << controller
72
- def error_method
73
- true
74
- end
75
- end
76
-
77
- case access
78
- when :protected
79
- class << controller
80
- protected :error_method
81
- end
82
- when :private
83
- class << controller
84
- private :error_method
85
- end
86
- end
87
-
88
- controller
89
- end
90
- end
@@ -1,31 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::RespondWithMatcher, type: :controller do
4
- statuses = { success: 200, redirect: 301, missing: 404, error: 500,
5
- not_implemented: 501 }
6
-
7
- statuses.each do |human_name, numeric_code|
8
- context "a controller responding with #{human_name}" do
9
- it 'accepts responding with a numeric response code' do
10
- expect(controller_with_status(numeric_code)).to respond_with(numeric_code)
11
- end
12
-
13
- it 'accepts responding with a symbol response code' do
14
- expect(controller_with_status(numeric_code)).to respond_with(human_name)
15
- end
16
-
17
- it 'rejects responding with another status' do
18
- another_status = statuses.except(human_name).keys.first
19
-
20
- expect(controller_with_status(numeric_code)).
21
- not_to respond_with(another_status)
22
- end
23
- end
24
- end
25
-
26
- def controller_with_status(status)
27
- build_fake_response do
28
- render text: 'text', status: status
29
- end
30
- end
31
- end
@@ -1,330 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe 'Shoulda::Matchers::ActionController::RouteMatcher', type: :controller do
4
- shared_examples_for 'tests involving expected route parts' do |args|
5
- include_controller_in_expected_route_options =
6
- args.fetch(:include_controller_in_expected_route_options)
7
-
8
- context 'when all parts of the expected route match an existing route' do
9
- it 'accepts' do
10
- define_route :get, '/', action: 'index'
11
-
12
- assert_accepts add_target_to(
13
- route(:get, '/'),
14
- build_expected_route_options(
15
- include_controller_in_expected_route_options,
16
- action: 'index'
17
- )
18
- )
19
- end
20
-
21
- if include_controller_in_expected_route_options
22
- context 'and the expected controller is specified as a symbol' do
23
- it 'accepts' do
24
- define_route :get, '/', action: 'index'
25
-
26
- assert_accepts add_target_to(
27
- route(:get, '/'),
28
- build_expected_route_options(
29
- include_controller_in_expected_route_options,
30
- action: 'index'
31
- )
32
- )
33
- end
34
- end
35
- end
36
-
37
- context 'and the expected action is specified as a symbol' do
38
- it 'accepts' do
39
- define_route :get, '/', action: 'index'
40
-
41
- assert_accepts add_target_to(
42
- route(:get, '/'),
43
- build_expected_route_options(
44
- include_controller_in_expected_route_options,
45
- action: :index
46
- )
47
- )
48
- end
49
- end
50
- end
51
-
52
- context 'when no parts of the expected route match an existing route' do
53
- it 'rejects' do
54
- assert_rejects add_target_to(
55
- route(:get, '/non_existent_route'),
56
- controller: 'no_controller',
57
- action: 'no_action'
58
- )
59
- end
60
- end
61
-
62
- context 'when all parts of the expected route but the method match an existing route' do
63
- it 'rejects' do
64
- define_route :post, '/', action: 'index'
65
-
66
- assert_rejects add_target_to(
67
- route(:get, '/'),
68
- build_expected_route_options(
69
- include_controller_in_expected_route_options,
70
- action: 'index'
71
- )
72
- )
73
- end
74
- end
75
-
76
- context 'when all parts of the expected route but the path match an existing route' do
77
- it 'rejects' do
78
- define_route :get, '/', action: 'index'
79
-
80
- assert_rejects add_target_to(
81
- route(:get, '/different_path'),
82
- build_expected_route_options(
83
- include_controller_in_expected_route_options,
84
- action: 'index'
85
- )
86
- )
87
- end
88
- end
89
-
90
- if include_controller_in_expected_route_options
91
- context 'when all parts of the expected route but the controller match an existing route' do
92
- it 'rejects' do
93
- define_route :get, '/', controller: 'another_controller', action: 'index'
94
-
95
- assert_rejects add_target_to(
96
- route(:get, '/'),
97
- build_expected_route_options(
98
- include_controller_in_expected_route_options,
99
- action: 'index'
100
- )
101
- )
102
- end
103
- end
104
- end
105
-
106
- context 'when all parts of the expected route but the action match an existing route' do
107
- it 'rejects' do
108
- define_route :get, '/', action: 'index'
109
-
110
- assert_rejects add_target_to(
111
- route(:get, '/'),
112
- build_expected_route_options(
113
- include_controller_in_expected_route_options,
114
- action: 'another_action'
115
- )
116
- )
117
- end
118
- end
119
- end
120
-
121
- shared_examples_for 'tests involving params' do
122
- context 'when the actual route has a param' do
123
- context 'and the expected params include that param' do
124
- it 'accepts' do
125
- define_route :get, "/#{controller_name}/:id", action: 'show'
126
-
127
- assert_accepts add_target_to(
128
- route(:get, "/#{controller_name}/1"),
129
- controller: controller_name,
130
- action: 'show',
131
- id: '1'
132
- )
133
- end
134
-
135
- context 'but its value was not specified as a string' do
136
- it 'accepts, treating it as a string' do
137
- define_route :get, "/#{controller_name}/:id", action: 'show'
138
-
139
- assert_accepts add_target_to(
140
- route(:get, "/#{controller_name}/1"),
141
- controller: controller_name,
142
- action: 'show',
143
- id: 1
144
- )
145
- end
146
- end
147
- end
148
-
149
- context 'and the expected params do not match the actual params' do
150
- it 'rejects' do
151
- define_route :get, "/#{controller_name}/:id", action: 'show'
152
-
153
- params = {
154
- controller: controller_name,
155
- action: 'show',
156
- some: 'other',
157
- params: 'here'
158
- }
159
- assert_rejects add_target_to(
160
- route(:get, "/#{controller_name}/:id"),
161
- params
162
- )
163
- end
164
- end
165
- end
166
-
167
- context 'when the actual route has a default param whose value is a symbol' do
168
- context 'and the expected params include a value for it' do
169
- context 'as a symbol' do
170
- it 'accepts' do
171
- define_route :post, "/#{controller_name}/(.:format)",
172
- action: 'create',
173
- defaults: { format: :json }
174
-
175
- assert_accepts add_target_to(
176
- route(:post, "/#{controller_name}"),
177
- controller: controller_name,
178
- action: 'create',
179
- format: :json
180
- )
181
- end
182
- end
183
-
184
- context 'as a string' do
185
- it 'accepts' do
186
- define_route :post, "/#{controller_name}/(.:format)",
187
- action: 'create',
188
- defaults: { format: :json }
189
-
190
- assert_accepts add_target_to(
191
- route(:post, "/#{controller_name}"),
192
- controller: controller_name,
193
- action: 'create',
194
- format: 'json'
195
- )
196
- end
197
- end
198
- end
199
- end
200
-
201
- context 'when the existing route has a glob segment' do
202
- context 'and a param is given which represents the segment' do
203
- it 'accepts' do
204
- define_route :get, "/#{controller_name}/*id", action: 'whatever'
205
-
206
- assert_accepts add_target_to(
207
- route(:get, "/#{controller_name}/foo/bar"),
208
- controller: controller_name,
209
- action: 'whatever',
210
- id: 'foo/bar'
211
- )
212
- end
213
- end
214
-
215
- context 'and no param is given which represents the segment' do
216
- it 'rejects' do
217
- define_route :get, "/#{controller_name}/*id", action: 'whatever'
218
-
219
- assert_rejects add_target_to(
220
- route(:get, "/#{controller_name}"),
221
- controller: controller_name,
222
- action: 'whatever'
223
- )
224
- end
225
- end
226
- end
227
- end
228
-
229
- shared_examples_for 'core tests' do
230
- context 'given a controller and action specified as individual options' do
231
- include_examples 'tests involving expected route parts',
232
- include_controller_in_expected_route_options: true
233
-
234
- include_examples 'tests involving params'
235
-
236
- def add_target_to(route_matcher, params)
237
- route_matcher.to(params)
238
- end
239
- end
240
-
241
- context 'given a controller and action joined together in a string' do
242
- include_examples 'tests involving expected route parts',
243
- include_controller_in_expected_route_options: true
244
-
245
- include_examples 'tests involving params'
246
-
247
- def add_target_to(route_matcher, args)
248
- controller = args.fetch(:controller)
249
- action = args.fetch(:action)
250
- route_matcher.to("#{controller}##{action}", args)
251
- end
252
- end
253
-
254
- context 'given just an action' do
255
- include_examples 'tests involving expected route parts',
256
- include_controller_in_expected_route_options: false
257
-
258
- include_examples 'tests involving params'
259
-
260
- def add_target_to(route_matcher, params)
261
- route_matcher.to(params)
262
- end
263
- end
264
- end
265
-
266
- before do
267
- setup_rails_controller_test(controller_class)
268
- end
269
-
270
- context 'given a controller that is not namespaced' do
271
- include_examples 'core tests'
272
-
273
- def controller_class_name
274
- 'ExamplesController'
275
- end
276
- end
277
-
278
- context 'given a controller that is namespaced' do
279
- def define_controller_under_test
280
- define_module('Admin')
281
- super
282
- end
283
-
284
- include_examples 'core tests'
285
-
286
- def controller_class_name
287
- 'Admin::ExamplesController'
288
- end
289
- end
290
-
291
- let(:controller_class) do
292
- define_controller_under_test
293
- end
294
-
295
- def define_controller_under_test
296
- define_controller(controller_class_name)
297
- end
298
-
299
- def controller_name
300
- controller_class_name.sub(/Controller$/, '').underscore
301
- end
302
-
303
- def define_route(method, path, args)
304
- action = args.fetch(:action)
305
- controller = args.fetch(:controller) { controller_name }
306
- define_routes do
307
- public_send(
308
- method,
309
- path,
310
- args.merge(controller: controller, action: action)
311
- )
312
- end
313
- end
314
-
315
- def build_expected_route_options(include_controller_in_expected_route_options, default_options)
316
- default_options.dup.tap do |options|
317
- if include_controller_in_expected_route_options
318
- options[:controller] = controller_name
319
- end
320
- end
321
- end
322
-
323
- def assert_accepts(matcher)
324
- expect(controller).to matcher
325
- end
326
-
327
- def assert_rejects(matcher)
328
- expect(controller).not_to matcher
329
- end
330
- end