githubris 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -0
- data/Rakefile +7 -0
- data/features/get_a_user.feature +8 -0
- data/features/list_of_public_gists.feature +4 -4
- data/features/list_of_users_public_gists.feature +2 -3
- data/features/step_definitions/general_steps.rb +5 -6
- data/features/support/env.rb +1 -1
- data/features/support/fakeweb_responses.rb +5 -1
- data/features/support/fixtures.rb +26 -2
- data/lib/githubris/api/gist.rb +31 -0
- data/lib/githubris/api/user.rb +15 -0
- data/lib/githubris/api.rb +7 -29
- data/lib/githubris/builder/gist.rb +16 -0
- data/lib/githubris/builder/user.rb +15 -0
- data/lib/githubris/builder.rb +10 -30
- data/lib/githubris/gist.rb +54 -43
- data/lib/githubris/user.rb +32 -6
- data/lib/githubris/version.rb +1 -1
- data/lib/githubris.rb +3 -3
- data/spec/githubris/api/gist_spec.rb +66 -0
- data/spec/githubris/api/user_spec.rb +18 -0
- data/spec/githubris/api_spec.rb +0 -24
- data/spec/githubris/builder/gist_spec.rb +38 -0
- data/spec/githubris/builder_spec.rb +8 -50
- data/spec/githubris/gist_spec.rb +65 -18
- data/spec/githubris/user_spec.rb +24 -0
- data/spec/support/fakeweb_responses.rb +4 -0
- data/spec/support/fixtures.rb +17 -630
- data/spec/support/user.json +14 -0
- data/spec/support/user_public_gists.json +65 -0
- metadata +15 -7
- data/features/step_definitions/public_gist_steps.rb +0 -0
- data/features/support/public_gists_page_1.json +0 -884
- data/features/support/public_gists_page_2.json +0 -898
@@ -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
|
-
|
16
|
+
describe '#build_users' do
|
17
|
+
let(:user_data) { Githubris::SpecHelper.user_data }
|
38
18
|
context 'schema' do
|
39
|
-
subject { Githubris::Builder.new.
|
19
|
+
subject { Githubris::Builder.new.build_user user_data }
|
40
20
|
|
41
|
-
|
42
|
-
|
43
|
-
its(:
|
44
|
-
its(:
|
45
|
-
its(:
|
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
|
data/spec/githubris/gist_spec.rb
CHANGED
@@ -2,32 +2,79 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Githubris::Gist do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe '#==' do
|
6
|
+
let(:this) { Githubris::Gist.new }
|
7
|
+
subject { this == other }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
-
its(:files) { should be_empty }
|
53
|
+
it { should be_false }
|
23
54
|
end
|
55
|
+
end
|
24
56
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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 })
|