Mocha + Rspec:我如何测试一个块?

时间:2015-01-12 15:56:47

标签: rspec mocha

我有一个使用块的方法。我试图测试它,但它失败了。我不确定如何设置它。有人可以帮忙吗?

方法:

def generate_text_response_image
  file = Tempfile.new(["temp_twitter_image_#{self.id}", ".jpg"])
  MiniMagick::Tool::Convert.new do |convert|
    convert << "("
    convert.size "1024x512"
    convert << "public/text_response_bg.png"
    convert << ")"
    convert << "("
    convert.size "700x256"
    convert.background "none"
    convert.fill 'white'
    convert << "caption:#{message}"
    convert << ")"
    convert.gravity "center"
    convert.compose "Over"
    convert.composite file.path
  end
  self.image = file
  self.save!
  file.unlink
end

失败的摩卡测试:

  it 'generates an image with the message as the caption' do
    convert = stub(:convert)
    MiniMagick::Tool::Convert.expects(:new).yields(convert)
    convert.should_receive(:<<).with("(")
    subject.send(:post) # this will call the generate_text_response_image private method
  end

0 个答案:

没有答案