You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In addition to verify_partial_doubles the above option may come handy to verify that you are stubbing an existing constant.
# When this is set to true, an error will be raised when
# `instance_double` or `class_double` is given the name of an undefined
# constant. You probably only want to set this when running your entire
# test suite, with all production code loaded. Setting this for an
# isolated unit test will prevent you from being able to isolate it!
Example
With this option set to false the following example will, surprisingly, pass:
describeUserGreeterdoit'picks user name and prints greeting'douser=instance_double('Usor')# notice a typoallow(user).toreceive(:name).and_return('John')expect{subject.process(user)}.tooutput('Hello, John')end
When User renames its name method to full_name, this spec will still pass, but UserGreeter will blow up in production with NoMethodError.
Real-life Examples
Example violations (resulting with errors when the option is set to true):
# Typo: notice the leading spacelet(:api){instance_double(' ThirdParty::API')}# `instance_double` expects a class namelet(:charge){instance_double('payment',id: 1)}# "payment" is not a defined constant. Perhaps you misspelt it?# Does not exist outside of the test codelet(:action){instance_double('Action')}# "Action" is not a defined constant (though "Namespace::Action" is)# Not loadedlet(:settings){class_double('Settings')}# "Settings" is not a defined constant# Double stubbingbeforedostub_const('ActionClass',Class.new)endlet(:action){instance_double(ActionClass)}"ActionClass"is not adefinedconstant
The text was updated successfully, but these errors were encountered:
In addition to
verify_partial_doubles
the above option may come handy to verify that you are stubbing an existing constant.Example
With this option set to
false
the following example will, surprisingly, pass:When
User
renames itsname
method tofull_name
, this spec will still pass, butUserGreeter
will blow up in production withNoMethodError
.Real-life Examples
Example violations (resulting with errors when the option is set to
true
):The text was updated successfully, but these errors were encountered: