jeudi 25 août 2016

Actual method being called instead of stub'd version

I am running a Chef spec unit test using the command below. The relevant code is shown further below. I expected some_test_data to be used in the unit test instead of method_name actually getting called. But what is happening is that the stub is not used. Instead method_name does actually get called, which in this case is not appropriate in the unit test. What am I mis-understanding or doing wrong here? Thank you.

rspec spec/unit/mytest_spec.rb

# Code from Chef Spec mytest_spec.rb unit test
allow(ClassName).to receive(:method_name).and_return(some_test_data)

# Code unit test is testing
my_variable = method_name(node)

# Method that gets called above
def self.method_name(node)
  # Do something
end

Aucun commentaire:

Enregistrer un commentaire