Rails / RSpec: How to test #initialize method?
问题 How can I specify #initialize behaviour with RSpec? For example here: generator.rb class Generator attr_accessor :seed def initialize(seed = nil) @seed = seed || pick_seed end def pick_seed Time.now.to_i end end generator_spec.rb require 'generator' describe Generator it "calls 'pick_seed' method unless seed specified" do end end I'd like to set expectation that pick_seed method called from #initialize method. 回答1: For me, expectations are about designing conversations among collaborators. So