什么是撬做这允许这个rspec通过?

时间:2015-07-15 19:06:08

标签: ruby rspec pry

当我通过其测试套件运行此代码时,self.reset_all方法失败(应该如此)。当我在方法中插入binding.pry时,它告诉我数组为空并且测试通过。

require "pry"

class Owner
  attr_reader :species

  def initialize(species)
    @species = species
  end

  def self.all
    ObjectSpace.each_object(self)
  end

  def self.reset_all
    binding.pry
    self.all.to_a
  end

  def self.count
    all.count
  end
end

以下是测试:

describe Owner do
  let(:owner) { Owner.new("human") }

  describe 'Class methods' do
    it "keeps track of the owners that have been created" do
      expect(Owner.all).to include(owner)
    end

    it "can reset the owners that have been created" do
      Owner.reset_all
      expect(Owner.count).to eq(0)
    end

    it "can count how many owners have been created" do
      Owner.reset_all
      Owner.new("human")
      expect(Owner.count).to eq(1)
    end
  end 
end

我使用binding.pry进行绿色测试,但没有使用。

0 个答案:

没有答案