开发者

How to test this with RSpec?

开发者 https://www.devze.com 2023-03-21 22:24 出处:网络
Using RSpec, I want to test that certain methods are called within a method. Take the following example class:

Using RSpec, I want to test that certain methods are called within a method. Take the following example class:

class Upload < ActiveRecord::Base
    def process
      case self.file_name
     开发者_如何学C when /\.html$/
        to_pdf
      end
    end
end

How would I test that to_pdf is called when process is called on an Upload instance with file_name = 'foo.html'? I'd like to do this using a test double if possible.


instance = Upload.new
instance.file_name = "foo.html"

instance.should_receive(:to_pdf)

instance.process
0

精彩评论

暂无评论...
验证码 换一张
取 消