githubris 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,26 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Githubris::Builder do
4
4
  let(:gist_collection_data) { Githubris::SpecHelper.gist_collection_data }
5
- let(:gist_data) { Githubris::SpecHelper.gist_data }
6
-
7
- describe '#build' do
8
-
9
- context 'when passed a collection of gist data' do
10
- it 'delegates to #build_gists' do
11
- Githubris::Builder.any_instance.stub(:build_gists)
12
- subject.build gist_collection_data
13
- subject.should have_received(:build_gists).with gist_collection_data
14
- end
15
- end
16
-
17
- context 'when passed the data for a single gist' do
18
- it 'delegates to #build_gist' do
19
- Githubris::Builder.any_instance.stub(:build_gist)
20
- subject.build gist_data
21
- subject.should have_received(:build_gist).with gist_data
22
- end
23
- end
24
- end
25
5
 
26
6
  describe '#build_gists' do
27
7
  it 'is an array of gists' do
@@ -33,38 +13,16 @@ describe Githubris::Builder do
33
13
  end
34
14
  end
35
15
 
36
-
37
- describe '#build_gist' do
16
+ describe '#build_users' do
17
+ let(:user_data) { Githubris::SpecHelper.user_data }
38
18
  context 'schema' do
39
- subject { Githubris::Builder.new.build gist_data }
19
+ subject { Githubris::Builder.new.build_user user_data }
40
20
 
41
- it { should be_instance_of Githubris::Gist }
42
- it { should be_public }
43
- its(:user) { should be_instance_of Githubris::User }
44
- its(:description) { should be_instance_of String }
45
- its(:created_at) { should be_instance_of DateTime }
46
- its(:updated_at) { should be_instance_of DateTime }
47
- its(:comments) { should be_instance_of Array }
48
- its(:files) { should be_instance_of Array }
49
- its(:url) { should be_kind_of URI }
50
- end
51
-
52
- context 'when passed a specific gist' do
53
- subject { Githubris::Builder.new.build gist_data }
54
-
55
- it 'is public' do
56
- subject.should be_public
57
- end
58
-
59
- its(:description) { should eql 'the meaning of gist' }
60
-
61
- it 'was created at 6:17:13 on July 15, 2008' do
62
- subject.created_at.should eql DateTime.new(2008, 7, 15, 18, 17, 13)
63
- end
64
-
65
- it 'was updated at 2:58:22 on Feburary 22, 2011' do
66
- subject.updated_at.should eql DateTime.new(2011, 2, 22, 2, 58, 22)
67
- end
21
+ its(:login) { should be_instance_of String }
22
+ its(:id) { should be_instance_of Fixnum }
23
+ its(:avatar_url) { should be_kind_of URI }
24
+ its(:url) { should be_kind_of URI }
25
+ its(:gravatar_id) { should be_instance_of String }
68
26
  end
69
27
  end
70
28
  end
@@ -2,32 +2,79 @@ require 'spec_helper'
2
2
 
3
3
  describe Githubris::Gist do
4
4
 
5
- context 'instance methods' do
6
- subject { gist }
7
- let(:gist) { Githubris::Gist.new }
5
+ describe '#==' do
6
+ let(:this) { Githubris::Gist.new }
7
+ subject { this == other }
8
8
 
