How to mock the data from a helper method call while performing an Rspec test on a main method?

598 views Asked by At

I'm trying to get the data suppose an array [1,2,3,4] from a method say helper, that is called by a main ruby method called basic, which is supposed to use that array that is being returned. How do i specify or hard code that array while writing tests for basic method?

1

There are 1 answers

1
PruthviRaj Reddy On

mock your dependency or message call

allow(self).to receive(:helper).with(params) or use (with_any) .and_return([1,2,3,4]). 

Find more for rspec2 @ https://relishapp.com/rspec/rspec-mocks/v/2-99/docs/method-stubs/allow-with-a-simple-return-value