mcmire-shoulda-matchers 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.gitignore +12 -0
 - data/.travis.yml +32 -0
 - data/.yardopts +7 -0
 - data/Appraisals +45 -0
 - data/CONTRIBUTING.md +41 -0
 - data/Gemfile +31 -0
 - data/Gemfile.lock +166 -0
 - data/MIT-LICENSE +22 -0
 - data/NEWS.md +299 -0
 - data/README.md +163 -0
 - data/Rakefile +116 -0
 - data/doc_config/gh-pages/index.html.erb +9 -0
 - data/doc_config/yard/setup.rb +22 -0
 - data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
 - data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
 - data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
 - data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
 - data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
 - data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
 - data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
 - data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
 - data/doc_config/yard/templates/default/fulldoc/html/js/app.js +300 -0
 - data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
 - data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
 - data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
 - data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
 - data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
 - data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
 - data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
 - data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
 - data/doc_config/yard/templates/default/layout/html/setup.rb +8 -0
 - data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
 - data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
 - data/features/rails_integration.feature +113 -0
 - data/features/step_definitions/rails_steps.rb +162 -0
 - data/features/support/env.rb +5 -0
 - data/gemfiles/3.0.gemfile +24 -0
 - data/gemfiles/3.0.gemfile.lock +150 -0
 - data/gemfiles/3.1.gemfile +27 -0
 - data/gemfiles/3.1.gemfile.lock +173 -0
 - data/gemfiles/3.2.gemfile +27 -0
 - data/gemfiles/3.2.gemfile.lock +171 -0
 - data/gemfiles/4.0.0.gemfile +28 -0
 - data/gemfiles/4.0.0.gemfile.lock +172 -0
 - data/gemfiles/4.0.1.gemfile +28 -0
 - data/gemfiles/4.0.1.gemfile.lock +172 -0
 - data/lib/shoulda-matchers.rb +1 -0
 - data/lib/shoulda/matchers.rb +11 -0
 - data/lib/shoulda/matchers/action_controller.rb +17 -0
 - data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +64 -0
 - data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +97 -0
 - data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +81 -0
 - data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +117 -0
 - data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +114 -0
 - data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +154 -0
 - data/lib/shoulda/matchers/action_controller/route_matcher.rb +116 -0
 - data/lib/shoulda/matchers/action_controller/route_params.rb +48 -0
 - data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +164 -0
 - data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +296 -0
 - data/lib/shoulda/matchers/active_model.rb +30 -0
 - data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +167 -0
 - data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +314 -0
 - data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +46 -0
 - data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +160 -0
 - data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +417 -0
 - data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +337 -0
 - data/lib/shoulda/matchers/active_model/errors.rb +10 -0
 - data/lib/shoulda/matchers/active_model/exception_message_finder.rb +58 -0
 - data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +92 -0
 - data/lib/shoulda/matchers/active_model/helpers.rb +46 -0
 - data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
 - data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +75 -0
 - data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +27 -0
 - data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +41 -0
 - data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +27 -0
 - data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +26 -0
 - data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +112 -0
 - data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +77 -0
 - data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +121 -0
 - data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +380 -0
 - data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +89 -0
 - data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +372 -0
 - data/lib/shoulda/matchers/active_model/validation_matcher.rb +97 -0
 - data/lib/shoulda/matchers/active_model/validation_message_finder.rb +69 -0
 - data/lib/shoulda/matchers/active_record.rb +22 -0
 - data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +204 -0
 - data/lib/shoulda/matchers/active_record/association_matcher.rb +901 -0
 - data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +41 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +41 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +81 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +65 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +94 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +41 -0
 - data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +63 -0
 - data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +261 -0
 - data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +149 -0
 - data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +72 -0
 - data/lib/shoulda/matchers/active_record/serialize_matcher.rb +181 -0
 - data/lib/shoulda/matchers/assertion_error.rb +19 -0
 - data/lib/shoulda/matchers/error.rb +6 -0
 - data/lib/shoulda/matchers/integrations/rspec.rb +20 -0
 - data/lib/shoulda/matchers/integrations/test_unit.rb +30 -0
 - data/lib/shoulda/matchers/rails_shim.rb +50 -0
 - data/lib/shoulda/matchers/version.rb +6 -0
 - data/lib/shoulda/matchers/warn.rb +8 -0
 - data/shoulda-matchers.gemspec +23 -0
 - data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
 - data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
 - data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
 - data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +63 -0
 - data/spec/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +63 -0
 - data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
 - data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +70 -0
 - data/spec/shoulda/matchers/action_controller/route_params_spec.rb +30 -0
 - data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
 - data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
 - data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
 - data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +170 -0
 - data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +81 -0
 - data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +95 -0
 - data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +320 -0
 - data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +166 -0
 - data/spec/shoulda/matchers/active_model/exception_message_finder_spec.rb +111 -0
 - data/spec/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +20 -0
 - data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
 - data/spec/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +169 -0
 - data/spec/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +59 -0
 - data/spec/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +59 -0
 - data/spec/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +57 -0
 - data/spec/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +139 -0
 - data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
 - data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +47 -0
 - data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +331 -0
 - data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +180 -0
 - data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +398 -0
 - data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +127 -0
 - data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +107 -0
 - data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +860 -0
 - data/spec/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +247 -0
 - data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
 - data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
 - data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
 - data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
 - data/spec/spec_helper.rb +26 -0
 - data/spec/support/active_model_versions.rb +13 -0
 - data/spec/support/active_resource_builder.rb +29 -0
 - data/spec/support/activemodel_helpers.rb +19 -0
 - data/spec/support/capture_helpers.rb +19 -0
 - data/spec/support/class_builder.rb +42 -0
 - data/spec/support/controller_builder.rb +74 -0
 - data/spec/support/fail_with_message_including_matcher.rb +33 -0
 - data/spec/support/fail_with_message_matcher.rb +32 -0
 - data/spec/support/i18n_faker.rb +10 -0
 - data/spec/support/mailer_builder.rb +10 -0
 - data/spec/support/model_builder.rb +81 -0
 - data/spec/support/rails_versions.rb +18 -0
 - data/spec/support/shared_examples/numerical_submatcher.rb +19 -0
 - data/spec/support/shared_examples/numerical_type_submatcher.rb +17 -0
 - data/spec/support/test_application.rb +120 -0
 - data/yard.watchr +5 -0
 - metadata +281 -0
 
