优秀测试代码收集

写道
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

 

check.should_receive(:loaded).once

 

之前一直用mocha, 很少用rspec带的mock,这么一看语义也是非常清晰!

 

 

你可能感兴趣的:(rspec)