vanity-source 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+
3
+ test Vanity::Source::GithubIssues do
4
+ context "setup" do
5
+ setup { setup_source "repo"=>"assaf/vanity" }
6
+
7
+ should "use repository name" do
8
+ assert_equal "Github Issues for assaf/vanity", metric.name
9
+ end
10
+
11
+ should "measure totals" do
12
+ assert metric.totals
13
+ end
14
+
15
+ should "capture open issues" do
16
+ assert metric.columns.include?(:id=>"open", :label=>"Open issues")
17
+ end
18
+
19
+ should "capture closed issues" do
20
+ assert metric.columns.include?(:id=>"closed", :label=>"Closed issues")
21
+ end
22
+ end
23
+
24
+
25
+ context "validation" do
26
+ should "raise error if repository name missing" do
27
+ assert_raise(RuntimeError) { setup_source "repo"=>" " }
28
+ end
29
+
30
+ should "raise error if repository name not user/repo" do
31
+ assert_raise(RuntimeError) { setup_source "repo"=>"vanity" }
32
+ end
33
+
34
+ should "allow alphanumeric, minus and underscore" do
35
+ setup_source "repo"=>"assaf/the-vanity_0"
36
+ assert_valid metric
37
+ end
38
+
39
+ should "create valid metric" do
40
+ setup_source "repo"=>"assaf/vanity"
41
+ assert_valid metric
42
+ end
43
+ end
44
+
45
+
46
+ context "update" do
47
+ setup { setup_source "repo"=>"assaf/vanity" }
48
+
49
+ should "handle 404" do
50
+ stub_request(:get, interactions.first.uri).to_return :status=>404
51
+ stub_request(:get, interactions.second.uri).to_return :status=>404
52
+ assert_raise(RuntimeError) { update_source }
53
+ assert_equal "Could not find the repository assaf/vanity", last_error
54
+ end
55
+
56
+ should "handle 401" do
57
+ stub_request(:get, interactions.first.uri).to_return :status=>401
58
+ stub_request(:get, interactions.second.uri).to_return :status=>401
59
+ assert_raise(RuntimeError) { update_source }
60
+ assert_equal "You are not authorized to access this repository, or invalid username/password", last_error
61
+ end
62
+
63
+ should "handle other error" do
64
+ stub_request(:get, interactions.first.uri).to_return :status=>500
65
+ stub_request(:get, interactions.second.uri).to_return :status=>500
66
+ assert_raise(RuntimeError) { update_source }
67
+ assert_equal "Last request didn't go as expected, trying again later", last_error
68
+ end
69
+
70
+ should "handle invlid document entity" do
71
+ stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
72
+ stub_request(:get, interactions.last.uri).to_return :body=>"Not JSON"
73
+ assert_raise(RuntimeError) { update_source }
74
+ assert_equal "Last request didn't go as expected, trying again later", last_error
75
+ end
76
+
77
+ should "capture number of open issues" do
78
+ update_source
79
+ assert_equal 9, totals[:open]
80
+ end
81
+
82
+ should "capture number of closed issues" do
83
+ update_source
84
+ assert_equal 12, totals[:closed]
85
+ end
86
+
87
+ should "not create any activity" do
88
+ update_source
89
+ assert activities.empty?
90
+ end
91
+
92
+ context "repeating" do
93
+ setup do
94
+ update_source
95
+ open = interactions.select { |i| i.uri =~ /open/ }
96
+ stub_request(:get, open.first.uri).to_return :body=>open.last.response.body
97
+ closed = interactions.select { |i| i.uri =~ /closed/ }
98
+ stub_request(:get, closed.first.uri).to_return :body=>closed.last.response.body
99
+ update_source
100
+ end
101
+
102
+ should "update open count" do
103
+ assert_equal 2, totals[:open]
104
+ end
105
+
106
+ should "update closed count" do
107
+ assert_equal 2, totals[:closed]
108
+ end
109
+
110
+ should "create activity for each issue opened or closed" do
111
+ assert_equal 2, activities.count
112
+ end
113
+
114
+ context "activity for open issue" do
115
+ setup do
116
+ @open = activities.first
117
+ end
118
+
119
+ should "capture issue URL" do
120
+ assert_equal "http://github.com/assaf/vanity/issues#issue/22", @open.url
121
+ end
122
+
123
+ should "use SHA1 for ID" do
124
+ assert_match /^[0-9a-f]{40}$/, @open.id
125
+ end
126
+
127
+ should "capture issue creation time" do
128
+ assert_equal Time.parse("2010/03/17 22:32:02 UTC"), @open.timestamp
129
+ end
130
+ end
131
+
132
+ context "activity for closed issue" do
133
+ setup do
134
+ @closed = activities.last
135
+ end
136
+
137
+ should "capture issue URL" do
138
+ assert_equal "http://github.com/assaf/vanity/issues#issue/19", @closed.url
139
+ end
140
+
141
+ should "use SHA1 for ID" do
142
+ assert_match /^[0-9a-f]{40}$/, @closed.id
143
+ end
144
+
145
+ should "capture issue closing time" do
146
+ assert_equal Time.parse("2010/07/03 04:16:42 UTC"), @closed.timestamp
147
+ end
148
+ end
149
+
150
+ end
151
+ end
152
+
153
+
154
+ context "meta" do
155
+ setup { setup_source "repo"=>"assaf/vanity" }
156
+
157
+ should "link to repository" do
158
+ assert_contains meta, :title=>"On Github", :url=>"http://github.com/assaf/vanity/issues"
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,188 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+
3
+ test Vanity::Source::Github do
4
+ context "setup" do
5
+ setup { setup_source "repo"=>"assaf/vanity", "branch"=>"master" }
6
+
7
+ should "use repository name" do
8
+ assert_equal "Github: assaf/vanity", metric.name
9
+ end
10
+
11
+ should "measure totals" do
12
+ assert metric.totals
13
+ end
14
+
15
+ should "capture commits" do
16
+ assert metric.columns.include?(:id=>"commits", :label=>"Commits")
17
+ end
18
+
19
+ should "capture watchers" do
20
+ assert metric.columns.include?(:id=>"watchers", :label=>"Watchers")
21
+ end
22
+
23
+ should "capture forks" do
24
+ assert metric.columns.include?(:id=>"forks", :label=>"Forks")
25
+ end
26
+
27
+ should "default branch to master" do
28
+ setup_source "repo"=>"assaf/vanity", "branch"=>" "
29
+ assert_equal "master", context["branch"]
30
+ end
31
+ end
32
+
33
+
34
+ context "validation" do
35
+ should "raise error if repository name missing" do
36
+ assert_raise(RuntimeError) { setup_source "repo"=>" ", "branch"=>"master" }
37
+ end
38
+
39
+ should "raise error if repository name not user/repo" do
40
+ assert_raise(RuntimeError) { setup_source "repo"=>"vanity", "branch"=>"master" }
41
+ end
42
+
43
+ should "allow alphanumeric, minus and underscore" do
44
+ setup_source "repo"=>"assaf/the-vanity_0", "branch"=>"master"
45
+ assert_valid metric
46
+ end
47
+
48
+ should "create valid metric" do
49
+ setup_source "repo"=>"assaf/vanity", "branch"=>"master"
50
+ assert_valid metric
51
+ end
52
+ end
53
+
54
+
55
+ context "update" do
56
+ setup { setup_source "repo"=>"assaf/vanity", "branch"=>"master" }
57
+
58
+ should "handle 404" do
59
+ stub_request(:get, interactions.first.uri).to_return :status=>404
60
+ assert_raise(RuntimeError) { update_source }
61
+ assert_equal "Could not find the repository assaf/vanity", last_error
62
+ end
63
+
64
+ should "handle 401" do
65
+ stub_request(:get, interactions.first.uri).to_return :status=>401
66
+ assert_raise(RuntimeError) { update_source }
67
+ assert_equal "You are not authorized to access this repository, or invalid username/password", last_error
68
+ end
69
+
70
+ should "handle other error" do
71
+ stub_request(:get, interactions.first.uri).to_return :status=>500
72
+ assert_raise(RuntimeError) { update_source }
73
+ assert_equal "Last request didn't go as expected, trying again later", last_error
74
+ end
75
+
76
+ should "handle invlid document entity" do
77
+ stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
78
+ assert_raise(RuntimeError) { update_source }
79
+ assert_equal "Last request didn't go as expected, trying again later", last_error
80
+ end
81
+
82
+ should "capture number of commits" do
83
+ update_source
84
+ assert_equal 35, totals[:commits]
85
+ end
86
+
87
+ should "capture number of wacthers" do
88
+ update_source
89
+ assert_equal 534, totals[:watchers]
90
+ end
91
+
92
+ should "capture number of forks" do
93
+ update_source
94
+ assert_equal 36, totals[:forks]
95
+ end
96
+
97
+ should "not create any activity" do
98
+ update_source
99
+ assert activities.empty?
100
+ end
101
+
102
+ context "repeating" do
103
+ setup do
104
+ update_source
105
+ repo = interactions.select { |i| i.uri =~ /repos\/show/ }
106
+ stub_request(:get, repo.first.uri).to_return :body=>repo.last.response.body
107
+ commits = interactions.select { |i| i.uri =~ /commits\/list/ }
108
+ stub_request(:get, commits.first.uri).to_return :body=>commits.last.response.body
109
+ update_source
110
+ end
111
+
112
+ should "update watchers" do
113
+ assert_equal 555, totals[:watchers]
114
+ end
115
+
116
+ should "update forks" do
117
+ assert_equal 38, totals[:forks]
118
+ end
119
+
120
+ should "capture new number of commits" do
121
+ assert_equal 37, totals[:commits]
122
+ end
123
+
124
+ should "create activity for each commit" do
125
+ assert_equal 2, activities.count
126
+ end
127
+
128
+ should "create most recent activity for most recent commit" do
129
+ assert_equal ["The second commit", "The third commit"], activities.map(&:body)
130
+ end
131
+
132
+ context "activity" do
133
+
134
+ should "capture commit URL" do
135
+ assert_equal "http://github.com/assaf/vanity/commit/dd154a9fdd2ac534b62b55b8acac2fd092d65439", activity.url
136
+ end
137
+
138
+ should "capture commit SHA" do
139
+ assert_equal "dd154a9fdd2ac534b62b55b8acac2fd092d65439", activity.id
140
+ end
141
+
142
+ should "capture timestamp" do
143
+ assert_equal Time.parse("2010-08-06T00:22:01-07:00 UTC"), activity.timestamp
144
+ end
145
+
146
+ should "capture commit message" do
147
+ assert_equal "The third commit", activity.body
148
+ end
149
+
150
+ should "capture commit author name" do
151
+ assert_equal "Assaf Arkin", activity.person.name
152
+ end
153
+
154
+ should "capture commit author email" do
155
+ assert_equal "assaf@labnotes.org", activity.person.email
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+ end
162
+
163
+
164
+ context "meta" do
165
+ setup { setup_source "repo"=>"assaf/vanity", "branch"=>"master" }
166
+
167
+ should "link to repository" do
168
+ assert_contains meta, :title=>"Repository", :text=>"assaf/vanity", :url=>"http://github.com/assaf/vanity"
169
+ end
170
+
171
+ should "include project description" do
172
+ assert_contains meta, :text=>"Experiment Driven Development for Ruby"
173
+ end
174
+
175
+ should "link to project home page" do
176
+ assert_contains meta, :title=>"Home page", :url=>"http://vanity.labnotes.org"
177
+ end
178
+
179
+ should "list branch name" do
180
+ assert_contains meta, :title=>"Branch", :text=>"master"
181
+ end
182
+
183
+ should "show last commit message" do
184
+ assert_contains meta, :title=>"Commit", :text=>"Gemfile changes necessary to pass test suite.",
185
+ :url=>"http://github.com/assaf/vanity/commit/dd154a9fdd2ac534b62b55b8acac2fd092d6543a"
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,130 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+
3
+ test Vanity::Source::RubyGems do
4
+ context "setup" do
5
+ setup { setup_source "gem_name"=>"vanity" }
6
+
7
+ should "use gem name" do
8
+ assert_equal "RubyGems: vanity", metric.name
9
+ end
10
+
11
+ should "measure totals" do
12
+ assert metric.totals
13
+ end
14
+
15
+ should "capture downloads" do
16
+ assert metric.columns.include?(:id=>"downloads", :label=>"Downloads")
17
+ end
18
+ end
19
+
20
+
21
+ context "validation" do
22
+ should "raise error if gem name missing" do
23
+ assert_raise(RuntimeError) { setup_source "gem_name"=>" " }
24
+ end
25
+
26
+ should "create valid metric" do
27
+ setup_source "gem_name"=>"vanity"
28
+ assert_valid metric
29
+ end
30
+ end
31
+
32
+
33
+ context "update" do
34
+ setup { setup_source "gem_name"=>"vanity" }
35
+
36
+ should "properly encode gem name" do
37
+ setup_source "gem_name"=>"need&this=encoded"
38
+ update_source rescue nil
39
+ assert_requested :get, "http://rubygems.org/api/v1/gems/need%26this%3Dencoded.json"
40
+ end
41
+
42
+ should "handle 404" do
43
+ stub_request(:get, interactions.first.uri).to_return :status=>404
44
+ assert_raise(RuntimeError) { update_source }
45
+ assert_equal "Could not find the Gem vanity", last_error
46
+ end
47
+
48
+ should "handle other error" do
49
+ stub_request(:get, interactions.first.uri).to_return :status=>500
50
+ assert_raise(RuntimeError) { update_source }
51
+ assert_equal "Last request didn't go as expected, trying again later", last_error
52
+ end
53
+
54
+ should "handle invlid document entity" do
55
+ stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
56
+ assert_raise(RuntimeError) { update_source }
57
+ assert_equal "Last request didn't go as expected, trying again later", last_error
58
+ end
59
+
60
+ should "capture number of downloads" do
61
+ update_source
62
+ assert_equal({ :downloads=>3492 }, totals)
63
+ end
64
+
65
+ should "not create any activity" do
66
+ update_source
67
+ assert activities.empty?
68
+ end
69
+
70
+ context "repeating" do
71
+ setup do
72
+ update_source
73
+ data = JSON.parse(interactions.first.response.body).merge("downloads"=>9040, "version"=>"2.1.0")
74
+ stub_request(:get, interactions.first.uri).to_return :body=>data.to_json
75
+ update_source
76
+ end
77
+
78
+ should "update version number" do
79
+ assert meta.include?(:title=>"Version", :text=>"2.1.0")
80
+ end
81
+
82
+ should "capture new number of downloads" do
83
+ assert_equal({ :downloads=>9040 }, totals)
84
+ end
85
+
86
+ should "create activity for new release" do
87
+ assert activity
88
+ end
89
+
90
+ context "activity" do
91
+ should "should have unique identifier" do
92
+ assert_equal "vanity-2.1.0", activity.id
93
+ end
94
+
95
+ should "capture have body denoting release" do
96
+ assert_equal "Released <a href=\"http://rubygems.org/gems/vanity/versions/2.1.0\">vanity version 2.1.0</a>", activity.body
97
+ end
98
+
99
+ should "link to project page" do
100
+ assert_equal "http://rubygems.org/gems/vanity", activity.url
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+
107
+ context "meta" do
108
+ setup { setup_source "gem_name"=>"vanity" }
109
+
110
+ should "link to project page" do
111
+ assert_contains meta, :title=>"Project", :text=>"vanity", :url=>"http://vanity.labnotes.org"
112
+ end
113
+
114
+ should "include project description" do
115
+ assert_contains meta, :text=>"Mirror, mirror on the wall ..."
116
+ end
117
+
118
+ should "include version number" do
119
+ assert_contains meta, :title=>"Version", :text=>"1.4.0"
120
+ end
121
+
122
+ should "list authors" do
123
+ assert_contains meta, :title=>"Authors", :text=>"Assaf Arkin"
124
+ end
125
+
126
+ should "link to RubyGems page" do
127
+ assert_contains meta, :title=>"Source", :text=>"RubyGems", :url=>"http://rubygems.org/gems/vanity"
128
+ end
129
+ end
130
+ end