| 
         @@ -0,0 +1,181 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Shoulda
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Matchers
         
     | 
| 
      
 3 
     | 
    
         
            +
                module ActiveRecord
         
     | 
| 
      
 4 
     | 
    
         
            +
                  # The `serialize` matcher tests usage of the `serialize` macro.
         
     | 
| 
      
 5 
     | 
    
         
            +
                  #
         
     | 
| 
      
 6 
     | 
    
         
            +
                  #     class Product < ActiveRecord::Base
         
     | 
| 
      
 7 
     | 
    
         
            +
                  #       serialize :customizations
         
     | 
| 
      
 8 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 9 
     | 
    
         
            +
                  #
         
     | 
| 
      
 10 
     | 
    
         
            +
                  #     # RSpec
         
     | 
| 
      
 11 
     | 
    
         
            +
                  #     describe Product do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  #       it { should serialize(:customizations) }
         
     | 
| 
      
 13 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 14 
     | 
    
         
            +
                  #
         
     | 
| 
      
 15 
     | 
    
         
            +
                  #     # Test::Unit
         
     | 
| 
      
 16 
     | 
    
         
            +
                  #     class ProductTest < ActiveSupport::TestCase
         
     | 
| 
      
 17 
     | 
    
         
            +
                  #       should serialize(:customizations)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  #
         
     | 
| 
      
 20 
     | 
    
         
            +
                  # #### Qualifiers
         
     | 
| 
      
 21 
     | 
    
         
            +
                  #
         
     | 
