写道
it "should load classes only once" do
autoload_dir "#{spec_dir}/only_once"
check = mock
check.should_receive(:loaded).once
ClassLoader.add_observer do |klass|
klass.name.should == "OnlyOnceSpec"
check.loaded
end
OnlyOnceSpec
OnlyOnceSpec
end
autoload_dir "#{spec_dir}/only_once"
check = mock
check.should_receive(:loaded).once
ClassLoader.add_observer do |klass|
klass.name.should == "OnlyOnceSpec"
check.loaded
end
OnlyOnceSpec
OnlyOnceSpec
end
check.should_receive(:loaded).once
之前一直用mocha, 很少用rspec带的mock,这么一看语义也是非常清晰!