shoulda-matchers 3.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,517 +0,0 @@
|
|
1
|
-
require 'unit_spec_helper'
|
2
|
-
|
3
|
-
describe Shoulda::Matchers::Independent::DelegateMethodMatcher do
|
4
|
-
describe '#description' do
|
5
|
-
context 'when the subject is an instance' do
|
6
|
-
subject { Object.new }
|
7
|
-
|
8
|
-
context 'without any qualifiers' do
|
9
|
-
it 'states that it should delegate method to the right object' do
|
10
|
-
matcher = delegate_method(:method_name).to(:delegate)
|
11
|
-
message = 'delegate #method_name to #delegate object'
|
12
|
-
|
13
|
-
expect(matcher.description).to eq message
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'qualified with #as' do
|
18
|
-
it 'states that it should delegate method to the right object and method' do
|
19
|
-
matcher = delegate_method(:method_name).to(:delegate).as(:alternate)
|
20
|
-
message = 'delegate #method_name to #delegate object as #alternate'
|
21
|
-
|
22
|
-
expect(matcher.description).to eq message
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'qualified with #with_arguments' do
|
27
|
-
it 'states that it should delegate method to the right object with right argument' do
|
28
|
-
matcher = delegate_method(:method_name).to(:delegate).
|
29
|
-
with_arguments(:foo, bar: [1, 2])
|
30
|
-
message = 'delegate #method_name to #delegate object passing arguments [:foo, {:bar=>[1, 2]}]'
|
31
|
-
|
32
|
-
expect(matcher.description).to eq message
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'qualified with #with_prefix' do
|
37
|
-
context 'without arguments' do
|
38
|
-
before do
|
39
|
-
define_model('Country') do
|
40
|
-
def hello; 'hello' end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when the subject's delegating method also has a prefix" do
|
45
|
-
it 'produces the correct description' do
|
46
|
-
define_class('Person') do
|
47
|
-
delegate :hello, to: :country, prefix: true
|
48
|
-
|
49
|
-
def country
|
50
|
-
Country.new
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
matcher = delegate_method(:hello).to(:country).with_prefix
|
55
|
-
expect(matcher.description).
|
56
|
-
to eq('delegate #country_hello to #country object as #hello')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'as true' do
|
62
|
-
before do
|
63
|
-
define_model('Country') do
|
64
|
-
def hello; 'hello' end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when the subject's delegating method also has a prefix" do
|
69
|
-
it 'produces the correct description' do
|
70
|
-
define_class('Person') do
|
71
|
-
delegate :hello, to: :country, prefix: true
|
72
|
-
|
73
|
-
def country
|
74
|
-
Country.new
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
matcher = delegate_method(:hello).to(:country).with_prefix(true)
|
79
|
-
expect(matcher.description).
|
80
|
-
to eq('delegate #country_hello to #country object as #hello')
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'as a symbol/string' do
|
86
|
-
it 'should delegate as (prefix_supplied)_(method_on_target)' do
|
87
|
-
define_model('Country') do
|
88
|
-
def hello; 'hello' end
|
89
|
-
end
|
90
|
-
|
91
|
-
define_class('Person') do
|
92
|
-
delegate :hello, to: :country, prefix: 'county'
|
93
|
-
|
94
|
-
def country
|
95
|
-
Country.new
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
matcher = delegate_method(:hello).to(:country).with_prefix('county')
|
100
|
-
expect(matcher.description).
|
101
|
-
to eq('delegate #county_hello to #country object as #hello')
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when the subject is a class' do
|
108
|
-
subject { Object }
|
109
|
-
|
110
|
-
context 'without any qualifiers' do
|
111
|
-
it 'states that it should delegate method to the right object' do
|
112
|
-
matcher = delegate_method(:method_name).to(:delegate)
|
113
|
-
|
114
|
-
expect(matcher.description).
|
115
|
-
to eq 'delegate .method_name to .delegate object'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'qualified with #as' do
|
120
|
-
it 'states that it should delegate method to the right object and method' do
|
121
|
-
matcher = delegate_method(:method_name).to(:delegate).as(:alternate)
|
122
|
-
message = 'delegate .method_name to .delegate object as .alternate'
|
123
|
-
|
124
|
-
expect(matcher.description).to eq message
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'qualified with #with_arguments' do
|
129
|
-
it 'states that it should delegate method to the right object with right argument' do
|
130
|
-
matcher = delegate_method(:method_name).to(:delegate).
|
131
|
-
with_arguments(:foo, bar: [1, 2])
|
132
|
-
message = 'delegate .method_name to .delegate object passing arguments [:foo, {:bar=>[1, 2]}]'
|
133
|
-
|
134
|
-
expect(matcher.description).to eq message
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'raises an error if the delegate object was never specified before matching' do
|
141
|
-
expect {
|
142
|
-
expect(Object.new).to delegate_method(:name)
|
143
|
-
}.to raise_error described_class::DelegateObjectNotSpecified
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'stubbing a delegating method on an instance' do
|
147
|
-
it 'only happens temporarily and is removed after the match' do
|
148
|
-
define_class('Company') do
|
149
|
-
def name
|
150
|
-
'Acme Company'
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
define_class('Person') do
|
155
|
-
def company_name
|
156
|
-
company.name
|
157
|
-
end
|
158
|
-
|
159
|
-
def company
|
160
|
-
Company.new
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
person = Person.new
|
165
|
-
matcher = delegate_method(:company_name).to(:company).as(:name)
|
166
|
-
matcher.matches?(person)
|
167
|
-
|
168
|
-
expect(person.company.name).to eq 'Acme Company'
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when the subject does not delegate anything' do
|
173
|
-
before do
|
174
|
-
define_class('PostOffice')
|
175
|
-
end
|
176
|
-
|
177
|
-
context 'when the subject is an instance' do
|
178
|
-
it 'rejects with the correct failure message' do
|
179
|
-
post_office = PostOffice.new
|
180
|
-
message = [
|
181
|
-
'Expected PostOffice to delegate #deliver_mail to #mailman object',
|
182
|
-
'Method calls sent to PostOffice#mailman: (none)'
|
183
|
-
].join("\n")
|
184
|
-
|
185
|
-
expect {
|
186
|
-
expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
|
187
|
-
}.to fail_with_message(message)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'when the subject is a class' do
|
192
|
-
it 'uses the proper syntax for class methods in errors' do
|
193
|
-
message = [
|
194
|
-
'Expected PostOffice to delegate .deliver_mail to .mailman object',
|
195
|
-
'Method calls sent to PostOffice.mailman: (none)'
|
196
|
-
].join("\n")
|
197
|
-
|
198
|
-
expect {
|
199
|
-
expect(PostOffice).to delegate_method(:deliver_mail).to(:mailman)
|
200
|
-
}.to fail_with_message(message)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
context 'when the subject delegates correctly' do
|
206
|
-
before do
|
207
|
-
define_class('Mailman')
|
208
|
-
|
209
|
-
define_class('PostOffice') do
|
210
|
-
def deliver_mail
|
211
|
-
mailman.deliver_mail
|
212
|
-
end
|
213
|
-
|
214
|
-
def mailman
|
215
|
-
Mailman.new
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'accepts' do
|
221
|
-
post_office = PostOffice.new
|
222
|
-
expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
|
223
|
-
end
|
224
|
-
|
225
|
-
context 'negating the matcher' do
|
226
|
-
it 'rejects with the correct failure message' do
|
227
|
-
post_office = PostOffice.new
|
228
|
-
message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object, but it did'
|
229
|
-
|
230
|
-
expect {
|
231
|
-
expect(post_office).not_to delegate_method(:deliver_mail).to(:mailman)
|
232
|
-
}.to fail_with_message(message)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
context 'when the delegating method is private' do
|
238
|
-
before do
|
239
|
-
define_class('Mailman')
|
240
|
-
|
241
|
-
define_class('PostOffice') do
|
242
|
-
def deliver_mail
|
243
|
-
mailman.deliver_mail
|
244
|
-
end
|
245
|
-
|
246
|
-
def mailman
|
247
|
-
Mailman.new
|
248
|
-
end
|
249
|
-
|
250
|
-
private :mailman
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'accepts' do
|
255
|
-
post_office = PostOffice.new
|
256
|
-
expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
context 'qualified with #with_arguments' do
|
261
|
-
before do
|
262
|
-
define_class('Mailman')
|
263
|
-
|
264
|
-
define_class('PostOffice') do
|
265
|
-
def deliver_mail(*args)
|
266
|
-
mailman.deliver_mail('221B Baker St.', hastily: true)
|
267
|
-
end
|
268
|
-
|
269
|
-
def mailman
|
270
|
-
Mailman.new
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context 'qualified with #with_arguments' do
|
276
|
-
context 'when the subject delegates with matching arguments' do
|
277
|
-
it 'accepts' do
|
278
|
-
post_office = PostOffice.new
|
279
|
-
expect(post_office).to delegate_method(:deliver_mail).
|
280
|
-
to(:mailman).with_arguments('221B Baker St.', hastily: true)
|
281
|
-
end
|
282
|
-
|
283
|
-
context 'negating the matcher' do
|
284
|
-
it 'rejects with the correct failure message' do
|
285
|
-
post_office = PostOffice.new
|
286
|
-
message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object passing arguments ["221B Baker St.", {:hastily=>true}], but it did'
|
287
|
-
|
288
|
-
expect {
|
289
|
-
expect(post_office).
|
290
|
-
not_to delegate_method(:deliver_mail).
|
291
|
-
to(:mailman).
|
292
|
-
with_arguments('221B Baker St.', hastily: true)
|
293
|
-
}.to fail_with_message(message)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context 'when not given the correct arguments' do
|
299
|
-
it 'rejects with the correct failure message' do
|
300
|
-
post_office = PostOffice.new
|
301
|
-
message = [
|
302
|
-
'Expected PostOffice to delegate #deliver_mail to #mailman object passing arguments ["123 Nowhere Ln."]',
|
303
|
-
'Method calls sent to PostOffice#mailman:',
|
304
|
-
'1) deliver_mail("221B Baker St.", {:hastily=>true})'
|
305
|
-
].join("\n")
|
306
|
-
|
307
|
-
expect {
|
308
|
-
expect(post_office).to delegate_method(:deliver_mail).
|
309
|
-
to(:mailman).with_arguments('123 Nowhere Ln.')
|
310
|
-
}.to fail_with_message(message)
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
context 'qualified with #as' do
|
317
|
-
before do
|
318
|
-
define_class(:mailman)
|
319
|
-
|
320
|
-
define_class(:post_office) do
|
321
|
-
def deliver_mail
|
322
|
-
mailman.deliver_mail_and_avoid_dogs
|
323
|
-
end
|
324
|
-
|
325
|
-
def mailman
|
326
|
-
Mailman.new
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
context "when the given method is the same as the subject's delegating method" do
|
332
|
-
it 'accepts' do
|
333
|
-
post_office = PostOffice.new
|
334
|
-
expect(post_office).to delegate_method(:deliver_mail).
|
335
|
-
to(:mailman).as(:deliver_mail_and_avoid_dogs)
|
336
|
-
end
|
337
|
-
|
338
|
-
context 'negating the assertion' do
|
339
|
-
it 'rejects with the correct failure message' do
|
340
|
-
post_office = PostOffice.new
|
341
|
-
message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object as #deliver_mail_and_avoid_dogs, but it did'
|
342
|
-
|
343
|
-
expect {
|
344
|
-
expect(post_office).
|
345
|
-
not_to delegate_method(:deliver_mail).
|
346
|
-
to(:mailman).
|
347
|
-
as(:deliver_mail_and_avoid_dogs)
|
348
|
-
}.to fail_with_message(message)
|
349
|
-
end
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
context "when the given method is not the same as the subject's delegating method" do
|
354
|
-
it 'rejects with the correct failure message' do
|
355
|
-
post_office = PostOffice.new
|
356
|
-
message = [
|
357
|
-
'Expected PostOffice to delegate #deliver_mail to #mailman object as #watch_tv',
|
358
|
-
'Method calls sent to PostOffice#mailman:',
|
359
|
-
'1) deliver_mail_and_avoid_dogs()'
|
360
|
-
].join("\n")
|
361
|
-
|
362
|
-
expect {
|
363
|
-
expect(post_office).to delegate_method(:deliver_mail).
|
364
|
-
to(:mailman).as(:watch_tv)
|
365
|
-
}.to fail_with_message(message)
|
366
|
-
end
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
context 'qualified with #with_prefix' do
|
371
|
-
context 'without arguments' do
|
372
|
-
before do
|
373
|
-
define_model('Country') do
|
374
|
-
def hello; 'hello' end
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
context "when the subject's delegating method also has a prefix" do
|
379
|
-
it 'accepts' do
|
380
|
-
define_class('Person') do
|
381
|
-
delegate :hello, to: :country, prefix: true
|
382
|
-
|
383
|
-
def country
|
384
|
-
Country.new
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
person = Person.new
|
389
|
-
expect(person).to delegate_method(:hello). to(:country).with_prefix
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
context "when the subject's delegating method does not have a prefix" do
|
394
|
-
it 'rejects with the correct failure message' do
|
395
|
-
define_class('Person') do
|
396
|
-
delegate :hello, to: :country
|
397
|
-
|
398
|
-
def country
|
399
|
-
Country.new
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
message = [
|
404
|
-
'Expected Person to delegate #country_hello to #country object as #hello',
|
405
|
-
'Method calls sent to Person#country: (none)'
|
406
|
-
].join("\n")
|
407
|
-
|
408
|
-
person = Person.new
|
409
|
-
|
410
|
-
expect {
|
411
|
-
expect(person).to delegate_method(:hello). to(:country).with_prefix
|
412
|
-
}.to fail_with_message(message)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
context 'as true' do
|
418
|
-
before do
|
419
|
-
define_model('Country') do
|
420
|
-
def hello; 'hello' end
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
context "when the subject's delegating method also has a prefix" do
|
425
|
-
it 'accepts' do
|
426
|
-
define_class('Person') do
|
427
|
-
delegate :hello, to: :country, prefix: true
|
428
|
-
|
429
|
-
def country
|
430
|
-
Country.new
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
person = Person.new
|
435
|
-
expect(person).
|
436
|
-
to delegate_method(:hello).
|
437
|
-
to(:country).with_prefix(true)
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
context "when the subject's delegating method does not have a prefix" do
|
442
|
-
it 'rejects with the correct failure message' do
|
443
|
-
define_class('Person') do
|
444
|
-
delegate :hello, to: :country
|
445
|
-
|
446
|
-
def country
|
447
|
-
Country.new
|
448
|
-
end
|
449
|
-
end
|
450
|
-
|
451
|
-
message = [
|
452
|
-
'Expected Person to delegate #country_hello to #country object as #hello',
|
453
|
-
'Method calls sent to Person#country: (none)'
|
454
|
-
].join("\n")
|
455
|
-
|
456
|
-
person = Person.new
|
457
|
-
|
458
|
-
expect {
|
459
|
-
expect(person).
|
460
|
-
to delegate_method(:hello).
|
461
|
-
to(:country).with_prefix(true)
|
462
|
-
}.to fail_with_message(message)
|
463
|
-
end
|
464
|
-
end
|
465
|
-
end
|
466
|
-
|
467
|
-
context 'as a symbol/string' do
|
468
|
-
before do
|
469
|
-
define_model('Country') do
|
470
|
-
def hello; 'hello' end
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
context "when the subject's delegating method has the same prefix" do
|
475
|
-
it 'accepts' do
|
476
|
-
define_class('Person') do
|
477
|
-
delegate :hello, to: :country, prefix: 'county'
|
478
|
-
|
479
|
-
def country
|
480
|
-
Country.new
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
person = Person.new
|
485
|
-
expect(person).
|
486
|
-
to delegate_method(:hello).
|
487
|
-
to(:country).with_prefix('county')
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
context "when the subject's delegating method has a different prefix" do
|
492
|
-
it 'rejects with the correct failure message' do
|
493
|
-
define_class('Person') do
|
494
|
-
delegate :hello, to: :country, prefix: 'something_else'
|
495
|
-
|
496
|
-
def country
|
497
|
-
Country.new
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
message = [
|
502
|
-
'Expected Person to delegate #county_hello to #country object as #hello',
|
503
|
-
'Method calls sent to Person#country: (none)'
|
504
|
-
].join("\n")
|
505
|
-
|
506
|
-
person = Person.new
|
507
|
-
|
508
|
-
expect {
|
509
|
-
expect(person).
|
510
|
-
to delegate_method(:hello).
|
511
|
-
to(:country).with_prefix('county')
|
512
|
-
}.to fail_with_message(message)
|
513
|
-
end
|
514
|
-
end
|
515
|
-
end
|
516
|
-
end
|
517
|
-
end
|