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
@@ -1,92 +0,0 @@
|
|
1
|
-
require_relative 'helpers/model_builder'
|
2
|
-
|
3
|
-
module UnitTests
|
4
|
-
class RecordWithDifferentErrorAttributeBuilder
|
5
|
-
include ModelBuilder
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
@options = options.reverse_merge(default_options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def attribute_that_receives_error
|
12
|
-
options[:attribute_that_receives_error]
|
13
|
-
end
|
14
|
-
|
15
|
-
def attribute_to_validate
|
16
|
-
options[:attribute_to_validate]
|
17
|
-
end
|
18
|
-
|
19
|
-
def message
|
20
|
-
options[:message]
|
21
|
-
end
|
22
|
-
|
23
|
-
def message=(message)
|
24
|
-
options[:message] = message
|
25
|
-
end
|
26
|
-
|
27
|
-
def model
|
28
|
-
@_model ||= create_model
|
29
|
-
end
|
30
|
-
|
31
|
-
def model_name
|
32
|
-
'Example'
|
33
|
-
end
|
34
|
-
|
35
|
-
def record
|
36
|
-
model.new
|
37
|
-
end
|
38
|
-
|
39
|
-
def valid_value
|
40
|
-
'some value'
|
41
|
-
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
|
45
|
-
attr_reader :options
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def context
|
50
|
-
{
|
51
|
-
validation_method_name: validation_method_name,
|
52
|
-
valid_value: valid_value,
|
53
|
-
attribute_to_validate: attribute_to_validate,
|
54
|
-
attribute_that_receives_error: attribute_that_receives_error,
|
55
|
-
message: message
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def create_model
|
60
|
-
_context = context
|
61
|
-
|
62
|
-
define_model model_name, model_columns do
|
63
|
-
validate _context[:validation_method_name]
|
64
|
-
|
65
|
-
define_method(_context[:validation_method_name]) do
|
66
|
-
if self[_context[:attribute_to_validate]] != _context[:valid_value]
|
67
|
-
self.errors.add(_context[:attribute_that_receives_error], _context[:message])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def validation_method_name
|
74
|
-
:custom_validation
|
75
|
-
end
|
76
|
-
|
77
|
-
def model_columns
|
78
|
-
{
|
79
|
-
attribute_to_validate => :string,
|
80
|
-
attribute_that_receives_error => :string
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def default_options
|
85
|
-
{
|
86
|
-
attribute_that_receives_error: :attribute_that_receives_error,
|
87
|
-
attribute_to_validate: :attribute_to_validate,
|
88
|
-
message: 'some message'
|
89
|
-
}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
shared_examples_for 'ignoring_interference_by_writer' do |common_config|
|
2
|
-
valid_tests = [
|
3
|
-
:accept_if_qualified_but_changing_value_does_not_interfere,
|
4
|
-
:reject_if_qualified_but_changing_value_interferes
|
5
|
-
]
|
6
|
-
tests = common_config.fetch(:tests)
|
7
|
-
tests.assert_valid_keys(valid_tests)
|
8
|
-
|
9
|
-
define_method(:common_config) { common_config }
|
10
|
-
|
11
|
-
context 'when the writer method for the attribute changes incoming values' do
|
12
|
-
context 'and the value change does not cause a test failure' do
|
13
|
-
config_for_test = tests[:accept_if_qualified_but_changing_value_does_not_interfere]
|
14
|
-
|
15
|
-
if config_for_test
|
16
|
-
it 'accepts (and does not raise an error)' do
|
17
|
-
args = build_args(config_for_test)
|
18
|
-
scenario = build_scenario_for_validation_matcher(args)
|
19
|
-
matcher = matcher_from(scenario)
|
20
|
-
|
21
|
-
expect(scenario.record).to matcher
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'and the value change causes a test failure' do
|
27
|
-
config_for_test = tests[:reject_if_qualified_but_changing_value_interferes]
|
28
|
-
|
29
|
-
if config_for_test
|
30
|
-
it 'lists how the value got changed in the failure message' do
|
31
|
-
args = build_args(config_for_test)
|
32
|
-
scenario = build_scenario_for_validation_matcher(args)
|
33
|
-
matcher = matcher_from(scenario)
|
34
|
-
|
35
|
-
assertion = lambda do
|
36
|
-
expect(scenario.record).to matcher
|
37
|
-
end
|
38
|
-
|
39
|
-
if config_for_test.key?(:expected_message_includes)
|
40
|
-
message = config_for_test[:expected_message_includes]
|
41
|
-
expect(&assertion).to fail_with_message_including(message)
|
42
|
-
else
|
43
|
-
message = config_for_test.fetch(:expected_message)
|
44
|
-
expect(&assertion).to fail_with_message(message)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def build_args(config_for_test)
|
52
|
-
args_from_common_config.merge(args_from_config_for_test(config_for_test))
|
53
|
-
end
|
54
|
-
|
55
|
-
def args_from_common_config
|
56
|
-
common_config.slice(
|
57
|
-
:column_type,
|
58
|
-
:model_creator,
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
def args_from_config_for_test(config)
|
63
|
-
config.slice(
|
64
|
-
:attribute_name,
|
65
|
-
:attribute_overrides,
|
66
|
-
:changing_values_with,
|
67
|
-
:default_value,
|
68
|
-
:model_name,
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
|
-
def matcher_from(scenario)
|
73
|
-
scenario.matcher.tap do |matcher|
|
74
|
-
if respond_to?(:configure_validation_matcher)
|
75
|
-
configure_validation_matcher(matcher)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
shared_examples 'a numerical submatcher' do
|
2
|
-
it 'implements the with_message method' do
|
3
|
-
expect(subject).to respond_to(:with_message).with(1).arguments
|
4
|
-
end
|
5
|
-
|
6
|
-
it 'implements the matches? method' do
|
7
|
-
expect(subject).to respond_to(:matches?).with(1).arguments
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'implements the failure_message method' do
|
11
|
-
expect(subject).to respond_to(:failure_message).with(0).arguments
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'implements the failure_message_when_negated method' do
|
15
|
-
expect(subject).to respond_to(:failure_message_when_negated).with(0).arguments
|
16
|
-
end
|
17
|
-
end
|
@@ -1,360 +0,0 @@
|
|
1
|
-
shared_examples_for 'set session or flash matcher' do
|
2
|
-
context 'without any qualifiers' do
|
3
|
-
it 'produces the right description' do
|
4
|
-
expected_description = "should set any key in #{store_name}"
|
5
|
-
matcher = set_store
|
6
|
-
|
7
|
-
expect(matcher.description).to eq expected_description
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'in the positive' do
|
11
|
-
context 'if the store is not empty' do
|
12
|
-
it 'accepts' do
|
13
|
-
controller = controller_with_store('any key' => 'any value')
|
14
|
-
expect(controller).to set_store
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'if the store is empty' do
|
19
|
-
it 'rejects' do
|
20
|
-
controller = controller_with_empty_store
|
21
|
-
expect(controller).not_to set_store
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'produces the correct failure message' do
|
25
|
-
controller = controller_with_empty_store
|
26
|
-
expected_message = %<Expected #{controller.class} to set any key in #{store_name}, but it did not>
|
27
|
-
|
28
|
-
expect { expect(controller).to set_store }.
|
29
|
-
to fail_with_message(expected_message)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'in the negative' do
|
35
|
-
context 'if the given key is present in the store' do
|
36
|
-
it 'produces the correct failure message' do
|
37
|
-
controller = controller_with_store('any key' => 'any value')
|
38
|
-
expected_message = %<Expected #{controller.class} not to set any key in #{store_name}, but it did>
|
39
|
-
assertion = proc do
|
40
|
-
expect(controller).not_to set_store
|
41
|
-
end
|
42
|
-
|
43
|
-
expect(&assertion).to fail_with_message(expected_message)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'with #[]' do
|
50
|
-
it 'produces the right description' do
|
51
|
-
matcher = set_store['the key']
|
52
|
-
expected_description = %<should set #{store_name}["the key"]>
|
53
|
-
|
54
|
-
expect(matcher.description).to eq expected_description
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'in the positive' do
|
58
|
-
context 'if the given key is present in the store' do
|
59
|
-
it 'accepts the param as a string' do
|
60
|
-
controller = controller_with_store('the_key' => 'any value')
|
61
|
-
expect(controller).to set_store['the_key']
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'accepts the param as a symbol' do
|
65
|
-
controller = controller_with_store('the_key' => 'any value')
|
66
|
-
expect(controller).to set_store[:the_key]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'if the given key is not present in the store' do
|
71
|
-
it 'rejects' do
|
72
|
-
controller = controller_with_empty_store
|
73
|
-
expect(controller).not_to set_store['the key']
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'produces the correct failure message' do
|
77
|
-
controller = controller_with_empty_store
|
78
|
-
expected_message = %<Expected #{controller.class} to set #{store_name}["the key"], but it did not>
|
79
|
-
assertion = proc do
|
80
|
-
expect(controller).to set_store['the key']
|
81
|
-
end
|
82
|
-
|
83
|
-
expect(&assertion).to fail_with_message(expected_message)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'in the negative' do
|
89
|
-
context 'if the given key is present in the store' do
|
90
|
-
it 'produces the correct failure message' do
|
91
|
-
controller = controller_with_store('the key' => 'any value')
|
92
|
-
expected_message = %<Expected #{controller.class} not to set #{store_name}["the key"], but it did>
|
93
|
-
assertion = proc do
|
94
|
-
expect(controller).not_to set_store['the key']
|
95
|
-
end
|
96
|
-
|
97
|
-
expect(&assertion).to fail_with_message(expected_message)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'with #to' do
|
104
|
-
context 'given a static value' do
|
105
|
-
it 'produces the right description' do
|
106
|
-
matcher = set_store.to('the value')
|
107
|
-
expected_description = %<should set any key in #{store_name} to "the value">
|
108
|
-
|
109
|
-
expect(matcher.description).to eq expected_description
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'in the positive' do
|
113
|
-
context 'if the given value is present in the store' do
|
114
|
-
it 'accepts' do
|
115
|
-
controller = controller_with_store('any key' => 'the value')
|
116
|
-
expect(controller).to set_store.to('the value')
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'accepts given a value of nil' do
|
120
|
-
controller = controller_with_store('any key' => nil)
|
121
|
-
expect(controller).to set_store.to(nil)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'accepts given a value of false' do
|
125
|
-
controller = controller_with_store('any key' => false)
|
126
|
-
expect(controller).to set_store.to(false)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'if the given value is not present in the store' do
|
131
|
-
it 'rejects' do
|
132
|
-
controller = controller_with_empty_store
|
133
|
-
expect(controller).not_to set_store.to('the value')
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'rejects checking for nil' do
|
137
|
-
controller = controller_with_empty_store
|
138
|
-
expect(controller).not_to set_store.to(nil)
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'produces the correct failure message' do
|
142
|
-
controller = controller_with_empty_store
|
143
|
-
expected_message = %<Expected #{controller.class} to set any key in #{store_name} to "the value", but it did not>
|
144
|
-
assertion = proc do
|
145
|
-
expect(controller).to set_store.to('the value')
|
146
|
-
end
|
147
|
-
|
148
|
-
expect(&assertion).to fail_with_message(expected_message)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'in the negative' do
|
154
|
-
context 'if the given value is present in the store' do
|
155
|
-
it 'produces the correct failure message' do
|
156
|
-
controller = controller_with_store('any key' => 'the value')
|
157
|
-
expected_message = %<Expected #{controller.class} not to set any key in #{store_name} to "the value", but it did>
|
158
|
-
assertion = proc do
|
159
|
-
expect(controller).not_to set_store.to('the value')
|
160
|
-
end
|
161
|
-
|
162
|
-
expect(&assertion).to fail_with_message(expected_message)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'given a regexp' do
|
169
|
-
it 'produces the right description' do
|
170
|
-
matcher = set_store.to(/value/)
|
171
|
-
expected_description = %<should set any key in #{store_name} to a value matching /value/>
|
172
|
-
|
173
|
-
expect(matcher.description).to eq expected_description
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'in the positive' do
|
177
|
-
context 'if the given value is present in the store' do
|
178
|
-
it 'accepts' do
|
179
|
-
controller = controller_with_store('any key' => 'the value')
|
180
|
-
expect(controller).to set_store.to(/value/)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'accepts given a value of nil' do
|
184
|
-
controller = controller_with_store('any key' => nil)
|
185
|
-
expect(controller).to set_store.to(nil)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'accepts given a value of false' do
|
189
|
-
controller = controller_with_store('any key' => false)
|
190
|
-
expect(controller).to set_store.to(false)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
context 'if the given value is not present in the store' do
|
195
|
-
it 'rejects' do
|
196
|
-
controller = controller_with_empty_store
|
197
|
-
expect(controller).not_to set_store.to(/value/)
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'produces the correct failure message' do
|
201
|
-
controller = controller_with_empty_store
|
202
|
-
expected_message = %<Expected #{controller.class} to set any key in #{store_name} to a value matching /value/, but it did not>
|
203
|
-
assertion = proc do
|
204
|
-
expect(controller).to set_store.to(/value/)
|
205
|
-
end
|
206
|
-
|
207
|
-
expect(&assertion).to fail_with_message(expected_message)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context 'in the negative' do
|
213
|
-
context 'if the given value is present in the store' do
|
214
|
-
it 'produces the correct failure message' do
|
215
|
-
controller = controller_with_store('any key' => 'the value')
|
216
|
-
expected_message = %<Expected #{controller.class} not to set any key in #{store_name} to a value matching /value/, but it did>
|
217
|
-
assertion = proc do
|
218
|
-
expect(controller).not_to set_store.to(/value/)
|
219
|
-
end
|
220
|
-
|
221
|
-
expect(&assertion).to fail_with_message(expected_message)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'with #[] + #to' do
|
229
|
-
context 'given a static value' do
|
230
|
-
it 'produces the right description' do
|
231
|
-
expected_description = %<should set #{store_name}["the key"] to "the value">
|
232
|
-
matcher = set_store['the key'].to('the value')
|
233
|
-
|
234
|
-
expect(matcher.description).to eq expected_description
|
235
|
-
end
|
236
|
-
|
237
|
-
context 'in the positive' do
|
238
|
-
context 'if the given value is present in the store' do
|
239
|
-
it 'accepts' do
|
240
|
-
controller = controller_with_store('the key' => 'the value')
|
241
|
-
expect(controller).to set_store['the key'].to('the value')
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context 'if the given value is not present in the store' do
|
246
|
-
it 'rejects' do
|
247
|
-
controller = controller_with_empty_store
|
248
|
-
expect(controller).not_to set_store['the key'].to('the value')
|
249
|
-
end
|
250
|
-
|
251
|
-
it 'produces the correct failure message' do
|
252
|
-
controller = controller_with_empty_store
|
253
|
-
expected_message = %<Expected #{controller.class} to set #{store_name}["the key"] to "the value", but it did not>
|
254
|
-
assertion = proc do
|
255
|
-
expect(controller).to set_store['the key'].to('the value')
|
256
|
-
end
|
257
|
-
|
258
|
-
expect(&assertion).to fail_with_message(expected_message)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context 'in the negative' do
|
264
|
-
context 'if the given value is present in the store' do
|
265
|
-
it 'produces the correct failure message' do
|
266
|
-
controller = controller_with_store('the key' => 'the value')
|
267
|
-
expected_message = %<Expected #{controller.class} not to set #{store_name}["the key"] to "the value", but it did>
|
268
|
-
assertion = proc do
|
269
|
-
expect(controller).not_to set_store['the key'].to('the value')
|
270
|
-
end
|
271
|
-
|
272
|
-
expect(&assertion).to fail_with_message(expected_message)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context 'given a dynamic value' do
|
279
|
-
it 'produces the right description' do
|
280
|
-
context = double('context', method_in_context: 'the value')
|
281
|
-
matcher = set_store['the key'].
|
282
|
-
in_context(context).
|
283
|
-
to { method_in_context }
|
284
|
-
expected_description = %<should set #{store_name}["the key"] to "the value">
|
285
|
-
|
286
|
-
expect(matcher.description).to eq expected_description
|
287
|
-
end
|
288
|
-
|
289
|
-
context 'in the positive' do
|
290
|
-
context 'if the value evaluated in the context is present in the store' do
|
291
|
-
it 'accepts' do
|
292
|
-
controller = controller_with_store('the key' => 'the value')
|
293
|
-
context = double('context', method_in_context: 'the value')
|
294
|
-
|
295
|
-
expect(controller).to set_store['the key'].
|
296
|
-
in_context(context).
|
297
|
-
to { method_in_context }
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
context 'if the value evaluated in the context is not present in the store' do
|
302
|
-
it 'rejects' do
|
303
|
-
controller = controller_with_empty_store
|
304
|
-
context = double('context', method_in_context: 'the value')
|
305
|
-
|
306
|
-
expect(controller).not_to set_store['the key'].
|
307
|
-
in_context(context).
|
308
|
-
to { method_in_context }
|
309
|
-
end
|
310
|
-
|
311
|
-
it 'produces the correct failure message' do
|
312
|
-
controller = controller_with_empty_store
|
313
|
-
context = double('context', method_in_context: 'the value')
|
314
|
-
expected_message = %<Expected #{controller.class} to set #{store_name}["the key"] to "the value", but it did not>
|
315
|
-
assertion = proc do
|
316
|
-
expect(controller).to set_store['the key'].
|
317
|
-
in_context(context).
|
318
|
-
to { method_in_context }
|
319
|
-
end
|
320
|
-
|
321
|
-
expect(&assertion).to fail_with_message(expected_message)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
context 'in the negative' do
|
327
|
-
context 'if the value evaluated in the context is present in the store' do
|
328
|
-
it 'produces the correct failure message' do
|
329
|
-
context = double('context', method_in_context: 'the value')
|
330
|
-
controller = controller_with_store('the key' => 'the value')
|
331
|
-
expected_message = %<Expected #{controller.class} not to set #{store_name}["the key"] to "the value", but it did>
|
332
|
-
assertion = proc do
|
333
|
-
expect(controller).not_to set_store['the key'].
|
334
|
-
in_context(context).
|
335
|
-
to { method_in_context }
|
336
|
-
end
|
337
|
-
|
338
|
-
expect(&assertion).to fail_with_message(expected_message)
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def controller_with_empty_store
|
346
|
-
build_fake_response
|
347
|
-
end
|
348
|
-
|
349
|
-
def controller_with_store(store_contents)
|
350
|
-
context = self
|
351
|
-
|
352
|
-
build_fake_response do
|
353
|
-
store = context.store_within(self)
|
354
|
-
|
355
|
-
store_contents.each do |key, value|
|
356
|
-
store[key] = value
|
357
|
-
end
|
358
|
-
end
|
359
|
-
end
|
360
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module UnitTests
|
4
|
-
class ValidationMatcherScenario
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
attr_reader :matcher
|
8
|
-
|
9
|
-
def initialize(arguments)
|
10
|
-
@arguments = arguments.dup
|
11
|
-
@matcher_proc = @arguments.delete(:matcher_proc)
|
12
|
-
|
13
|
-
@specified_model_creator = @arguments.delete(:model_creator) do
|
14
|
-
raise KeyError.new(<<-MESSAGE)
|
15
|
-
:model_creator is missing. You can either provide it as an option or as
|
16
|
-
a method.
|
17
|
-
MESSAGE
|
18
|
-
end
|
19
|
-
|
20
|
-
@model_creator = model_creator_class.new(@arguments)
|
21
|
-
end
|
22
|
-
|
23
|
-
def record
|
24
|
-
@_record ||= model.new.tap do |record|
|
25
|
-
attribute_default_values_by_name.each do |attribute_name, default_value|
|
26
|
-
record.public_send("#{attribute_name}=", default_value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def model
|
32
|
-
@_model ||= model_creator.call
|
33
|
-
end
|
34
|
-
|
35
|
-
def matcher
|
36
|
-
@_matcher ||= matcher_proc.call(attribute_name)
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
attr_reader(
|
42
|
-
:arguments,
|
43
|
-
:existing_value,
|
44
|
-
:matcher_proc,
|
45
|
-
:model_creator,
|
46
|
-
:specified_model_creator,
|
47
|
-
)
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def_delegators(
|
52
|
-
:model_creator,
|
53
|
-
:attribute_name,
|
54
|
-
:attribute_default_values_by_name,
|
55
|
-
)
|
56
|
-
|
57
|
-
def model_creator_class
|
58
|
-
UnitTests::ModelCreators.retrieve(specified_model_creator) ||
|
59
|
-
specified_model_creator
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::ActionController::CallbackMatcher, type: :controller do
|
4
|
-
shared_examples 'CallbackMatcher' do |kind, callback_type|
|
5
|
-
let(:kind) { kind }
|
6
|
-
let(:callback_type) { callback_type }
|
7
|
-
let(:method_name) { :authenticate_user! }
|
8
|
-
let(:matcher) { described_class.new(method_name, kind, callback_type) }
|
9
|
-
let(:controller) { define_controller('HookController').new }
|
10
|
-
|
11
|
-
def match
|
12
|
-
__send__("use_#{kind}_#{callback_type}", method_name)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "matches when a #{kind} hook is in place" do
|
16
|
-
add_callback(kind, callback_type, method_name)
|
17
|
-
|
18
|
-
expect(controller).to match
|
19
|
-
end
|
20
|
-
|
21
|
-
it "does not match when a #{kind} hook is missing" do
|
22
|
-
expect(controller).not_to match
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'description' do
|
26
|
-
it 'includes the filter kind and name' do
|
27
|
-
expect(matcher.description).to eq "have #{method_name.inspect} as a #{kind}_#{callback_type}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'failure message' do
|
32
|
-
it 'includes the filter kind and name that was expected' do
|
33
|
-
message = "Expected that HookController would have #{method_name.inspect} as a #{kind}_#{callback_type}"
|
34
|
-
|
35
|
-
expect {
|
36
|
-
expect(controller).to send("use_#{kind}_#{callback_type}", method_name)
|
37
|
-
}.to fail_with_message(message)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'failure message when negated' do
|
42
|
-
it 'includes the filter kind and name that was expected' do
|
43
|
-
add_callback(kind, callback_type, method_name)
|
44
|
-
message = "Expected that HookController would not have #{method_name.inspect} as a #{kind}_#{callback_type}"
|
45
|
-
|
46
|
-
expect { expect(controller).not_to match }.to fail_with_message(message)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def add_callback(kind, callback_type, callback)
|
53
|
-
controller.class.__send__("#{kind}_#{callback_type}", callback)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#use_before_filter' do
|
58
|
-
it_behaves_like 'CallbackMatcher', :before, :filter
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#use_after_filter' do
|
62
|
-
it_behaves_like 'CallbackMatcher', :after, :filter
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#use_around_filter' do
|
66
|
-
it_behaves_like 'CallbackMatcher', :around, :filter
|
67
|
-
end
|
68
|
-
|
69
|
-
if rails_4_x?
|
70
|
-
describe '#use_before_action' do
|
71
|
-
it_behaves_like 'CallbackMatcher', :before, :action
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#use_after_action' do
|
75
|
-
it_behaves_like 'CallbackMatcher', :after, :action
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#use_around_action' do
|
79
|
-
it_behaves_like 'CallbackMatcher', :around, :action
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|