| 
      
 22 
     | 
    
         
            +
                  # ##### as
         
     | 
| 
      
 23 
     | 
    
         
            +
                  #
         
     | 
| 
      
 24 
     | 
    
         
            +
                  # Use `as` if you are using a custom serializer class.
         
     | 
| 
      
 25 
     | 
    
         
            +
                  #
         
     | 
| 
      
 26 
     | 
    
         
            +
                  #     class ProductSpecsSerializer
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #       def load(string)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #         # ...
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #       end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #       def dump(options)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #         # ...
         
     | 
| 
      
 33 
     | 
    
         
            +
                  #       end
         
     | 
| 
      
 34 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 35 
     | 
    
         
            +
                  #
         
     | 
| 
      
 36 
     | 
    
         
            +
                  #     class Product < ActiveRecord::Base
         
     | 
| 
      
 37 
     | 
    
         
            +
                  #       serialize :specifications, ProductSpecsSerializer
         
     | 
| 
      
 38 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #     # RSpec
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #     describe Product do
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #       it { should serialize(:specifications).as(ProductSpecsSerializer) }
         
     | 
| 
      
 43 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  #
         
     | 
| 
      
 45 
     | 
    
         
            +
                  #     # Test::Unit
         
     | 
| 
      
 46 
     | 
    
         
            +
                  #     class ProductTest < ActiveSupport::TestCase
         
     | 
| 
      
 47 
     | 
    
         
            +
                  #       should serialize(:specifications).as(ProductSpecsSerializer)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  #
         
     | 
| 
      
 50 
     | 
    
         
            +
                  # ##### as_instance_of
         
     | 
| 
      
 51 
     | 
    
         
            +
                  #
         
     | 
| 
      
 52 
     | 
    
         
            +
                  # Use `as_instance_of` if you are using a custom serializer object.
         
     | 
| 
      
 53 
     | 
    
         
            +
                  #
         
     | 
| 
      
 54 
     | 
    
         
            +
                  #     class ProductOptionsSerializer
         
     | 
| 
      
 55 
     | 
    
         
            +
                  #       def load(string)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  #         # ...
         
     | 
| 
      
 57 
     | 
    
         
            +
                  #       end
         
     | 
| 
      
 58 
     | 
    
         
            +
                  #
         
     | 
| 
      
 59 
     | 
    
         
            +
                  #       def dump(options)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  #         # ...
         
     | 
| 
      
 61 
     | 
    
         
            +
                  #       end
         
     | 
| 
      
 62 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 63 
     | 
    
         
            +
                  #
         
     | 
| 
      
 64 
     | 
    
         
            +
                  #     class Product < ActiveRecord::Base
         
     | 
| 
      
 65 
     | 
    
         
            +
                  #       serialize :options, ProductOptionsSerializer.new
         
     | 
| 
      
 66 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 67 
     | 
    
         
            +
                  #
         
     | 
| 
      
 68 
     | 
    
         
            +
                  #     # RSpec
         
     | 
| 
      
 69 
     | 
    
         
            +
                  #     describe Product do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  #       it { should serialize(:options).as_instance_of(ProductOptionsSerializer) }
         
     | 
| 
      
 71 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 72 
     | 
    
         
            +
                  #
         
     | 
| 
      
 73 
     | 
    
         
            +
                  #     # Test::Unit
         
     | 
| 
      
 74 
     | 
    
         
            +
                  #     class ProductTest < ActiveSupport::TestCase
         
     | 
| 
      
 75 
     | 
    
         
            +
                  #       should serialize(:options).as_instance_of(ProductOptionsSerializer)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 77 
     | 
    
         
            +
                  #
         
     | 
| 
      
 78 
     | 
    
         
            +
                  # @return [SerializeMatcher]
         
     | 
| 
      
 79 
     | 
    
         
            +
                  #
         
     | 
| 
      
 80 
     | 
    
         
            +
                  def serialize(name)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    SerializeMatcher.new(name)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                  # @private
         
     | 
