ruby - Rspec Class any_instance expects method_name - where it is documented? -
ruby - Rspec Class any_instance expects method_name - where it is documented? -
i've stumbled upon next piece of code in rspec test , must more or less figured out can't find relevant sources prove it. please point me gem or docs describe:
describe somemodule::salesforce::lead before somemodule::salesforce::lead.any_instance.expects(:materialize) end ... end
it seems :each illustration in spec sets expectation on instance of class described above receive phone call :materialize method and redefines method do nothing . lastly part seems crucial because avoids connecting salesforce in test environment can't find confirmation this.
any_instance
documented under working legacy code
you right in both sets expectation , stubs out original method on given instance of class.
previous versions of rspec accomplish monkeypatch ruby core classes (object
, baseobject
)
rspec 3 has new syntax not rely on monkeypatching:
before expect_any_instance_of(somemodule::salesforce).to receive(:materialize) end
ruby rspec mocking
Comments
Post a Comment