Sha256: d155acf77e59dc7981e7b22cb0909c867f77b5bf0db89219b2678c3c3f734a11

Contents?: true

Size: 1.95 KB

Versions: 14

Compression:

Stored size: 1.95 KB

Contents

require "paperclip/matchers/have_attached_file_matcher"
require "paperclip/matchers/validate_attachment_presence_matcher"
require "paperclip/matchers/validate_attachment_content_type_matcher"
require "paperclip/matchers/validate_attachment_size_matcher"

module Paperclip
  module Shoulda
    # Provides RSpec-compatible & Test::Unit-compatible matchers for testing Paperclip attachments.
    #
    # *RSpec*
    #
    # In spec_helper.rb, you'll need to require the matchers:
    #
    #   require "paperclip/matchers"
    #
    # And _include_ the module:
    #
    #   RSpec.configure do |config|
    #     config.include Paperclip::Shoulda::Matchers
    #   end
    #
    # Example:
    #   describe User do
    #     it { should have_attached_file(:avatar) }
    #     it { should validate_attachment_presence(:avatar) }
    #     it { should validate_attachment_content_type(:avatar).
    #                   allowing('image/png', 'image/gif').
    #                   rejecting('text/plain', 'text/xml') }
    #     it { should validate_attachment_size(:avatar).
    #                   less_than(2.megabytes) }
    #   end
    #
    #
    # *TestUnit*
    #
    # In test_helper.rb, you'll need to require the matchers as well:
    #
    #   require "paperclip/matchers"
    #
    # And _extend_ the module:
    #
    #   class ActiveSupport::TestCase
    #     extend Paperclip::Shoulda::Matchers
    #
    #     #...other initializers...#
    #   end
    #
    # Example:
    #   require 'test_helper'
    #
    #   class UserTest < ActiveSupport::TestCase
    #     should have_attached_file(:avatar)
    #     should validate_attachment_presence(:avatar)
    #     should validate_attachment_content_type(:avatar).
    #                  allowing('image/png', 'image/gif').
    #                  rejecting('text/plain', 'text/xml')
    #     should validate_attachment_size(:avatar).
    #                  less_than(2.megabytes)
    #   end
    #
    module Matchers
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kt-paperclip-7.2.2 lib/paperclip/matchers.rb
kt-paperclip-7.2.1 lib/paperclip/matchers.rb
kt-paperclip-7.2.0 lib/paperclip/matchers.rb
kt-paperclip-6.4.2 lib/paperclip/matchers.rb
kt-paperclip-7.1.1 lib/paperclip/matchers.rb
kt-paperclip-7.1.0 lib/paperclip/matchers.rb
kt-paperclip-7.0.1 lib/paperclip/matchers.rb
kt-paperclip-7.0.0 lib/paperclip/matchers.rb
kt-paperclip-6.4.1 lib/paperclip/matchers.rb
kt-paperclip-6.4.0 lib/paperclip/matchers.rb
kt-paperclip-6.3.0 lib/paperclip/matchers.rb
kt-paperclip-6.2.2 lib/paperclip/matchers.rb
kt-paperclip-6.2.1 lib/paperclip/matchers.rb
kt-paperclip-6.2.0 lib/paperclip/matchers.rb