9
- it 'new gists are created now' do
10
- DateTime.stub(:now => DateTime.new(2012, 12, 21, 12, 0, 0))
11
- gist.created_at.should eql DateTime.now
12
- end
9
+ context 'the other\'s class is Githubris::Gist' do
10
+ let(:other) { Githubris::Gist.new }
11
+
12
+ context 'the gists have the same creation times' do
13
+ before { Githubris::Gist.any_instance.stub(created_at: stub) }
14
+
15
+ context 'the files are the same' do
16
+ before { Githubris::Gist.any_instance.stub(files: stub) }
17
+
18
+ context 'the user is the same' do
19
+ before { Githubris::Gist.any_instance.stub(user: stub) }
20
+
21
+ it { should be_true }
22
+
23
+ end
24
+
25
+ context 'the user isn\'t the same' do
26
+ let(:this) { Githubris::Gist.new(user: :the_right_user) }
27
+ let(:other) { Githubris::Gist.new(user: :not_the_right_user) }
28
+
29
+ it { should be_false }
30
+ end
31
+
32
+ it { should be_true }
33
+ end
34
+
35
+ context 'the files are\'t the same' do
36
+ let(:other) { Githubris::Gist.new(files: stub) }
37
+
38
+ it { should be_false }
39
+ end
40
+ end
13
41
 
14
- context 'Gist owned by Isaac' do
15
- subject { Githubris::Gist.new user: user }
16
- let(:user) { Githubris::User.new }
17
- its(:user) { should eql user }
42
+ context 'the gists were created at different times' do
43
+ let(:this) { Githubris::Gist.new(created_at: DateTime.new(2012))}
44
+ let(:other) { Githubris::Gist.new(created_at: DateTime.new(1990)) }
45
+
46
+ it { should be_false }
47
+ end
18
48
  end
19
49
 
50
+ context 'the other\'s class is not Githubris::Gist' do
51
+ let(:other) { stub }
20
52
 
21
- describe 'a gist without files' do
22
- its(:files) { should be_empty }
53
+ it { should be_false }
23
54
  end
55
+ end
24
56
 
25
- describe 'a gist created with a file' do
26
- subject do
27
- Githubris::Gist.new(files: [stub])
28
- end
57
+ it 'new gists are created now' do
58
+ DateTime.stub(now: DateTime.new(2012))
59
+ subject.created_at.should eql DateTime.now
60
+ end
29
61
 
30
- its(:files) { should have(1).items }
62
+ context 'Gist owned by Isaac' do
63
+ subject { Githubris::Gist.new user: user }
64
+ let(:user) { Githubris::User.new }
65
+ its(:user) { should eql user }
66
+ end
67
+
68
+
69
+ describe 'a gist without files' do
70
+ its(:files) { should be_empty }
71
+ end
72
+
73
+ describe 'a gist created with a file' do
74
+ subject do
75
+ Githubris::Gist.new(files: [stub])
31
76
  end
77
+
78
+ its(:files) { should have(1).items }
32
79
  end
33
80
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Githubris::User do
4
+ it 'is initialized with an attributes hash' do
5
+ attributes = {foo: 'bar'}
6
+ lambda { Githubris::User.new attributes }.should_not raise_error
7
+ end
8
+
9
+ describe '#public_gists' do
10
+ it 'hits the API' do
11
+ Githubris::API.any_instance.should_receive(:get_user_public_gists)
12
+ user = Githubris::User.new
13
+ user.public_gists
14
+ end
15
+ end
16
+
17
+ describe '#==' do
18
+ it 'matches based on attributes' do
19
+ user1 = Githubris::User.new({foo: 'bar'})
20
+ user2 = Githubris::User.new({foo: 'bar'})
21
+ user1.should == user2
22
+ end
23
+ end
24
+ end
@@ -4,3 +4,7 @@ FakeWeb.allow_net_connect = false
4
4
  FakeWeb.register_uri(:get, 'https://api.github.com/', :body => '{}')
5
5
  FakeWeb.register_uri(:get, /gists\/public(?:[^?]*\?page=(\d+))?/,
6
6
  :body => File.open("spec/support/public_gists_page_#{$1 || 1}.json", 'r') {|f| f.read })
7
+ FakeWeb.register_uri(:get, /users\/([^\/]*)\/gists\z/,
8
+ :body => File.open("spec/support/user_public_gists.json"){|f| f.read })
9
+ FakeWeb.register_uri(:get, /users\/\w+\z/,
10
+ :body => File.open("spec/support/user.json"){|f| f.read })