In rspec how do I test what attribute failed the strict validation. I have only been able to test if the “ActiveModel::StrictValidationFailed” exception was thrown.
Here is a example:
it "should not be valid if the asset already exists" do
n = Factory.build( :private_attached_asset, :asset => Rack::Test::UploadedFile.new( "test.pdf", 'application/pdf' ))
expect { n.save }.should raise_error(ActiveModel::StrictValidationFailed)
#n.should have(1).error_on(:checksum)
end
The commented out line throws the exception again.
You can’t check for error messages on strict validations because they raise immediately and don’t set the
errorsobject. Alternatively, you can test the exact error message raised: