[rspec-users] Stub a class and instances
Marcelo de Moraes Serpa
celoserpa at gmail.com
Mon Apr 5 00:21:25 EDT 2010
For example, I have this scenario where a Directory model will only save if
it can connect to the LDAP server. In a test I'm writting, though,
connecting to the LDAP server is not relevant, so I tried doing this:
context "LDAP is on" do
@account.directory = Directory.make :ldap_on
However, the Directory.make fails (since the before_save ldap test fails,
because authenticate_user can't connect to the LDAP server). The issue is
that it stubs the method as a singleton method of Directory.
One alternative is opening the Directory class and redefining the
authenticate_user method, but I'd like to know if rSpec supports somehow
stubing a class and let it stub instance too.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users