shoulda-matchers 3.1.0 → 5.2.0
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.
- checksums.yaml +5 -5
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +407 -232
- data/docs/errors/NonCaseSwappableValueError.md +2 -2
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +7 -80
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +4 -3
- data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +36 -30
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +8 -10
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +7 -9
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +18 -15
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +3 -2
- data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -3
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +88 -29
- data/lib/shoulda/matchers/action_controller/route_params.rb +2 -2
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +4 -4
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
- data/lib/shoulda/matchers/action_controller.rb +2 -0
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -9
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +42 -39
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +52 -26
- data/lib/shoulda/matchers/active_model/helpers.rb +2 -2
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -30
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +2 -1
- data/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
- data/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
- data/lib/shoulda/matchers/active_model/qualifiers.rb +2 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +30 -6
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +8 -3
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +31 -16
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +52 -16
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +137 -84
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +159 -46
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +130 -66
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +251 -24
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +12 -9
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +38 -6
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
- data/lib/shoulda/matchers/active_model/validator.rb +4 -9
- data/lib/shoulda/matchers/active_model.rb +3 -5
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +10 -7
- data/lib/shoulda/matchers/active_record/association_matcher.rb +386 -111
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +14 -15
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +30 -8
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +34 -11
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +69 -0
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +74 -0
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +458 -42
- data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +185 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +63 -23
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +164 -48
- data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +106 -0
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +13 -11
- data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
- data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +18 -18
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
- data/lib/shoulda/matchers/active_record/uniqueness.rb +1 -1
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +430 -200
- data/lib/shoulda/matchers/active_record.rb +28 -20
- data/lib/shoulda/matchers/configuration.rb +12 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
- data/lib/shoulda/matchers/doublespeak/object_double.rb +6 -2
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
- data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
- data/lib/shoulda/matchers/doublespeak.rb +2 -1
- data/lib/shoulda/matchers/error.rb +1 -1
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +109 -29
- data/lib/shoulda/matchers/independent.rb +2 -2
- data/lib/shoulda/matchers/integrations/configuration.rb +8 -4
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/rails_shim.rb +172 -51
- data/lib/shoulda/matchers/routing.rb +2 -2
- data/lib/shoulda/matchers/util/word_wrap.rb +17 -12
- data/lib/shoulda/matchers/util.rb +39 -5
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +4 -3
- data/shoulda-matchers.gemspec +33 -15
- metadata +31 -338
- data/.gitignore +0 -12
- data/.hound.yml +0 -3
- data/.hound_config/ruby.yml +0 -12
- data/.travis.yml +0 -19
- data/.yardopts +0 -10
- data/Appraisals +0 -73
- data/CONTRIBUTING.md +0 -101
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -70
- data/NEWS.md +0 -986
- data/Rakefile +0 -39
- data/custom_plan.rb +0 -88
- data/doc_config/gh-pages/index.html.erb +0 -9
- data/doc_config/yard/setup.rb +0 -22
- data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
- data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
- data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -62
- data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
- data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
- data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -32
- data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
- data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -298
- data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
- data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
- data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
- data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -8
- data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
- data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
- data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
- data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
- data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
- data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
- data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
- data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
- data/gemfiles/4.0.0.gemfile +0 -38
- data/gemfiles/4.0.0.gemfile.lock +0 -223
- data/gemfiles/4.0.1.gemfile +0 -38
- data/gemfiles/4.0.1.gemfile.lock +0 -225
- data/gemfiles/4.1.gemfile +0 -38
- data/gemfiles/4.1.gemfile.lock +0 -220
- data/gemfiles/4.2.gemfile +0 -38
- data/gemfiles/4.2.gemfile.lock +0 -243
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
- data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +0 -37
- data/script/SUPPORTED_VERSIONS +0 -1
- data/script/install_gems_in_all_appraisals +0 -14
- data/script/run_all_tests +0 -14
- data/script/update_gem_in_all_appraisals +0 -15
- data/script/update_gems_in_all_appraisals +0 -14
- data/spec/acceptance/active_model_integration_spec.rb +0 -23
- data/spec/acceptance/independent_matchers_spec.rb +0 -125
- data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
- data/spec/acceptance/rails_integration_spec.rb +0 -156
- data/spec/acceptance_spec_helper.rb +0 -23
- data/spec/doublespeak_spec_helper.rb +0 -2
- data/spec/report_warnings.rb +0 -7
- data/spec/spec_helper.rb +0 -21
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
- data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/command_helpers.rb +0 -55
- data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
- data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
- data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
- data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
- data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
- data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
- data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
- data/spec/support/acceptance/helpers.rb +0 -31
- data/spec/support/acceptance/matchers/have_output.rb +0 -31
- data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
- data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
- data/spec/support/tests/bundle.rb +0 -94
- data/spec/support/tests/command_runner.rb +0 -230
- data/spec/support/tests/current_bundle.rb +0 -61
- data/spec/support/tests/database.rb +0 -28
- data/spec/support/tests/database_adapters/postgresql.rb +0 -25
- data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
- data/spec/support/tests/database_configuration.rb +0 -33
- data/spec/support/tests/database_configuration_registry.rb +0 -28
- data/spec/support/tests/filesystem.rb +0 -100
- data/spec/support/tests/version.rb +0 -45
- data/spec/support/unit/active_record/create_table.rb +0 -54
- data/spec/support/unit/attribute.rb +0 -47
- data/spec/support/unit/capture.rb +0 -40
- data/spec/support/unit/change_value.rb +0 -111
- data/spec/support/unit/create_model_arguments/basic.rb +0 -135
- data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
- data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
- data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
- data/spec/support/unit/helpers/active_model_versions.rb +0 -28
- data/spec/support/unit/helpers/active_record_versions.rb +0 -24
- data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
- data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
- data/spec/support/unit/helpers/class_builder.rb +0 -90
- data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
- data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
- data/spec/support/unit/helpers/controller_builder.rb +0 -63
- data/spec/support/unit/helpers/database_helpers.rb +0 -20
- data/spec/support/unit/helpers/i18n_faker.rb +0 -15
- data/spec/support/unit/helpers/mailer_builder.rb +0 -12
- data/spec/support/unit/helpers/model_builder.rb +0 -114
- data/spec/support/unit/helpers/rails_versions.rb +0 -28
- data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
- data/spec/support/unit/i18n.rb +0 -7
- data/spec/support/unit/load_environment.rb +0 -12
- data/spec/support/unit/matchers/deprecate.rb +0 -60
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -62
- data/spec/support/unit/matchers/print_warning_including.rb +0 -59
- data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
- data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
- data/spec/support/unit/model_creators/active_model.rb +0 -39
- data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
- data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
- data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
- data/spec/support/unit/model_creators/active_record.rb +0 -43
- data/spec/support/unit/model_creators/basic.rb +0 -97
- data/spec/support/unit/model_creators.rb +0 -19
- data/spec/support/unit/rails_application.rb +0 -126
- data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
- data/spec/support/unit/record_validating_confirmation_builder.rb +0 -51
- data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
- data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
- data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
- data/spec/support/unit/validation_matcher_scenario.rb +0 -62
- data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
- data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -592
- data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
- data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
- data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
- data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
- data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
- data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -823
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
- data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
- data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -266
- data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -91
- data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -149
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -207
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1015
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -288
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1837
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -380
- data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1242
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -168
- data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
- data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
- data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
- data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1418
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -80
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
- data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -517
- data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -242
- data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
- data/spec/unit_spec_helper.rb +0 -46
- data/spec/warnings_spy/filesystem.rb +0 -45
- data/spec/warnings_spy/partitioner.rb +0 -36
- data/spec/warnings_spy/reader.rb +0 -53
- data/spec/warnings_spy/reporter.rb +0 -88
- data/spec/warnings_spy.rb +0 -64
- data/tasks/documentation.rb +0 -199
- data/zeus.json +0 -11
@@ -46,7 +46,7 @@ error message explains, you have two options:
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# RSpec
|
49
|
-
describe User do
|
49
|
+
RSpec.describe User, type: :model do
|
50
50
|
context "validations" do
|
51
51
|
subject do
|
52
52
|
# Note that "123" == "123".swapcase. This is a problem!
|
@@ -87,7 +87,7 @@ error message explains, you have two options:
|
|
87
87
|
end
|
88
88
|
|
89
89
|
# RSpec
|
90
|
-
describe User do
|
90
|
+
RSpec.describe User, type: :model do
|
91
91
|
context "validations" do
|
92
92
|
subject do
|
93
93
|
# Note that "123" == "123".swapcase, but it's okay
|
@@ -1,56 +1,6 @@
|
|
1
1
|
module Shoulda
|
2
2
|
module Matchers
|
3
3
|
module ActionController
|
4
|
-
# The `use_before_filter` matcher is used to test that a before_filter
|
5
|
-
# callback is defined within your controller.
|
6
|
-
#
|
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
|
-
# # Minitest (Shoulda)
|
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]
|
24
|
-
#
|
25
|
-
def use_before_filter(callback)
|
26
|
-
CallbackMatcher.new(callback, :before, :filter)
|
27
|
-
end
|
28
|
-
|
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
|
41
|
-
#
|
42
|
-
# # Minitest (Shoulda)
|
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]
|
49
|
-
#
|
50
|
-
def use_after_filter(callback)
|
51
|
-
CallbackMatcher.new(callback, :after, :filter)
|
52
|
-
end
|
53
|
-
|
54
4
|
# The `use_before_action` matcher is used to test that a before_action
|
55
5
|
# callback is defined within your controller.
|
56
6
|
#
|
@@ -59,7 +9,7 @@ module Shoulda
|
|
59
9
|
# end
|
60
10
|
#
|
61
11
|
# # RSpec
|
62
|
-
# describe UsersController do
|
12
|
+
# RSpec.describe UsersController, type: :controller do
|
63
13
|
# it { should use_before_action(:authenticate_user!) }
|
64
14
|
# it { should_not use_before_action(:prevent_ssl) }
|
65
15
|
# end
|
@@ -84,7 +34,7 @@ module Shoulda
|
|
84
34
|
# end
|
85
35
|
#
|
86
36
|
# # RSpec
|
87
|
-
# describe IssuesController do
|
37
|
+
# RSpec.describe IssuesController, type: :controller do
|
88
38
|
# it { should use_after_action(:log_activity) }
|
89
39
|
# it { should_not use_after_action(:destroy_user) }
|
90
40
|
# end
|
@@ -101,31 +51,6 @@ module Shoulda
|
|
101
51
|
CallbackMatcher.new(callback, :after, :action)
|
102
52
|
end
|
103
53
|
|
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
|
116
|
-
#
|
117
|
-
# # Minitest (Shoulda)
|
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]
|
124
|
-
#
|
125
|
-
def use_around_filter(callback)
|
126
|
-
CallbackMatcher.new(callback, :around, :filter)
|
127
|
-
end
|
128
|
-
|
129
54
|
# The `use_around_action` matcher is used to test that an around_action
|
130
55
|
# callback is defined within your controller.
|
131
56
|
#
|
@@ -134,7 +59,7 @@ module Shoulda
|
|
134
59
|
# end
|
135
60
|
#
|
136
61
|
# # RSpec
|
137
|
-
# describe ChangesController do
|
62
|
+
# RSpec.describe ChangesController, type: :controller do
|
138
63
|
# it { should use_around_action(:wrap_in_transaction) }
|
139
64
|
# it { should_not use_around_action(:save_view_context) }
|
140
65
|
# end
|
@@ -167,11 +92,13 @@ module Shoulda
|
|
167
92
|
end
|
168
93
|
|
169
94
|
def failure_message
|
170
|
-
"Expected that #{controller_class.name} would have :#{method_name}
|
95
|
+
"Expected that #{controller_class.name} would have :#{method_name}"\
|
96
|
+
" as a #{kind}_#{callback_type}"
|
171
97
|
end
|
172
98
|
|
173
99
|
def failure_message_when_negated
|
174
|
-
"Expected that #{controller_class.name} would not have
|
100
|
+
"Expected that #{controller_class.name} would not have"\
|
101
|
+
" :#{method_name} as a #{kind}_#{callback_type}"
|
175
102
|
end
|
176
103
|
|
177
104
|
def description
|
@@ -10,7 +10,7 @@ module Shoulda
|
|
10
10
|
# end
|
11
11
|
#
|
12
12
|
# # RSpec
|
13
|
-
# describe ApplicationController do
|
13
|
+
# RSpec.describe ApplicationController, type: :controller do
|
14
14
|
# it { should filter_param(:secret_key) }
|
15
15
|
# end
|
16
16
|
#
|
@@ -31,12 +31,13 @@ module Shoulda
|
|
31
31
|
@key = key
|
32
32
|
end
|
33
33
|
|
34
|
-
def matches?(
|
34
|
+
def matches?(_controller)
|
35
35
|
filters_key?
|
36
36
|
end
|
37
37
|
|
38
38
|
def failure_message
|
39
|
-
"Expected #{@key} to be filtered; filtered keys:
|
39
|
+
"Expected #{@key} to be filtered; filtered keys:"\
|
40
|
+
" #{filtered_keys.join(', ')}"
|
40
41
|
end
|
41
42
|
|
42
43
|
def failure_message_when_negated
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
1
2
|
module Shoulda
|
2
3
|
module Matchers
|
3
4
|
module ActionController
|
@@ -34,10 +35,7 @@ module Shoulda
|
|
34
35
|
expected_value === actual_value
|
35
36
|
end
|
36
37
|
end
|
37
|
-
|
38
|
-
def empty?
|
39
|
-
flash.empty?
|
40
|
-
end
|
38
|
+
delegate :empty?, to: :flash
|
41
39
|
|
42
40
|
def use_now!
|
43
41
|
@use_now = true
|
@@ -35,7 +35,7 @@ module Shoulda
|
|
35
35
|
# end
|
36
36
|
#
|
37
37
|
# # RSpec
|
38
|
-
# describe UsersController do
|
38
|
+
# RSpec.describe UsersController, type: :controller do
|
39
39
|
# it do
|
40
40
|
# params = {
|
41
41
|
# user: {
|
@@ -96,7 +96,7 @@ module Shoulda
|
|
96
96
|
# end
|
97
97
|
#
|
98
98
|
# # RSpec
|
99
|
-
# describe UsersController do
|
99
|
+
# RSpec.describe UsersController, type: :controller do
|
100
100
|
# before do
|
101
101
|
# create(:user, id: 1)
|
102
102
|
# end
|
@@ -170,7 +170,7 @@ module Shoulda
|
|
170
170
|
# end
|
171
171
|
#
|
172
172
|
# # RSpec
|
173
|
-
# describe UsersController do
|
173
|
+
# RSpec.describe UsersController, type: :controller do
|
174
174
|
# before do
|
175
175
|
# create(:user, id: 1)
|
176
176
|
# end
|
@@ -209,7 +209,8 @@ module Shoulda
|
|
209
209
|
attr_writer :stubbed_params
|
210
210
|
|
211
211
|
def initialize(expected_permitted_parameter_names)
|
212
|
-
@expected_permitted_parameter_names =
|
212
|
+
@expected_permitted_parameter_names =
|
213
|
+
expected_permitted_parameter_names
|
213
214
|
@action = nil
|
214
215
|
@verb = nil
|
215
216
|
@request_params = {}
|
@@ -250,25 +251,29 @@ module Shoulda
|
|
250
251
|
parameters_double_registry.register
|
251
252
|
|
252
253
|
Doublespeak.with_doubles_activated do
|
253
|
-
|
254
|
+
params = { params: request_params }
|
255
|
+
|
256
|
+
context.__send__(verb, action, **params)
|
254
257
|
end
|
255
258
|
|
256
259
|
unpermitted_parameter_names.empty?
|
257
260
|
end
|
258
261
|
|
259
262
|
def failure_message
|
260
|
-
"Expected #{verb.upcase} ##{action} to #{expectation}
|
263
|
+
"Expected #{verb.upcase} ##{action} to #{expectation},"\
|
264
|
+
"\nbut #{reality}."
|
261
265
|
end
|
262
266
|
|
263
267
|
def failure_message_when_negated
|
264
|
-
"Expected #{verb.upcase} ##{action} not to #{expectation}
|
268
|
+
"Expected #{verb.upcase} ##{action} not to #{expectation},"\
|
269
|
+
"\nbut it did."
|
265
270
|
end
|
266
271
|
|
267
272
|
protected
|
268
273
|
|
269
|
-
attr_reader :controller, :double_collections_by_parameter_name, :action,
|
270
|
-
:
|
271
|
-
:parameters_double_registry
|
274
|
+
attr_reader :controller, :double_collections_by_parameter_name, :action,
|
275
|
+
:verb, :request_params, :expected_permitted_parameter_names,
|
276
|
+
:context, :subparameter_name, :parameters_double_registry
|
272
277
|
|
273
278
|
def expectation
|
274
279
|
message = 'restrict parameters '
|
@@ -277,7 +282,8 @@ module Shoulda
|
|
277
282
|
message << "on #{subparameter_name.inspect} "
|
278
283
|
end
|
279
284
|
|
280
|
-
message << 'to '
|
285
|
+
message << 'to '\
|
286
|
+
"#{format_parameter_names(expected_permitted_parameter_names)}"
|
281
287
|
|
282
288
|
message
|
283
289
|
end
|
@@ -286,9 +292,9 @@ module Shoulda
|
|
286
292
|
if actual_permitted_parameter_names.empty?
|
287
293
|
'it did not restrict any parameters'
|
288
294
|
else
|
289
|
-
'the restricted parameters were '
|
290
|
-
|
291
|
-
|
295
|
+
'the restricted parameters were '\
|
296
|
+
"#{format_parameter_names(actual_permitted_parameter_names)}"\
|
297
|
+
' instead'
|
292
298
|
end
|
293
299
|
end
|
294
300
|
|
@@ -298,12 +304,12 @@ module Shoulda
|
|
298
304
|
|
299
305
|
def actual_permitted_parameter_names
|
300
306
|
@_actual_permitted_parameter_names ||= begin
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
+
options =
|
308
|
+
if subparameter_name
|
309
|
+
{ for: subparameter_name }
|
310
|
+
else
|
311
|
+
{}
|
312
|
+
end
|
307
313
|
parameters_double_registry.permitted_parameter_names(options)
|
308
314
|
end
|
309
315
|
end
|
@@ -324,8 +330,8 @@ module Shoulda
|
|
324
330
|
|
325
331
|
def default_verb
|
326
332
|
case action
|
327
|
-
|
328
|
-
|
333
|
+
when :create then :post
|
334
|
+
when :update then RailsShim.verb_for_update
|
329
335
|
end
|
330
336
|
end
|
331
337
|
|
@@ -336,31 +342,30 @@ module Shoulda
|
|
336
342
|
# @private
|
337
343
|
class CompositeParametersDoubleRegistry
|
338
344
|
def initialize
|
339
|
-
@
|
345
|
+
@parameters_double_registries = []
|
340
346
|
end
|
341
347
|
|
342
348
|
def register
|
343
349
|
double_collection = Doublespeak.double_collection_for(
|
344
|
-
::ActionController::Parameters.singleton_class
|
350
|
+
::ActionController::Parameters.singleton_class,
|
345
351
|
)
|
346
352
|
double_collection.register_proxy(:new).to_return do |call|
|
347
353
|
params = call.return_value
|
348
354
|
parameters_double_registry = ParametersDoubleRegistry.new(params)
|
349
355
|
parameters_double_registry.register
|
350
|
-
|
351
|
-
parameters_double_registry
|
356
|
+
parameters_double_registries << parameters_double_registry
|
352
357
|
end
|
353
358
|
end
|
354
359
|
|
355
360
|
def permitted_parameter_names(options = {})
|
356
|
-
|
361
|
+
parameters_double_registries.flat_map do |double_registry|
|
357
362
|
double_registry.permitted_parameter_names(options)
|
358
363
|
end
|
359
364
|
end
|
360
365
|
|
361
366
|
protected
|
362
367
|
|
363
|
-
attr_reader :
|
368
|
+
attr_reader :parameters_double_registries
|
364
369
|
end
|
365
370
|
|
366
371
|
# @private
|
@@ -385,7 +390,7 @@ module Shoulda
|
|
385
390
|
|
386
391
|
if double_collections_by_parameter_name.key?(subparameter_name)
|
387
392
|
self.class.permitted_parameter_names_within(
|
388
|
-
double_collections_by_parameter_name[subparameter_name]
|
393
|
+
double_collections_by_parameter_name[subparameter_name],
|
389
394
|
)
|
390
395
|
else
|
391
396
|
[]
|
@@ -432,7 +437,8 @@ module Shoulda
|
|
432
437
|
# @private
|
433
438
|
class VerbNotDefinedError < StandardError
|
434
439
|
def message
|
435
|
-
'You must specify an HTTP verb when using a non-RESTful action.
|
440
|
+
'You must specify an HTTP verb when using a non-RESTful action.'\
|
441
|
+
' For example: for(:authorize, verb: :post)'
|
436
442
|
end
|
437
443
|
end
|
438
444
|
end
|
@@ -14,7 +14,7 @@ module Shoulda
|
|
14
14
|
# end
|
15
15
|
#
|
16
16
|
# # RSpec
|
17
|
-
# describe PostsController do
|
17
|
+
# RSpec.describe PostsController, type: :controller do
|
18
18
|
# describe 'GET #show' do
|
19
19
|
# before { get :show }
|
20
20
|
#
|
@@ -28,7 +28,7 @@ module Shoulda
|
|
28
28
|
# context 'GET #show' do
|
29
29
|
# setup { get :show }
|
30
30
|
#
|
31
|
-
# should redirect_to { posts_path }
|
31
|
+
# should redirect_to('/posts') { posts_path }
|
32
32
|
# should redirect_to(action: :index)
|
33
33
|
# end
|
34
34
|
# end
|
@@ -75,14 +75,12 @@ module Shoulda
|
|
75
75
|
private
|
76
76
|
|
77
77
|
def redirects_to_url?
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
false
|
85
|
-
end
|
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.assertion_exception_class => e
|
82
|
+
@failure_message = e.message
|
83
|
+
false
|
86
84
|
end
|
87
85
|
|
88
86
|
def url
|
@@ -15,7 +15,7 @@ module Shoulda
|
|
15
15
|
# <%= render 'sidebar' %>
|
16
16
|
#
|
17
17
|
# # RSpec
|
18
|
-
# describe PostsController do
|
18
|
+
# RSpec.describe PostsController, type: :controller do
|
19
19
|
# describe 'GET #show' do
|
20
20
|
# before { get :show }
|
21
21
|
#
|
@@ -71,14 +71,12 @@ module Shoulda
|
|
71
71
|
private
|
72
72
|
|
73
73
|
def renders_template?
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
false
|
81
|
-
end
|
74
|
+
@context.__send__(:assert_template, @options, @message)
|
75
|
+
@failure_message_when_negated = "Didn't expect to render #{@template}"
|
76
|
+
true
|
77
|
+
rescue Shoulda::Matchers.assertion_exception_class => e
|
78
|
+
@failure_message = e.message
|
79
|
+
false
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
@@ -11,7 +11,7 @@ module Shoulda
|
|
11
11
|
# end
|
12
12
|
#
|
13
13
|
# # RSpec
|
14
|
-
# describe PostsController do
|
14
|
+
# RSpec.describe PostsController, type: :controller do
|
15
15
|
# describe 'GET #show' do
|
16
16
|
# before { get :show }
|
17
17
|
#
|
@@ -38,7 +38,7 @@ module Shoulda
|
|
38
38
|
# end
|
39
39
|
#
|
40
40
|
# # RSpec
|
41
|
-
# describe PostsController do
|
41
|
+
# RSpec.describe PostsController, type: :controller do
|
42
42
|
# describe 'GET #sidebar' do
|
43
43
|
# before { get :sidebar }
|
44
44
|
#
|
@@ -64,12 +64,12 @@ module Shoulda
|
|
64
64
|
# @private
|
65
65
|
class RenderWithLayoutMatcher
|
66
66
|
def initialize(expected_layout)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
@expected_layout =
|
68
|
+
if expected_layout
|
69
|
+
expected_layout.to_s
|
70
|
+
else
|
71
|
+
nil
|
72
|
+
end
|
73
73
|
@controller = nil
|
74
74
|
end
|
75
75
|
|
@@ -95,11 +95,12 @@ module Shoulda
|
|
95
95
|
|
96
96
|
def description
|
97
97
|
description = 'render with '
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
description <<
|
99
|
+
if @expected_layout.nil?
|
100
|
+
'a layout'
|
101
|
+
else
|
102
|
+
"the #{@expected_layout.inspect} layout"
|
103
|
+
end
|
103
104
|
description
|
104
105
|
end
|
105
106
|
|
@@ -118,7 +119,9 @@ module Shoulda
|
|
118
119
|
end
|
119
120
|
|
120
121
|
def rendered_layouts
|
121
|
-
recorded_layouts.keys.compact.map { |layout|
|
122
|
+
recorded_layouts.keys.compact.map { |layout|
|
123
|
+
layout.sub(%r{^layouts/}, '')
|
124
|
+
}
|
122
125
|
end
|
123
126
|
|
124
127
|
def recorded_layouts
|
@@ -135,7 +138,7 @@ module Shoulda
|
|
135
138
|
|
136
139
|
def result
|
137
140
|
if rendered_with_layout?
|
138
|
-
|
141
|
+
"rendered with #{rendered_layouts.map(&:inspect).join(', ')}"
|
139
142
|
else
|
140
143
|
'rendered without a layout'
|
141
144
|
end
|
@@ -16,7 +16,7 @@ module Shoulda
|
|
16
16
|
# end
|
17
17
|
#
|
18
18
|
# # RSpec
|
19
|
-
# describe ApplicationController do
|
19
|
+
# RSpec.describe ApplicationController, type: :controller do
|
20
20
|
# it do
|
21
21
|
# should rescue_from(ActiveRecord::RecordNotFound).
|
22
22
|
# with(:handle_not_found)
|
@@ -79,7 +79,8 @@ module Shoulda
|
|
79
79
|
end
|
80
80
|
|
81
81
|
unless handler_exists?
|
82
|
-
expectation << " but #{controller} does not respond to
|
82
|
+
expectation << " but #{controller} does not respond to"\
|
83
|
+
" #{expected_method}"
|
83
84
|
end
|
84
85
|
expectation
|
85
86
|
end
|
@@ -13,7 +13,7 @@ module Shoulda
|
|
13
13
|
# end
|
14
14
|
#
|
15
15
|
# # RSpec
|
16
|
-
# describe PostsController do
|
16
|
+
# RSpec.describe PostsController, type: :controller do
|
17
17
|
# describe 'GET #index' do
|
18
18
|
# before { get :index }
|
19
19
|
#
|
@@ -39,7 +39,7 @@ module Shoulda
|
|
39
39
|
# end
|
40
40
|
#
|
41
41
|
# # RSpec
|
42
|
-
# describe PostsController do
|
42
|
+
# RSpec.describe PostsController, type: :controller do
|
43
43
|
# describe 'DELETE #destroy' do
|
44
44
|
# before { delete :destroy }
|
45
45
|
#
|
@@ -65,7 +65,7 @@ module Shoulda
|
|
65
65
|
# end
|
66
66
|
#
|
67
67
|
# # RSpec
|
68
|
-
# describe PostsController do
|
68
|
+
# RSpec.describe PostsController, type: :controller do
|
69
69
|
# describe 'GET #show' do
|
70
70
|
# before { get :show }
|
71
71
|
#
|