vendredi 29 avril 2016

Stub a function which is inside the function to be tested

I have a function let's say A whose output and functionality I have to test, A calls another function B which takes a lot of time to compute the output. So I am trying to use stubs to mimic all the values that B returns.

def A
  #do something
  output = B
  #do something with output
end

Now the test files

describe "check what A returns" do
   ClassName.stub(:B) do
     [0, 1]
   end
   test_values  = TestClass.A(input parameters)
   #checks on test values
end

My aim is to pass the expected output of B to function A. I am using RSpec. How do I go about it?

Aucun commentaire:

Enregistrer un commentaire