shoulda-matchers 2.8.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.hound_config/ruby.yml +7 -0
  3. data/.travis.yml +11 -54
  4. data/Appraisals +45 -100
  5. data/CONTRIBUTING.md +51 -7
  6. data/Gemfile +7 -19
  7. data/Gemfile.lock +60 -134
  8. data/Guardfile +5 -0
  9. data/NEWS.md +203 -0
  10. data/README.md +95 -50
  11. data/Rakefile +1 -0
  12. data/doc_config/yard/templates/default/layout/html/setup.rb +1 -1
  13. data/gemfiles/4.0.0.gemfile +10 -7
  14. data/gemfiles/4.0.0.gemfile.lock +103 -79
  15. data/gemfiles/4.0.1.gemfile +10 -7
  16. data/gemfiles/4.0.1.gemfile.lock +109 -83
  17. data/gemfiles/4.1.gemfile +10 -7
  18. data/gemfiles/4.1.gemfile.lock +109 -85
  19. data/gemfiles/4.2.gemfile +10 -9
  20. data/gemfiles/4.2.gemfile.lock +86 -78
  21. data/lib/shoulda/matchers.rb +13 -18
  22. data/lib/shoulda/matchers/action_controller.rb +4 -1
  23. data/lib/shoulda/matchers/action_controller/flash_store.rb +95 -0
  24. data/lib/shoulda/matchers/action_controller/{strong_parameters_matcher.rb → permit_matcher.rb} +147 -30
  25. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  26. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
  27. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +1 -1
  28. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  29. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -1
  30. data/lib/shoulda/matchers/action_controller/route_params.rb +15 -6
  31. data/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
  32. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +30 -136
  33. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +28 -109
  34. data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +103 -0
  35. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +1 -12
  36. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +79 -10
  37. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +10 -0
  38. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +21 -0
  39. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +24 -0
  40. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -5
  41. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +29 -10
  42. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +27 -10
  43. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +27 -12
  44. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +56 -20
  45. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +3 -11
  46. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +65 -0
  47. data/lib/shoulda/matchers/active_record/association_matcher.rb +40 -6
  48. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +21 -7
  49. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +11 -40
  50. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
  51. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -6
  52. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +137 -22
  53. data/lib/shoulda/matchers/configuration.rb +20 -0
  54. data/lib/shoulda/matchers/doublespeak.rb +11 -1
  55. data/lib/shoulda/matchers/doublespeak/double.rb +29 -11
  56. data/lib/shoulda/matchers/doublespeak/double_collection.rb +4 -3
  57. data/lib/shoulda/matchers/doublespeak/method_call.rb +35 -0
  58. data/lib/shoulda/matchers/doublespeak/object_double.rb +7 -2
  59. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +4 -3
  60. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +3 -3
  61. data/lib/shoulda/matchers/doublespeak/world.rb +21 -1
  62. data/lib/shoulda/matchers/integrations.rb +43 -0
  63. data/lib/shoulda/matchers/integrations/configuration.rb +68 -0
  64. data/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
  65. data/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
  66. data/lib/shoulda/matchers/integrations/libraries.rb +15 -0
  67. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +31 -0
  68. data/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
  69. data/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
  70. data/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
  71. data/lib/shoulda/matchers/integrations/libraries/rails.rb +30 -0
  72. data/lib/shoulda/matchers/integrations/rails.rb +12 -0
  73. data/lib/shoulda/matchers/integrations/registry.rb +28 -0
  74. data/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
  75. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
  76. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
  77. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
  78. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
  79. data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
  80. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
  81. data/lib/shoulda/matchers/rails_shim.rb +0 -40
  82. data/lib/shoulda/matchers/version.rb +1 -1
  83. data/script/SUPPORTED_VERSIONS +1 -1
  84. data/script/update_gems_in_all_appraisals +14 -0
  85. data/shoulda-matchers.gemspec +2 -2
  86. data/spec/acceptance/active_model_integration_spec.rb +4 -1
  87. data/spec/acceptance/independent_matchers_spec.rb +6 -6
  88. data/spec/acceptance/multiple_libraries_integration_spec.rb +52 -0
  89. data/spec/acceptance/rails_integration_spec.rb +15 -5
  90. data/spec/acceptance_spec_helper.rb +8 -0
  91. data/spec/doublespeak_spec_helper.rb +14 -0
  92. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +110 -0
  93. data/spec/support/acceptance/helpers.rb +2 -0
  94. data/spec/support/acceptance/helpers/base_helpers.rb +6 -1
  95. data/spec/support/acceptance/helpers/command_helpers.rb +6 -2
  96. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -8
  97. data/spec/support/acceptance/helpers/n_unit_helpers.rb +25 -0
  98. data/spec/support/acceptance/helpers/rspec_helpers.rb +2 -0
  99. data/spec/support/acceptance/helpers/step_helpers.rb +13 -19
  100. data/spec/support/acceptance/matchers/have_output.rb +1 -1
  101. data/spec/support/tests/bundle.rb +1 -1
  102. data/spec/support/tests/command_runner.rb +25 -13
  103. data/spec/support/tests/current_bundle.rb +47 -0
  104. data/spec/support/tests/database.rb +28 -0
  105. data/spec/support/tests/database_adapters/postgresql.rb +25 -0
  106. data/spec/support/tests/database_adapters/sqlite3.rb +26 -0
  107. data/spec/support/tests/database_configuration.rb +33 -0
  108. data/spec/support/tests/database_configuration_registry.rb +28 -0
  109. data/spec/support/tests/filesystem.rb +25 -2
  110. data/spec/support/unit/helpers/active_record_versions.rb +12 -0
  111. data/spec/support/unit/helpers/class_builder.rb +6 -2
  112. data/spec/support/unit/helpers/column_type_helpers.rb +26 -0
  113. data/spec/support/unit/helpers/controller_builder.rb +0 -28
  114. data/spec/support/unit/helpers/database_helpers.rb +18 -0
  115. data/spec/support/unit/helpers/model_builder.rb +38 -6
  116. data/spec/support/unit/helpers/rails_versions.rb +2 -2
  117. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +9 -8
  118. data/spec/support/unit/matchers/fail_with_message_matcher.rb +1 -1
  119. data/spec/support/unit/rails_application.rb +29 -13
  120. data/spec/support/unit/record_validating_confirmation_builder.rb +1 -2
  121. data/spec/support/unit/shared_examples/set_session_or_flash.rb +355 -0
  122. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +433 -0
  123. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +1 -5
  124. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +37 -0
  125. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +23 -147
  126. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +8 -285
  127. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +562 -0
  128. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +81 -14
  129. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +16 -8
  130. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +101 -9
  131. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +39 -1
  132. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +39 -1
  133. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +39 -0
  134. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -17
  135. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -17
  136. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -17
  137. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +838 -271
  138. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -19
  139. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +93 -0
  140. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +3 -3
  141. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +25 -0
  142. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +905 -0
  143. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +17 -11
  144. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
  145. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +144 -43
  146. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +1 -1
  147. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +36 -11
  148. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +29 -16
  149. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +8 -5
  150. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +1 -1
  151. data/spec/unit_spec_helper.rb +15 -14
  152. data/spec/warnings_spy.rb +1 -1
  153. metadata +68 -29
  154. data/docs.watchr +0 -5
  155. data/gemfiles/3.0.gemfile +0 -26
  156. data/gemfiles/3.0.gemfile.lock +0 -173
  157. data/gemfiles/3.1.gemfile +0 -32
  158. data/gemfiles/3.1.gemfile.lock +0 -212
  159. data/gemfiles/3.1_1.9.2.gemfile +0 -32
  160. data/gemfiles/3.1_1.9.2.gemfile.lock +0 -212
  161. data/gemfiles/3.2.gemfile +0 -33
  162. data/gemfiles/3.2.gemfile.lock +0 -212
  163. data/gemfiles/3.2_1.9.2.gemfile +0 -31
  164. data/gemfiles/3.2_1.9.2.gemfile.lock +0 -207
  165. data/lib/shoulda/matchers/assertion_error.rb +0 -27
  166. data/lib/shoulda/matchers/doublespeak/structs.rb +0 -10
  167. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +0 -39
  168. data/lib/shoulda/matchers/integrations/rspec.rb +0 -19
  169. data/lib/shoulda/matchers/integrations/test_unit.rb +0 -34
  170. data/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -331
  171. data/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -564
