given I have the following with the internal assignments to filter and ldap:

class Collaborator
  def self.search_ldap(term)
    last_name = term.strip.split(/[, ]/).first.downcase
    filter = Net::LDAP::Filter.eq('surName', last_name)
    ldap = Net::LDAP.new( :host => 'foo', :port => 636, :base => 'bar',
:encryption => :fiz)
    ldap.search(:filter => filter)
  end
end

I would like mock out the LDAP class so i can test the behavior of the
method without LDAP.

describe Collaborator do
  it "should search ldap and return last names from the first item of the
search phrase" do
    entry = Net::LDAP::Entry
      items = {:cn=>["Jim Bob"],:uid=>['bob46'],:mail=>'b...@life.edu'}
      items.each{|k,v| entry.stub(k) {v} }

    # how do I get to objects inside this method, something like?
    assigns(:ldap).stub(:search).and_return(entry) # but that doesnt work
    Collaborator.search_ldap("Bob").should == [entry]
  end
end
-- 
Jed Schneider
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to