Ruby 无法调用实例\u double两次

Ruby 无法调用实例\u double两次,ruby,rspec,mocking,Ruby,Rspec,Mocking,我正在编写一个测试fot rspec,以检查是否将项添加到我像数组一样使用的类中 describe '#collection' do let(:process) { instance_double("WebServerProcess", :cpu => 33, :mem => 22, :pid => 1, :port => 8000) } it 'return the collection'

我正在编写一个测试fot rspec,以检查是否将项添加到我像数组一样使用的类中

    describe '#collection' do
        let(:process) {
            instance_double("WebServerProcess", :cpu => 33, :mem => 22, :pid => 1, :port => 8000)
        }
        it 'return the collection' do
            WebServersCollection.add process
            expect(subject.collection).to eq([process])
        end
        it 'should add with <<' do
            WebServersCollection << process
            expect(subject.collection).to eq([process])
        end
    end
description'#collection'做什么
let(:进程){
实例_double(“WebServerProcess”,:cpu=>33,:mem=>22,:pid=>1,:端口=>8000)
}
它“返回集合”吗
WebServersCollection.add进程
expect(subject.collection).to eq([进程])
结束

它应该加上我认为这个错误告诉了你你需要知道的一切

你不能那样做,而且

您需要在每个希望使用它的示例中创建一个新的示例