rspec 载波应该 has_dimensions 总是失败:拇指未调整大小
我已经设置了载波,它可以很好地处理我的图像。我在子文件夹中得到了经过很好调整大小的拇指版本等等。既来自我的前端 (HTML) 又来自我的 rails 控制台
。我使用 MiniMagic
但在我的 rspec 中拇指测试总是失败。
describe 'processed images' do
before(:each) do
AttachmentUploader.enable_processing = true
AttachmentUploader.enable_processing = true
@uploader = AttachmentUploader.new(@post, :image)
@uploader.store!(File.open(@file))
end
after(:each) do
@uploader.remove!
AttachmentUploader.enable_processing = false
end
describe 'the thumb version' do
it "should scale down ane image to be exactly 50 by 50 pixels" do
@uploader.recreate_versions!
@uploader.thumb.should have_dimensions(50, 50)
end
end
@file
是在装置中找到的文件。它被找到并附加(其他测试通过)。如果我注释掉 @uploader.remove!
行,它会在例如 .../public/uploads/post/image/thumb_fig.png
中留下一个文件。 但是,该文件未调整大小。当通过 rails console
调用相同的序列时,它会很好地调整大小。
我的规格中是否缺少某些内容?我需要设置一个特殊的标志吗?强制运行某种方法?
I have carrierwave set up and it processes my images fine. I get nicely resized thumb versions in a subfolder and all that. Both from my frontend (HTML) and from my rails console
. I use MiniMagic
But in my rspec the thumb test fails always.
describe 'processed images' do
before(:each) do
AttachmentUploader.enable_processing = true
AttachmentUploader.enable_processing = true
@uploader = AttachmentUploader.new(@post, :image)
@uploader.store!(File.open(@file))
end
after(:each) do
@uploader.remove!
AttachmentUploader.enable_processing = false
end
describe 'the thumb version' do
it "should scale down ane image to be exactly 50 by 50 pixels" do
@uploader.recreate_versions!
@uploader.thumb.should have_dimensions(50, 50)
end
end
@file
is a file found in fixtures. It is found and attached (other tests pass). And if I comment out the line @uploader.remove!
, It leaves a file in e.g. .../public/uploads/post/image/thumb_fig.png
.
That file, however is not resized. When invoking the same sequence trough rails console
it gets resized just fine.
Am I missing something in my specs? Do I need to set a special flag? Force a certain method to be ran?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参加这个聚会有点晚了,但我自己也在做类似的事情。据我所知,你的测试看起来不错,尽管我相信@uploader.recreate_Versions!是不必要的。否则,请检查以确保您在 Uploader 类中确实有一个要处理的调用,并且您
在您的测试中包含 CarrierWave::Test::Matchers
a little late to this party but working on something similar myself. From what I can tell your test looks fine although I believe @uploader.recreate_Versions! is unnecessary. Otherwise check to make sure that you do have a call to process in your Uploader class and that you
include CarrierWave::Test::Matchers
in your tests确保您已在 config/initializers/rierwave.rb 中启用 Carrierwave 处理。
它应该是:
Make sure you have enabled processing for Carrierwave in
config/initializers/carrierwave.rb
.It should read: