-1

问题在标题中。例如,我有一个类:

class A
  def self.something
    p 'Something'
  end

  def call_something
    self.class.something
  end
end

我想写一个测试,一个instance aonclass A方法调用:a.call_something实际上会调用A.something. 这可能吗?

4

1 回答 1

2

试试看怎么样?我想这行得通

describe '#call_something' do
  it 'calls something in classA' do
    a = ClassA.new
    ClassA.should_receive(:something)
    a.call_something
  end
end
于 2012-10-30T13:42:22.667 回答