File: profile_spec.rb

package info (click to toggle)
tdiary-contrib 5.0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,660 kB
  • sloc: ruby: 17,024; lisp: 546; xml: 451; php: 61; sql: 40; makefile: 18
file content (62 lines) | stat: -rw-r--r-- 1,968 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-

require 'spec_helper'
require 'profile'

describe "Profile::Service" do
  describe "GitHub" do
    before do
      require 'json'
      allow_any_instance_of(Profile::Service::GitHub).to receive(:fetch).and_return(JSON.parse(File.read("spec/fixtures/github.json")))

      # workaround for run spec on various environment.
      require 'openssl'
      OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

      # http://develop.github.com/p/general.html
      @profile = Profile::Service::GitHub.new("schacon")
    end

    it "should include name, mail, image properties" do
      expect(@profile.name).to eq("Scott Chacon")
      expect(@profile.mail).to eq("schacon@gmail.com")
      expect(@profile.image).to eq("https://avatars.githubusercontent.com/u/70?v=3")
    end
  end

  describe "Gravatar" do
    # http://ja.gravatar.com/site/implement/hash/

    before do
      require 'json'
      allow_any_instance_of(Profile::Service::Gravatar).to receive(:fetch).and_return(JSON.parse(File.read("spec/fixtures/gravatar.json")))

      @profile = Profile::Service::Gravatar.new("iHaveAn@email.com")
    end
    it "should include name, mail, image properties" do
      expect(@profile.name).to eq("tDiary")
      expect(@profile.mail).to eq("iHaveAn@email.com")
      expect(@profile.image).to eq("http://2.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802")
    end

    context 'with options' do
      before do
        @profile = Profile::Service::Gravatar.new("iHaveAn@email.com", :size => 40)
      end

      it "should specify size option" do
        expect(@profile.image).to eq("http://2.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802?s=40")
      end
    end
  end

  describe "Hatena" do
    before do
      @profile = Profile::Service::Hatena.new("kmachu")
    end

    it "should include image property" do
      expect(@profile.image).to eq("http://www.hatena.ne.jp/users/km/kmachu/profile.gif")
    end
  end
end