Michael Irwin
Michael Irwin

Reputation: 3149

How to test this with RSpec?

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
      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.

Upvotes: 3

Views: 140

Answers (1)

Dogbert
Dogbert

Reputation: 222080

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

instance.should_receive(:to_pdf)

instance.process

Upvotes: 6

Related Questions