0

基本的に、method_1とmethod_2がプロセスメソッドから呼び出されることを確認したいと思います。

  def process
        begin
          method_1  if some_condition
          method_2  if some_condition      
          self.update_attribute(:status,DONE)
        rescue=>e
          self.update_attribute(:status,ERROR)
          p e
        end
    end

def method_1
#some code
end

def method_2
#some code
end
4

1 に答える 1

1

これを試して:

it "should call #method_1" do
  YourClass.should_receive(:method_1)
  YourClass.process
end

it "should call #method_2" do
  YourClass.should_receive(:method_2)
  YourClass.process
end

それらはクラスメソッドだと思います。

それらがインスタンスメソッドである場合は、次のことを実行できますYourClass.any_instance.should_receive(...)your_instance.should_receive(...)

詳細については、 http://rubydoc.info/gems/rspec-mocks/framesを参照してください。

編集:

should_receiveまた、メソッドをスタブします。これにより、スタブがキャンセルされ、メソッドが呼び出されます。

YourClass.should_receive(:method_2).and_call_original
于 2013-03-14T13:54:41.070 に答える