Testing File Attachment Validation Matchers in Paperclip
This test suite validates the HaveAttachedFileMatcher functionality in Paperclip’s Shoulda matchers. It ensures proper attachment validation behavior for models using Paperclip’s file attachment system. The tests verify both positive and negative cases of file attachment detection.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
thoughtbot/paperclip
spec/paperclip/matchers/have_attached_file_matcher_spec.rb
require 'spec_helper'
require 'paperclip/matchers'
describe Paperclip::Shoulda::Matchers::HaveAttachedFileMatcher do
extend Paperclip::Shoulda::Matchers
it "rejects the dummy class if it has no attachment" do
reset_table "dummies"
reset_class "Dummy"
matcher = self.class.have_attached_file(:avatar)
expect(matcher).to_not accept(Dummy)
end
it 'accepts the dummy class if it has an attachment' do
rebuild_model
matcher = self.class.have_attached_file(:avatar)
expect(matcher).to accept(Dummy)
end
end