| 
      
 85 
     | 
    
         
            +
                  class SerializeMatcher
         
     | 
| 
      
 86 
     | 
    
         
            +
                    def initialize(name)
         
     | 
| 
      
 87 
     | 
    
         
            +
                      @name = name.to_s
         
     | 
| 
      
 88 
     | 
    
         
            +
                      @options = {}
         
     | 
| 
      
 89 
     | 
    
         
            +
                    end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                    def as(type)
         
     | 
| 
      
 92 
     | 
    
         
            +
                      @options[:type] = type
         
     | 
| 
      
 93 
     | 
    
         
            +
                      self
         
     | 
| 
      
 94 
     | 
    
         
            +
                    end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                    def as_instance_of(type)
         
     | 
| 
      
 97 
     | 
    
         
            +
                      @options[:instance_type] = type
         
     | 
| 
      
 98 
     | 
    
         
            +
                      self
         
     | 
| 
      
 99 
     | 
    
         
            +
                    end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                    def matches?(subject)
         
     | 
| 
      
 102 
     | 
    
         
            +
                      @subject = subject
         
     | 
| 
      
 103 
     | 
    
         
            +
                      serialization_valid? && type_valid?
         
     | 
| 
      
 104 
     | 
    
         
            +
                    end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                    def failure_message
         
     | 
| 
      
 107 
     | 
    
         
            +
                      "Expected #{expectation} (#{@missing})"
         
     | 
| 
      
 108 
     | 
    
         
            +
                    end
         
     | 
| 
      
 109 
     | 
    
         
            +
                    alias failure_message_for_should failure_message
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                    def failure_message_when_negated
         
     | 
| 
      
 112 
     | 
    
         
            +
                      "Did not expect #{expectation}"
         
     | 
| 
      
 113 
     | 
    
         
            +
                    end
         
     | 
| 
      
 114 
     | 
    
         
            +
                    alias failure_message_for_should_not failure_message_when_negated
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                    def description
         
     | 
| 
      
 117 
     | 
    
         
            +
                      description = "serialize :#{@name}"
         
     | 
| 
      
 118 
     | 
    
         
            +
                      description += " class_name => #{@options[:type]}" if @options.key?(:type)
         
     | 
| 
      
 119 
     | 
    
         
            +
                      description
         
     | 
| 
      
 120 
     | 
    
         
            +
                    end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                    protected
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                    def serialization_valid?
         
     | 
| 
      
 125 
     | 
    
         
            +
                      if model_class.serialized_attributes.keys.include?(@name)
         
     | 
| 
      
 126 
     | 
    
         
            +
                        true
         
     | 
| 
      
 127 
     | 
    
         
            +
                      else
         
     | 
| 
      
 128 
     | 
    
         
            +
                        @missing = "no serialized attribute called :#{@name}"
         
     | 
| 
      
 129 
     | 
    
         
            +
                        false
         
     | 
| 
      
 130 
     | 
    
         
            +
                      end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                    def class_valid?
         
     | 
| 
      
 134 
     | 
    
         
            +
                      if @options[:type]
         
     | 
| 
      
 135 
     | 
    
         
            +
                        klass = model_class.serialized_attributes[@name]
         
     | 
| 
      
 136 
     | 
    
         
            +
                        if klass == @options[:type]
         
     | 
| 
      
 137 
     | 
    
         
            +
                          true
         
     | 
| 
      
 138 
     | 
    
         
            +
                        else
         
     | 
| 
      
 139 
     | 
    
         
            +
                          if klass.respond_to?(:object_class) && klass.object_class == @options[:type]
         
     | 
| 
      
 140 
     | 
    
         
            +
                            true
         
     | 
| 
      
 141 
     | 
    
         
            +
                          else
         
     | 
| 
      
 142 
     | 
    
         
            +
                            @missing = ":#{@name} should be a type of #{@options[:type]}"
         
     | 
| 
      
 143 
     | 
    
         
            +
                            false
         
     | 