@@ -3,7 +3,8 @@ module Shoulda
3
3
  module Doublespeak
4
4
  # @private
5
5
  class DoubleCollection
6
- def initialize(klass)
6
+ def initialize(world, klass)
7
+ @world = world
7
8
  @klass = klass
8
9
  @doubles_by_method_name = {}
9
10
  end
@@ -40,12 +41,12 @@ module Shoulda
40
41
 
41
42
  protected
42
43
 
43
- attr_reader :klass, :doubles_by_method_name
44
+ attr_reader :world, :klass, :doubles_by_method_name
44
45
 
45
46
  def register_double(method_name, implementation_type)
46
47
  implementation =
47
48
  DoubleImplementationRegistry.find(implementation_type)
48
- double = Double.new(klass, method_name, implementation)
49
+ double = Double.new(world, klass, method_name, implementation)
49
50
  doubles_by_method_name[method_name] = double
50
51
  double
51
52
  end
@@ -0,0 +1,35 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class MethodCall
6
+ attr_accessor :return_value
7
+ attr_reader :method_name, :args, :block, :object, :double
8
+
9
+ def initialize(args)
10
+ @method_name = args.fetch(:method_name)
11
+ @args = args.fetch(:args)
12
+ @block = args[:block]
13
+ @double = args[:double]
14
+ @object = args[:object]
15
+ @return_value = nil
16
+ end
17
+
18
+ def with_return_value(return_value)
19
+ dup.tap do |call|
20
+ call.return_value = return_value
21
+ end
22
+ end
23
+
24
+ def ==(other)
25
+ other.is_a?(self.class) &&
26
+ method_name == other.method_name &&
27
+ args == other.args &&
28
+ block == other.block &&
29
+ double == other.double &&
30
+ object == other.object
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -19,8 +19,13 @@ module Shoulda
19
19
  end
20
20
 
21
21
  def method_missing(method_name, *args, &block)
22
- calls << MethodCallWithName.new(method_name, args, block)
23
- (calls_by_method_name[method_name] ||= []) << MethodCall.new(args, block)
22
+ call = MethodCall.new(
23
+ method_name: method_name,
24
+ args: args,
25
+ block: block
26
+ )
27
+ calls << call
28
+ (calls_by_method_name[method_name] ||= []) << call
24
29
  nil
25
30
  end
26
31
 
@@ -17,9 +17,10 @@ module Shoulda
17
17
  @stub_implementation = stub_implementation
18
18
  end
19
19
 
20
- def call(double, object, args, block)
21
- stub_implementation.call(double, object, args, block)
22
- double.call_original_method(object, args, block)
20
+ def call(call)
21
+ return_value = call.double.call_original_method(call)
22
+ stub_implementation.call(call.with_return_value(return_value))
23
+ return_value
23
24
  end
24
25
 
25
26
  protected
@@ -21,9 +21,9 @@ module Shoulda
21
21
  end
22
22
  end
23
23
 
24
- def call(double, object, args, block)
25
- double.record_call(args, block)
26
- implementation.call(object, args, block)
24
+ def call(call)
25
+ call.double.record_call(call)
26
+ implementation.call(call)
27
27
  end
28
28
 
29
29
  protected
