这个规范在我的CentOS开发盒上运行得很好,但在我的Macbook(10.7)上运行时失败了。
应用程序/模型/ issue.rb
class Issue < ActiveRecord::Base
has_attached_file :cover_image,
:styles => {
:thumbnail => ["80x80>"],
:large => ["600x600>"]
},
:path => ":rails_root/public/images/issues/:id/:style_:basename.:extension",
:url => "issues/:id/:style_:basename.:extension"
validates_attachment_content_type :cover_image, :content_type => ['image/jpeg', 'image/png']
attr_protected :cover_image_file_name, :cover_image_content_type, :cover_image_file_size
end
规格/模型/ issue_spec.rb
require 'spec_helper'
describe Issue do
it 'should not accept invalid image types' do
%w[spec/factories/assets/docs/image.jpg spec/factories/assets/docs/image.txt].each do |file_path| #image.jpg is a text file with a .jpg extension
issue = Factory.build(:issue, :cover_image => File.new(Rails.root + file_path))
issue.should have(2).errors_on(:cover_image)
end
end
end
在我的CentOS开发盒中,运行测试时没有失败。在我的Macbook上,我收到了这个错误:
Failure/Error: issue.should have(2)errors_on(:cover_image)
expected 2 errors on :cover_image, got 0
如果我尝试通过在浏览器中上传其中一个无效图像类型来尝试创建问题,则在两台计算机上,如果我使用有效的图像类型,它会失败并显示我期望的错误消息。
paperclip-2.4.2
rspec-2.6.0
factory_girl_rails-1.2.0
CentOS: ImageMagick-6.2.8 (yum package)
Mac OS X: ImageMagick-6.7.2-0 (Macports)