| 
      
 144 
     | 
    
         
            +
                          end
         
     | 
| 
      
 145 
     | 
    
         
            +
                        end
         
     | 
| 
      
 146 
     | 
    
         
            +
                      else
         
     | 
| 
      
 147 
     | 
    
         
            +
                        true
         
     | 
| 
      
 148 
     | 
    
         
            +
                      end
         
     | 
| 
      
 149 
     | 
    
         
            +
                    end
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                    def model_class
         
     | 
| 
      
 152 
     | 
    
         
            +
                      @subject.class
         
     | 
| 
      
 153 
     | 
    
         
            +
                    end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                    def instance_class_valid?
         
     | 
| 
      
 156 
     | 
    
         
            +
                      if @options.key?(:instance_type)
         
     | 
| 
      
 157 
     | 
    
         
            +
                        if model_class.serialized_attributes[@name].class == @options[:instance_type]
         
     | 
| 
      
 158 
     | 
    
         
            +
                          true
         
     | 
| 
      
 159 
     | 
    
         
            +
                        else
         
     | 
| 
      
 160 
     | 
    
         
            +
                          @missing = ":#{@name} should be an instance of #{@options[:type]}"
         
     | 
| 
      
 161 
     | 
    
         
            +
                          false
         
     | 
| 
      
 162 
     | 
    
         
            +
                        end
         
     | 
| 
      
 163 
     | 
    
         
            +
                      else
         
     | 
| 
      
 164 
     | 
    
         
            +
                        true
         
     | 
| 
      
 165 
     | 
    
         
            +
                      end
         
     | 
| 
      
 166 
     | 
    
         
            +
                    end
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                    def type_valid?
         
     | 
| 
      
 169 
     | 
    
         
            +
                      class_valid? && instance_class_valid?
         
     | 
| 
      
 170 
     | 
    
         
            +
                    end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                    def expectation
         
     | 
| 
      
 173 
     | 
    
         
            +
                      expectation = "#{model_class.name} to serialize the attribute called :#{@name}"
         
     | 
| 
      
 174 
     | 
    
         
            +
                      expectation += " with a type of #{@options[:type]}" if @options[:type]
         
     | 
| 
      
 175 
     | 
    
         
            +
                      expectation += " with an instance of #{@options[:instance_type]}" if @options[:instance_type]
         
     | 
| 
      
 176 
     | 
    
         
            +
                      expectation
         
     | 
| 
      
 177 
     | 
    
         
            +
                    end
         
     | 
| 
      
 178 
     | 
    
         
            +
                  end
         
     | 
| 
      
 179 
     | 
    
         
            +
                end
         
     | 
| 
      
 180 
     | 
    
         
            +
              end
         
     | 
| 
      
 181 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Shoulda
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Matchers
         
     | 
| 
      
 3 
     | 
    
         
            +
                if Gem.ruby_version >= Gem::Version.new('1.8') && Gem.ruby_version < Gem::Version.new('1.9')
         
     | 
| 
      
 4 
     | 
    
         
            +
                  require 'test/unit'
         
     | 
| 
      
 5 
     | 
    
         
            +
                  # @private
         
     | 
| 
      
 6 
     | 
    
         
            +
                  AssertionError = Test::Unit::AssertionFailedError
         
     | 
| 
      
 7 
     | 
    
         
            +
                elsif defined?(Test::Unit::AssertionFailedError)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # Test::Unit has been loaded already, so we use it
         
     | 
| 
      
 9 
     | 
    
         
            +
                  # @private
         
     | 
| 
      
 10 
     | 
    
         
            +
                  AssertionError = Test::Unit::AssertionFailedError
         
     | 
| 
      
 11 
     | 
    
         
            +
                elsif Gem.ruby_version >= Gem::Version.new("1.9")
         
     | 
| 
      
 12 
     | 
    
         
            +
                  require 'minitest/unit'
         
     | 
| 
      
 13 
     | 
    
         
            +
                  # @private
         
     | 