@@ -4,7 +4,19 @@ module Shoulda
4
4
  # @private
5
5
  class World
6
6
  def double_collection_for(klass)
7
- double_collections_by_class[klass] ||= DoubleCollection.new(klass)
7
+ double_collections_by_class[klass] ||=
8
+ DoubleCollection.new(self, klass)
9
+ end
10
+
11
+ def store_original_method_for(klass, method_name)
12
+ original_methods_for_class(klass)[method_name] ||=
13
+ klass.instance_method(method_name)
14
+ end
15
+
16
+ def original_method_for(klass, method_name)
17
+ if original_methods_by_class.key?(klass)
18
+ original_methods_by_class[klass][method_name]
19
+ end
8
20
  end
9
21
 
10
22
  def with_doubles_activated
@@ -31,6 +43,14 @@ module Shoulda
31
43
  def double_collections_by_class
32
44
  @_double_collections_by_class ||= {}
33
45
  end
46
+
47
+ def original_methods_by_class
48
+ @_original_methods_by_class ||= {}
49
+ end
50
+
51
+ def original_methods_for_class(klass)
52
+ original_methods_by_class[klass] ||= {}
53
+ end
34
54
  end
35
55
  end
36
56
  end
@@ -0,0 +1,43 @@
1
+ module Shoulda
2
+ module Matchers
3
+ # @private
4
+ module Integrations
5
+ class << self
6
+ def register_library(klass, name)
7
+ library_registry.register(klass, name)
8
+ end
9
+
10
+ def find_library!(name)
11
+ library_registry.find!(name)
12
+ end
13
+
14
+ def register_test_framework(klass, name)
15
+ test_framework_registry.register(klass, name)
16
+ end
17
+
18
+ def find_test_framework!(name)
19
+ test_framework_registry.find!(name)
20
+ end
21
+
22
+ private
23
+
24
+ def library_registry
25
+ @_library_registry ||= Registry.new
26
+ end
27
+
28
+ def test_framework_registry
29
+ @_test_framework_registry ||= Registry.new
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ require 'shoulda/matchers/integrations/configuration'
37
+ require 'shoulda/matchers/integrations/configuration_error'
38
+ require 'shoulda/matchers/integrations/inclusion'
39
+ require 'shoulda/matchers/integrations/rails'
40
+ require 'shoulda/matchers/integrations/registry'
41
+
42
+ require 'shoulda/matchers/integrations/libraries'
43
+ require 'shoulda/matchers/integrations/test_frameworks'
@@ -0,0 +1,68 @@
1
+ require 'set'
2
+
3
+ module Shoulda
4
+ module Matchers
5
+ module Integrations
6
+ # @private
7
+ class Configuration
8
+ def self.apply(configuration, &block)
9
+ new(configuration, &block).apply
10
+ end
11
+
12
+ def initialize(configuration, &block)
13
+ @test_frameworks = Set.new
14
+ @libraries = Set.new
15
+
16
+ test_framework :missing_test_framework
17
+ library :missing_library
18
+
19
+ block.call(self)
20
+ end
21
+
22
+ def test_framework(name)
23
+ clear_default_test_framework
24
+ @test_frameworks << Integrations.find_test_framework!(name)
25
+ end
26
+
27
+ def library(name)
28
+ @libraries << Integrations.find_library!(name)
29
+ end
30
+
31
+ def apply
32
+ if no_test_frameworks_added? && no_libraries_added?
33
+ raise ConfigurationError, <<EOT
34
+ shoulda-matchers is not configured correctly. You need to specify at least one
35
+ test framework and/or library. For example:
36
+
37
+ Shoulda::Matchers.configure do |config|
38
+ config.integrate do |with|
39
+ with.test_framework :rspec
40
+ with.library :rails
41
+ end
42
+ end
43
+ EOT
44
+ end
45
+
46
+ @test_frameworks.each do |test_framework|
47
+ test_framework.include(Shoulda::Matchers::Independent)
48
+ @libraries.each { |library| library.integrate_with(test_framework) }
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def clear_default_test_framework
55
+ @test_frameworks.select!(&:present?)
56
+ end
57
+
58
+ def no_test_frameworks_added?
59
+ @test_frameworks.empty? || !@test_frameworks.any?(&:present?)
60
+ end
61
+
62
+ def no_libraries_added?
63
+ @libraries.empty?
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ # @private
5
+ class ConfigurationError < StandardError
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ # @private
5
+ module Inclusion
6
+ def include_into(mod, *other_mods, &block)
7
+ mods_to_include = other_mods.dup
8
+ mods_to_extend = other_mods.dup
9
+
10
+ if block
11
+ mods_to_include << Module.new(&block)
12
+ end
13
+
14
+ mod.__send__(:include, *mods_to_include)
15
+ mod.extend(*mods_to_extend)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'shoulda/matchers/integrations/libraries/action_controller'
2
+ require 'shoulda/matchers/integrations/libraries/active_model'
3
+ require 'shoulda/matchers/integrations/libraries/active_record'
4
+ require 'shoulda/matchers/integrations/libraries/missing_library'
5
+ require 'shoulda/matchers/integrations/libraries/rails'
6
+
7
+ module Shoulda
8
+ module Matchers
9
+ module Integrations
10
+ # @private
11
+ module Libraries
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ module Libraries
5
+ # @private
6
+ class ActionController
7
+ Integrations.register_library(self, :action_controller)
8
+
9
+ include Integrations::Inclusion
10
+ include Integrations::Rails
11
+
12
+ def integrate_with(test_framework)
13
+ test_framework.include(matchers_module)
14
+
15
+ include_into(::ActionController::TestCase, matchers_module) do
16
+ def subject
17
+ @controller
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def matchers_module
25
+ Shoulda::Matchers::ActionController
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ module Libraries
5
+ # @private
6
+ class ActiveModel
7
+ Integrations.register_library(self, :active_model)
8
+
9
+ include Integrations::Inclusion
10
+ include Integrations::Rails
11
+
12
+ def integrate_with(test_framework)
13
+ test_framework.include(matchers_module)
14
+ include_into(ActiveSupport::TestCase, matchers_module)
15
+ end
16
+
17
+ private
18
+
19
+ def matchers_module
20
+ Shoulda::Matchers::ActiveModel
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ module Libraries
5
+ # @private
6
+ class ActiveRecord
7
+ Integrations.register_library(self, :active_record)
8
+
9
+ include Integrations::Inclusion
10
+ include Integrations::Rails
11
+
12
+ def integrate_with(test_framework)
13
+ test_framework.include(matchers_module)
14
+ include_into(ActiveSupport::TestCase, matchers_module)
15
+ end
16
+
17
+ private
18
+
19
+ def matchers_module
20
+ Shoulda::Matchers::ActiveRecord
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ module Libraries
5
+ # @private
6
+ class MissingLibrary
7
+ Integrations.register_library(self, :missing_library)
8
+
9
+ def integrate_with(test_framework)
10
+ end
11
+
12
+ def rails?
13
+ false
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ module Libraries
5
+ # @private
6
+ class Rails
7
+ Integrations.register_library(self, :rails)
8
+
9
+ include Integrations::Rails
10
+
11
+ SUB_LIBRARIES = [
12
+ :active_model,
13
+ :active_record,
14
+ :action_controller
15
+ ]
16
+
17
+ def integrate_with(test_framework)
18
+ Shoulda::Matchers.assertion_exception_class =
19
+ ActiveSupport::TestCase::Assertion
20
+
21
+ SUB_LIBRARIES.each do |name|
22
+ library = Integrations.find_library!(name)
23
+ library.integrate_with(test_framework)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Integrations
4
+ # @private
5
+ module Rails
6
+ def rails?
7
+ true
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end