dimanche 7 octobre 2018

Rspec: Getting error while testing private method

Getting error while testing a private method. Please suggest how to test private method is called from a public method.

Public

def public_method
    private_method
end

Private

  def private_method
    tries = 0
    begin
      raise Product::StaleObjectError.new("Product is changed while you were editing") if stale_object?
      // Do some work
      raise Exception.new("Total amount used is greater than approved") if total_approved < 0

      // Save Product
    rescue Product::StaleObjectError => e
      if tries < MAX_RETRIES
        tries += 1
        sleep(1 + tries)
        reload
        retry
      else
        raise Product::StaleObjectError("Product is changed while you were editing")
      end
    end
    attributes
  end

Test Case:

  before(:each) do
    @prod_v1 = Product.new
  end
  it 'test private method called' do
    expect_any_instance_of {Product}.to receive(:private_method)
    @prod_v1.public_method
  end

I am getting following error for test case

  Failure/Error: expect_any_instance_of {Prod}.to receive(:)
     ArgumentError:
       wrong number of arguments (0 for 1)

Aucun commentaire:

Enregistrer un commentaire