| 
      
 14 
     | 
    
         
            +
                  AssertionError = MiniTest::Assertion
         
     | 
| 
      
 15 
     | 
    
         
            +
                else
         
     | 
| 
      
 16 
     | 
    
         
            +
                  raise 'No unit test library available'
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # :enddoc:
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rspec/core'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            RSpec.configure do |config|
         
     | 
| 
      
 5 
     | 
    
         
            +
              if defined?(::ActiveRecord)
         
     | 
| 
      
 6 
     | 
    
         
            +
                require 'shoulda/matchers/active_record'
         
     | 
| 
      
 7 
     | 
    
         
            +
                require 'shoulda/matchers/active_model'
         
     | 
| 
      
 8 
     | 
    
         
            +
                config.include Shoulda::Matchers::ActiveRecord
         
     | 
| 
      
 9 
     | 
    
         
            +
                config.include Shoulda::Matchers::ActiveModel
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              elsif defined?(::ActiveModel)
         
     | 
| 
      
 12 
     | 
    
         
            +
                require 'shoulda/matchers/active_model'
         
     | 
| 
      
 13 
     | 
    
         
            +
                config.include Shoulda::Matchers::ActiveModel
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              if defined?(::ActionController)
         
     | 
| 
      
 17 
     | 
    
         
            +
                require 'shoulda/matchers/action_controller'
         
     | 
| 
      
 18 
     | 
    
         
            +
                config.include Shoulda::Matchers::ActionController
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            if defined?(ActionController) && defined?(ActionController::TestCase)
         
     | 
| 
      
 2 
     | 
    
         
            +
              require 'shoulda/matchers/action_controller'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              ActionController::TestCase.class_eval do
         
     | 
| 
      
 5 
     | 
    
         
            +
                include Shoulda::Matchers::ActionController
         
     | 
| 
      
 6 
     | 
    
         
            +
                extend Shoulda::Matchers::ActionController
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                def subject
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @controller
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            if defined?(ActiveRecord) && defined?(ActiveSupport::TestCase)
         
     | 
| 
      
 15 
     | 
    
         
            +
              require 'shoulda/matchers/active_record'
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              ActiveSupport::TestCase.class_eval do
         
     | 
| 
      
 18 
     | 
    
         
            +
                include Shoulda::Matchers::ActiveRecord
         
     | 
| 
      
 19 
     | 
    
         
            +
                extend Shoulda::Matchers::ActiveRecord
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            if defined?(ActiveModel) && defined?(ActiveSupport::TestCase)
         
     | 
| 
      
 24 
     | 
    
         
            +
              require 'shoulda/matchers/active_model'
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              ActiveSupport::TestCase.class_eval do
         
     | 
| 
      
 27 
     | 
    
         
            +
                include Shoulda::Matchers::ActiveModel
         
     | 
| 
      
 28 
     | 
    
         
            +
                extend Shoulda::Matchers::ActiveModel
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Shoulda
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Matchers
         
     | 
| 
      
 3 
     | 
    
         
            +
                # @private
         
     | 
| 
      
 4 
     | 
    
         
            +
                class RailsShim
         
     | 
| 
      
 5 
     | 
    
         
            +
                  def self.layouts_ivar
         
     | 
| 
      
 6 
     | 
    
         
            +
                    if action_pack_major_version >= 4
         
     | 
| 
      
 7 
     | 
    
         
            +
                      '@_layouts'
         
     | 
| 
      
 8 
     | 
    
         
            +
                    else
         
     | 
| 
      
 9 
     | 
    
         
            +
                      '@layouts'
         
     | 
| 
      
 10 
     | 
    
         
            +
                    end
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def self.flashes_ivar
         
     | 
| 
      
 14 
     | 
    
         
            +
                    if action_pack_major_version >= 4
         
     | 
| 
      
 15 
     | 
    
         
            +
                      :@flashes
         
     | 
| 
      
 16 
     | 
    
         
            +
                    else
         
     | 
