public
Description: the blackbook gem on github.
Homepage:
Clone URL: git://github.com/purzelrakete/blackbook.git
jjolma (author)
Wed Dec 10 08:04:39 -0800 2008
purzelrakete (committer)
Tue Dec 16 16:29:49 -0800 2008
blackbook / test / freenet_importer_test.rb
100644 53 lines (43 sloc) 1.576 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/../test_helper.rb'
 
context "The Freenet importer" do
 
  setup do
    @username, @password = BlackbookExtensions::TestHelper::Credentials.new(:freenet).get
 
    @importer = Blackbook::Importer::Freenet.new
    @importer.create_agent
  end
 
  specify "should match emails" do
    @importer.=~(nil).should.not.be
    @importer.=~({}).should.not.be
    @importer.=~({ 'username' => "john@foo.com" }).should.not.be
    @importer.=~({ :username => "john@foo.com" }).should.not.be
    @importer.=~({ :username => "john" }).should.not.be
    @importer.=~({ :username => "john@freenet.de" }).should.be
    @importer.=~({ :username => "JOHN@FREENET.DE" }).should.be
  end
 
  specify "should be able to login with correct credentials" do
    should.not.raise Exception do
      login(@username, @password)
    end
  end
 
  specify "should raise BadCredentialsError on login with wrong credentials" do
    should.raise Blackbook::BadCredentialsError do
      login
    end
  end
 
  specify "should raise BadCredentialsError on login with correct username and wrong password" do
    should.raise Blackbook::BadCredentialsError do
      login(@username)
    end
  end
 
  specify "should able to get contacts" do
    login(@username, @password)
 
    contacts = @importer.scrape_contacts
    contacts.should.not.be.empty
    contacts.should.be.all { |contact| contact.is_a? Hash }
  end
 
  private
    def login(username = "foo", password = "bar")
      @importer.options = { :username => username, :password => password }
      @importer.login
    end
end