shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
@@ -1,69 +0,0 @@
1
- require 'delegate'
2
-
3
- module UnitTests
4
- class RecordBuilderWithI18nValidationMessage < SimpleDelegator
5
- def initialize(builder, options = {})
6
- super(builder)
7
- @options = default_options.merge(options)
8
- builder.message = validation_message_key
9
- end
10
-
11
- def validation_message_key
12
- options[:validation_message_key]
13
- end
14
-
15
- protected
16
-
17
- attr_reader :builder, :options
18
-
19
- private
20
-
21
- def model
22
- @_model ||= super.tap do |model|
23
- stub_validation_messages
24
- end
25
- end
26
-
27
- def stub_validation_messages
28
- stub_default_validation_message
29
- stub_attribute_specific_validation_message
30
- end
31
-
32
- def stub_default_validation_message
33
- keys = [
34
- 'activerecord.errors.messages',
35
- validation_message_key
36
- ]
37
-
38
- I18nFaker.stub_translation(keys, default_message)
39
- end
40
-
41
- def stub_attribute_specific_validation_message
42
- keys = [
43
- 'activerecord.errors',
44
- "models.#{builder.model_name.to_s.underscore}",
45
- "attributes.#{builder.attribute_that_receives_error}",
46
- validation_message_key
47
- ]
48
-
49
- I18nFaker.stub_translation(
50
- keys,
51
- message_for_attribute_that_receives_error
52
- )
53
- end
54
-
55
- def default_message
56
- 'the wrong message'
57
- end
58
-
59
- def message_for_attribute_that_receives_error
60
- 'the right message'
61
- end
62
-
63
- def default_options
64
- {
65
- validation_message_key: :validation_message_key
66
- }
67
- end
68
- end
69
- end
@@ -1,54 +0,0 @@
1
- require_relative 'helpers/model_builder'
2
-
3
- module UnitTests
4
- class RecordValidatingConfirmationBuilder
5
- include ModelBuilder
6
-
7
- def initialize(options)
8
- @options = options
9
- end
10
-
11
- def model
12
- @_model ||= create_model
13
- end
14
-
15
- def model_name
16
- options.fetch(:model_name, 'Example')
17
- end
18
-
19
- def record
20
- model.new
21
- end
22
-
23
- def message=(message)
24
- options[:message] = message
25
- end
26
-
27
- def attribute_to_confirm
28
- options.fetch(:attribute, :attribute_to_confirm)
29
- end
30
-
31
- def confirmation_attribute
32
- options.fetch(
33
- :confirmation_attribute,
34
- :"#{attribute_to_confirm}_confirmation"
35
- )
36
- end
37
-
38
- def attribute_that_receives_error
39
- confirmation_attribute
40
- end
41
-
42
- protected
43
-
44
- attr_reader :options
45
-
46
- private
47
-
48
- def create_model
49
- define_model(model_name, attribute_to_confirm => :string) do |model|
50
- model.validates_confirmation_of(attribute_to_confirm, options)
51
- end
52
- end
53
- end
54
- end
@@ -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