Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 搬运工必须与不在rspec工作的助手完全相同_Ruby_Ruby On Rails 3_Rspec_Carrierwave_Rspec Rails - Fatal编程技术网

Ruby 搬运工必须与不在rspec工作的助手完全相同

Ruby 搬运工必须与不在rspec工作的助手完全相同,ruby,ruby-on-rails-3,rspec,carrierwave,rspec-rails,Ruby,Ruby On Rails 3,Rspec,Carrierwave,Rspec Rails,我尝试在Carrierwave上传上运行rspec测试时遇到一些问题。基本上,我正在尝试测试处理,以确保是否上传和处理了图像。我创建了一个后处理的示例文件,该文件应该与上传和处理后的测试文件相同。然而,我得到以下警告: image\u uploader.rb require File.dirname(__FILE__) + '/../spec_helper' require 'carrierwave/test/matchers' describe ImageUploader do in

我尝试在Carrierwave上传上运行rspec测试时遇到一些问题。基本上,我正在尝试测试处理,以确保是否上传和处理了图像。我创建了一个后处理的示例文件,该文件应该与上传和处理后的测试文件相同。然而,我得到以下警告:



image\u uploader.rb

require File.dirname(__FILE__) + '/../spec_helper'
require 'carrierwave/test/matchers'

describe ImageUploader do
  include CarrierWave::Test::Matchers
  include ActionDispatch::TestProcess

  before do
    ImageUploader.enable_processing = true
    @uploader_attr = fixture_file_upload('/test_images/testimage.jpg',    'image/jpeg')
    @uploader = ImageUploader.new(@uploader_attr)
    @uploader.store!
    @pregreyed_image =             fixture_file_upload('/test_images/testimage_GREY.jpg', 'image/jpeg')
  end

  after do
    @uploader.remove!
    ImageUploader.enable_processing = false
  end

  context 'the greyscale version' do
    it "should remove color from the image and make it greyscale" do

      @uploader.should be_identical_to(@pregreyed_image)
    end
  end
  end
class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  # Choose what kind of storage to use for this uploader:
  storage :file


  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end


  # Process files as they are uploaded:
   process :convert_to_grayscale

  def convert_to_grayscale
    manipulate! do |img|
      img.colorspace = Magick::GRAYColorspace
      img.quantize(256, Magick::GRAYColorspace)
      img = yield(img) if block_given?
      img
    end
  end
class ImageUploader
封面下方的
相同\u在两个参数上使用
FileUtils.idential?
。所以你的期望是:

@uploader.应该与(@pregreyed\u image)相同
他实际上是在打电话:

FileUtils.identical?(@uploader,@pregreyed\u image)
因为在我的测试环境中,我使用的是文件存储系统,所以我通过传入
#current_path
而不是像这样的上载程序本身来解决这个问题:

@uploader.current_path.should be_identical_to(@pregreyed_image)
实际上,我最终需要直接比较上传程序,并在我的上传程序上实现
=

classmyuploader
@uploader.current_path.should be_identical_to(@pregreyed_image)