| 
      
 17 
     | 
    
         
            +
                      :@used
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  def self.clean_scope(klass)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    if active_record_major_version == 4
         
     | 
| 
      
 23 
     | 
    
         
            +
                      klass.all
         
     | 
| 
      
 24 
     | 
    
         
            +
                    else
         
     | 
| 
      
 25 
     | 
    
         
            +
                      klass.scoped
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  def self.validates_confirmation_of_error_attribute(matcher)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    if active_model_major_version == 4
         
     | 
| 
      
 31 
     | 
    
         
            +
                      matcher.confirmation_attribute
         
     | 
| 
      
 32 
     | 
    
         
            +
                    else
         
     | 
| 
      
 33 
     | 
    
         
            +
                      matcher.attribute
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  def self.active_record_major_version
         
     | 
| 
      
 38 
     | 
    
         
            +
                    ::ActiveRecord::VERSION::MAJOR
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  def self.active_model_major_version
         
     | 
| 
      
 42 
     | 
    
         
            +
                    ::ActiveModel::VERSION::MAJOR
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  def self.action_pack_major_version
         
     | 
| 
      
 46 
     | 
    
         
            +
                    ::ActionPack::VERSION::MAJOR
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'shoulda/matchers/version'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Gem::Specification.new do |s|
         
     | 
| 
      
 5 
     | 
    
         
            +
              s.name        = "mcmire-shoulda-matchers"
         
     | 
| 
      
 6 
     | 
    
         
            +
              s.version     = Shoulda::Matchers::VERSION.dup
         
     | 
| 
      
 7 
     | 
    
         
            +
              s.authors     = ["Tammer Saleh", "Joe Ferris", "Ryan McGeary", "Dan Croak",
         
     | 
| 
      
 8 
     | 
    
         
            +
                               "Matt Jankowski", "Stafford Brunk"]
         
     | 
| 
      
 9 
     | 
    
         
            +
              s.date        = Time.now.strftime("%Y-%m-%d")
         
     | 
| 
      
 10 
     | 
    
         
            +
              s.email       = "support@thoughtbot.com"
         
     | 
| 
      
 11 
     | 
    
         
            +
              s.homepage    = "http://thoughtbot.com/community/"
         
     | 
| 
      
 12 
     | 
    
         
            +
              s.summary     = "Making tests easy on the fingers and eyes"
         
     | 
| 
      
 13 
     | 
    
         
            +
              s.license     = "MIT"
         
     | 
| 
      
 14 
     | 
    
         
            +
              s.description = "Making tests easy on the fingers and eyes"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              s.files         = `git ls-files`.split("\n")
         
     | 
| 
      
 17 
     | 
    
         
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         
     | 
| 
      
 18 
     | 
    
         
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         
     | 
| 
      
 19 
     | 
    
         
            +
              s.require_paths = ["lib"]
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              s.required_ruby_version = '>= 1.9.2'
         
     | 
| 
      
 22 
     | 
    
         
            +
              s.add_dependency('activesupport', '>= 3.0.0')
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Shoulda::Matchers::ActionController::FilterParamMatcher do
         
     | 
| 
      
 4 
     | 
    
         
            +
              it 'accepts filtering a filtered parameter' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                filter(:secret)
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                expect(nil).to filter_param(:secret)
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              it 'rejects filtering an unfiltered parameter' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                filter(:secret)
         
     | 
| 
      
 12 
     | 
    
         
            +
                matcher = filter_param(:other)
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                expect(matcher.matches?(nil)).to eq false
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                expect(matcher.failure_message).to match(/Expected other to be filtered.*secret/)
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def filter(param)
         
     | 
| 
      
 20 
     | 
    
         
            +
                Rails.application.config.filter_parameters = [param]
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Shoulda::Matchers::ActionController::RedirectToMatcher do
         
     | 
| 
      
 4 
     | 
    
         
            +
              context 'a controller that redirects' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                it 'accepts redirecting to that url' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  expect(controller_redirecting_to('/some/url')).to redirect_to('/some/url')
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                it 'rejects redirecting to a different url' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  expect(controller_redirecting_to('/some/url')).
         
     | 
| 
      
 11 
     | 
    
         
            +
                    not_to redirect_to('/some/other/url')
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                it 'accepts redirecting to that url in a block' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  expect(controller_redirecting_to('/some/url')).
         
     | 
| 
      
 16 
     | 
    
         
            +
                    to redirect_to('somewhere') { '/some/url' }
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                it 'rejects redirecting to a different url in a block' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  expect(controller_redirecting_to('/some/url')).
         
     | 
| 
      
 21 
     | 
    
         
            +
                    not_to redirect_to('somewhere else') { '/some/other/url' }
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def controller_redirecting_to(url)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  build_response { redirect_to url }
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              context 'a controller that does not redirect' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                it 'rejects redirecting to a url' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  controller = build_response { render text: 'hello' }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(controller).not_to redirect_to('/some/url')
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              it 'provides the correct description when provided a block' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                matcher = redirect_to('somewhere else') { '/some/other/url' }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                expect(matcher.description).to eq 'redirect to somewhere else'
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,78 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Shoulda::Matchers::ActionController::RenderTemplateMatcher do
         
     | 
| 
      
 4 
     | 
    
         
            +
              include ActionController::TemplateAssertions
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              context 'a controller that renders a template' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                it 'accepts rendering that template' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                  expect(controller_with_show).to render_template(:show)
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                it 'rejects rendering a different template' do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  expect(controller_with_show).not_to render_template(:index)
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                it 'accepts rendering that template in the given context' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  expect(controller_with_show).to render_template(:show).in_context(self)
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                it 'rejects rendering a different template in the given context' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  expect(controller_with_show).not_to render_template(:index).in_context(self)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def controller_with_show
         
     | 
| 
      
 24 
     | 
    
         
            +
                  build_response(action: 'show') { render }
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              context 'a controller that renders a partial' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                it 'accepts rendering that partial' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(controller_with_customer_partial).
         
     | 
| 
      
 31 
     | 
    
         
            +
                    to render_template(partial: '_customer')
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                it 'rejects rendering a different template' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  expect(controller_with_customer_partial).
         
     | 
| 
      
 36 
     | 
    
         
            +
                    not_to render_template(partial: '_client')
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                it 'accepts rendering that template in the given context' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  expect(controller_with_customer_partial).
         
     | 
| 
      
 41 
     | 
    
         
            +
                    to render_template(partial: '_customer').in_context(self)
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                it 'rejects rendering a different template in the given context' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                  expect(controller_with_customer_partial).
         
     | 
| 
      
 46 
     | 
    
         
            +
                    not_to render_template(partial: '_client').in_context(self)
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def controller_with_customer_partial
         
     | 
| 
      
 50 
     | 
    
         
            +
                  build_response(partial: '_customer') { render partial: 'customer' }
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              context 'a controller that does not render partials' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                it 'accepts not rendering a partial' do
         
     | 
| 
      
 56 
     | 
    
         
            +
                  controller = build_response(action: 'show') { render }
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  expect(controller).to render_template(partial: false)
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              context 'a controller that renders a partial several times' do
         
     | 
| 
      
 63 
     | 
    
         
            +
                it 'accepts rendering that partial twice' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  controller = build_response(partial: '_customer') do
         
     | 
| 
      
 65 
     | 
    
         
            +
                    render partial: 'customer', collection: [1,2]
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                  expect(controller).to render_template(partial: '_customer', count: 2)
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
              context 'a controller that does not render a template' do
         
     | 
| 
      
 73 
     | 
    
         
            +
                it 'rejects rendering a template' do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  expect(build_response { render nothing: true }).
         
     | 
| 
      
 75 
     | 
    
         
            +
                    not_to render_template(:show)
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
              end
         
     | 
| 
      
 78 
     | 
    
         
            +
            end
         
     |