rspec 载波应该 has_dimensions 总是失败:拇指未调整大小

发布于 2024-10-11 14:25:42 字数 1002 浏览 3 评论 0原文

我已经设置了载波,它可以很好地处理我的图像。我在子文件夹中得到了经过很好调整大小的拇指版本等等。既来自我的前端 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱世争霸 2024-10-18 14:25:42

参加这个聚会有点晚了,但我自己也在做类似的事情。据我所知,你的测试看起来不错,尽管我相信@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

亢潮 2024-10-18 14:25:42

确保您已在 config/initializers/rierwave.rb 中启用 Carrierwave 处理。

它应该是:

config.enable_processing = true

Make sure you have enabled processing for Carrierwave in config/initializers/carrierwave.rb.

It should read:

config.enable_processing = true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文