dash-mario 0.16 → 0.17

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.
@@ -61,25 +61,25 @@ test DashFu::Mario::Github do
61
61
 
62
62
  should "handle 404" do
63
63
  stub_request(:get, interactions.first.uri).to_return :status=>404
64
- assert_raise(RuntimeError) { source.update }
64
+ source.update
65
65
  assert_equal "Could not find the repository assaf/vanity", source.last_error
66
66
  end
67
67
 
68
68
  should "handle 401" do
69
69
  stub_request(:get, interactions.first.uri).to_return :status=>401
70
- assert_raise(RuntimeError) { source.update }
70
+ source.update
71
71
  assert_equal "You are not authorized to access this repository, or invalid username/password", source.last_error
72
72
  end
73
73
 
74
74
  should "handle other error" do
75
75
  stub_request(:get, interactions.first.uri).to_return :status=>500
76
- assert_raise(RuntimeError) { source.update }
76
+ source.update
77
77
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
78
78
  end
79
79
 
80
80
  should "handle invlid document entity" do
81
81
  stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
82
- assert_raise(RuntimeError) { source.update }
82
+ source.update
83
83
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
84
84
  end
85
85
 
@@ -98,128 +98,129 @@ test DashFu::Mario::Github do
98
98
  assert_equal 36, source.metric.values[:forks]
99
99
  end
100
100
 
101
- should "not create any activity" do
102
- source.update
103
- assert source.activities.empty?
104
- end
105
101
 
106
- context "repeating" do
107
- setup do
108
- source.update
109
- repo = interactions.select { |i| i.uri =~ /repos\/show/ }
110
- stub_request(:get, repo.first.uri).to_return :body=>repo.last.response.body
111
- commits = interactions.select { |i| i.uri =~ /commits\/list/ }
112
- stub_request(:get, commits.first.uri).to_return :body=>commits.last.response.body
113
- source.update
102
+ context "activity" do
103
+ setup { source.update }
104
+ subject { source.activity }
105
+
106
+ should "capture commit URL" do
107
+ assert_equal "http://github.com/assaf/vanity/commit/dd154a9fdd2ac534b62b55b8acac2fd092d6543a", subject.url
114
108
  end
115
109
 
116
- should "update watchers" do
117
- assert_equal 555, source.metric.values[:watchers]
110
+ should "capture commit SHA" do
111
+ assert_equal "dd154a9fdd2ac534b62b55b8acac2fd092d6543a", subject.uid
118
112
  end
119
113
 
120
- should "update forks" do
121
- assert_equal 38, source.metric.values[:forks]
114
+ should "capture timestamp" do
115
+ assert_equal Time.parse("2010-08-06T00:18:01-07:00 UTC").utc, subject.timestamp
122
116
  end
123
117
 
124
- should "capture new number of commits" do
125
- assert_equal 39, source.metric.values[:commits]
118
+ should "capture push" do
119
+ assert_match %{pushed to master at <a href="http://github.com/assaf/vanity">assaf/vanity</a>:}, subject.html
126
120
  end
127
121
 
128
- context "activity" do
129
- subject { source.activity }
122
+ should "tag as push" do
123
+ assert_contains subject.tags, "push"
124
+ end
130
125
 
131
- should "capture commit URL" do
132
- assert_equal "http://github.com/assaf/vanity/commit/dd154a9fdd2ac534b62b55b8acac2fd092d65439", subject.url
133
- end
126
+ should "be valid" do
127
+ subject.validate
128
+ assert subject.valid?
129
+ end
130
+
131
+ context "person" do
132
+ subject { source.activity.person }
134
133
 
135
- should "capture commit SHA" do
136
- assert_equal "cc156a9fdd2ac534b62b55b8acac2fd092d65439", subject.uid
134
+ should "capture full name" do
135
+ assert_equal "Assaf Arkin", subject.fullname
137
136
  end
138
137
 
139
- should "capture timestamp" do
140
- assert_equal Time.parse("2010-08-06T00:22:01-07:00 UTC"), subject.timestamp
138
+ should "capture email" do
139
+ assert_equal "assaf@labnotes.org", subject.email
141
140
  end
142
141
 
143
- should "capture push" do
144
- assert_match %{pushed to master at <a href="http://github.com/assaf/vanity">assaf/vanity</a>:}, subject.html
142
+ should "capture identity" do
143
+ assert_contains subject.identities, "github.com:assaf"
145
144
  end
145
+ end
146
+
147
+ context "commit message" do
148
+ subject { (Nokogiri::HTML(source.activity.html)/"blockquote").map(&:inner_text).join("\n") }
146
149
 
147
- should "tag as push" do
148
- assert_contains subject.tags, "push"
150
+ should "start with commit SHA" do
151
+ assert_match /^dd154a9 /, subject
149
152
  end
150
153
 
151
- should "be valid" do
152
- subject.validate
153
- assert subject.valid?
154
+ should "include first 50 characters of message" do
155
+ with_message "This is a very long message and we're only going to show the first 50 characters of it."
156
+ assert_equal 50, subject[/\s(.*)/, 1].length
154
157
  end
155
158
 
156
- context "person" do
157
- subject { source.activity.person }
159
+ should "use only first line of message" do
160
+ with_message "This message is made\nof two lines"
161
+ assert_match "This message is made", subject[/\s(.*)/, 1]
162
+ end
158
163
 
159
- should "capture full name" do
160
- assert_equal "Assaf Arkin", subject.fullname
161
- end
164
+ def with_message(message)
165
+ commits = interactions.select { |i| i.uri =~ /commits\/list/ }
166
+ commit = JSON.parse(commits.first.response.body)["commits"].first
167
+ commit["id"] = "ff156a9fdd2ac534b62b55b8acac2fd092d65439"
168
+ commit["message"] = message
169
+ stub_request(:get, commits.first.uri).to_return :body=>{ :commits=>[commit] }.to_json
170
+ source.update
171
+ end
172
+ end
162
173
 
163
- should "capture email" do
164
- assert_equal "assaf@labnotes.org", subject.email
165
- end
174
+ context "sequential commits" do
175
+ setup do
176
+ puts source.activities.clear
177
+ interaction = interactions.select { |i| i.uri =~ /commits\/list/ }.last
178
+ stub_request(:get, interaction.uri).to_return :body=>interaction.response.body
179
+ source.update
180
+ end
181
+ subject { (Nokogiri::HTML(source.activity.html)/"blockquote") }
166
182
 
167
- should "capture identity" do
168
- assert_contains subject.identities, "github.com:assaf"
169
- end
183
+ should "show as multiple activities" do
184
+ assert_equal 3, source.activities.count # 4 commits -> 3 activities
170
185
  end
171
186
 
172
- context "commit message" do
173
- subject { (Nokogiri::HTML(source.activity.html)/"blockquote").inner_text.strip }
174
-
175
- should "start with commit SHA" do
176
- assert_match /^cc156a9 /, subject
177
- end
178
-
179
- should "include first 50 characters of message" do
180
- with_message "This is a very long message and we're only going to show the first 50 characters of it."
181
- assert_equal 50, subject[/\s(.*)/, 1].length
182
- end
183
-
184
- should "use only first line of message" do
185
- with_message "This message is made\nof two lines"
186
- assert_match "This message is made", subject[/\s(.*)/, 1]
187
- end
188
-
189
- def with_message(message)
190
- commits = interactions.select { |i| i.uri =~ /commits\/list/ }
191
- commit = JSON.parse(commits.first.response.body)["commits"].first
192
- commit["message"] = message
193
- stub_request(:get, commits.first.uri).to_return :body=>{ :commits=>[commit] }.to_json
194
- source.update
195
- end
187
+ should "merge related commits into single activity" do
188
+ assert_equal 2, subject.length # last one has two commits
196
189
  end
197
190
 
198
- context "sequential commits" do
199
- setup do
200
- interaction = interactions.select { |i| i.uri =~ /commits\/list/ }.last
201
- stub_request(:get, interaction.uri).to_return :body=>interaction.response.body
202
- source.update
203
- end
204
- subject { (Nokogiri::HTML(source.activity.html)/"blockquote") }
205
-
206
- should "show as multiple activities" do
207
- assert_equal 3, source.activities.count # 4 commits -> 3 activities
208
- end
209
-
210
- should "merge related commits into single activity" do
211
- assert_equal 2, subject.length # last one has two commits
212
- end
213
-
214
- should "merge related commits in order they were listed" do
215
- first, second = subject.map { |bq| bq.inner_text.strip }
216
- assert_equal "cc156a9 Most recent commit", first
217
- assert_equal "dd156a9 Not most recent commit", second
218
- end
191
+ should "merge related commits in order they were listed" do
192
+ first, second = subject.map { |bq| bq.inner_text.strip }
193
+ assert_equal "cc156a9 Most recent commit", first
194
+ assert_equal "dd156a9 Not most recent commit", second
219
195
  end
220
196
  end
221
197
 
222
198
  end
199
+
200
+
201
+ context "repeating" do
202
+ setup do
203
+ source.update
204
+ repo = interactions.select { |i| i.uri =~ /repos\/show/ }
205
+ stub_request(:get, repo.first.uri).to_return :body=>repo.last.response.body
206
+ commits = interactions.select { |i| i.uri =~ /commits\/list/ }
207
+ stub_request(:get, commits.first.uri).to_return :body=>commits.last.response.body
208
+ source.update
209
+ end
210
+
211
+ should "update watchers" do
212
+ assert_equal 555, source.metric.values[:watchers]
213
+ end
214
+
215
+ should "update forks" do
216
+ assert_equal 38, source.metric.values[:forks]
217
+ end
218
+
219
+ should "capture new number of commits" do
220
+ assert_equal 39, source.metric.values[:commits]
221
+ end
222
+ end
223
+
223
224
  end
224
225
 
225
226
 
@@ -17,13 +17,14 @@ class Source
17
17
  def setup(params = {})
18
18
  mario.setup state, params
19
19
  self.name = state.delete("source.name")
20
- @metric = Metric.new(:name=>name, :columns=>state["metric.columns"], :totals=>!!state["metric.totals"]) if state["metric.columns"]
20
+ @metric = Metric.new(:name=>name, :columns=>state.delete("metric.columns"), :totals=>!!state.delete("metric.totals")) if state["metric.columns"]
21
21
  validate
22
22
  end
23
23
 
24
24
  def validate
25
25
  raise "Must be named" if name.blank?
26
26
  raise "Name must be 3 characters of longer" if name.length < 3
27
+ raise "State fields can only use alphanumeric/underscore in their names" unless state.keys.all? { |k| k =~ /^\w+$/ }
27
28
  mario.validate state
28
29
  metric.validate if metric
29
30
  end
@@ -39,18 +40,25 @@ class Source
39
40
  # assert source.update
40
41
  def update(request = nil)
41
42
  @last_error = nil
42
- mario.update state, request, &callback
43
+ mario.update state, request, Callback.new(self)
43
44
  rescue
44
45
  @last_error = $!.message
45
46
  raise
46
47
  end
47
48
 
48
- # Performs an update on the source and returns the meta-data.
49
+ # Similar to update but raises last error.
50
+ def update!(request = nil)
51
+ update request
52
+ raise @last_error if @last_error
53
+ end
54
+
55
+ # Performs an update on the source and returns the meta-data. Raises
56
+ # last_error if error reported during update.
49
57
  #
50
58
  # @example
51
59
  # assert source.meta.include?(:title=>"Version", :text=>"1.4.0")
52
60
  def meta
53
- mario.update state, nil, &callback
61
+ update!
54
62
  mario.meta(state)
55
63
  end
56
64
 
@@ -67,25 +75,33 @@ class Source
67
75
  activities.last
68
76
  end
69
77
 
70
- protected
78
+ class Callback
79
+ def initialize(source)
80
+ @source = source
81
+ end
82
+
83
+ def activity!(values)
84
+ values = values.clone
85
+ if person = values.delete(:person)
86
+ values[:person] = Person.new(person)
87
+ end
88
+ @source.activities.push Activity.new(values)
89
+ end
90
+
91
+ def set!(values)
92
+ @source.metric.values.update values
93
+ end
71
94
 
72
- def callback
73
- lambda do |args|
74
- if args[:set]
75
- metric.values.update args[:set]
76
- elsif args[:inc]
77
- args[:inc].each do |name, value|
78
- metric.values[name] ||= 0
79
- metric.values[name] += value
80
- end
81
- elsif args[:activity]
82
- values = args[:activity].clone
83
- if person = values.delete(:person)
84
- values[:person] = Person.new(person)
85
- end
86
- activities.push Activity.new(values)
95
+ def inc!(values)
96
+ values.each do |name, value|
97
+ @source.metric.values[name] ||= 0
98
+ @source.metric.values[name] += value
87
99
  end
88
100
  end
101
+
102
+ def error!(message)
103
+ @source.last_error = message
104
+ end
89
105
  end
90
106
 
91
107
  end
@@ -16,7 +16,7 @@ test DashFu::Mario::RubyGems do
16
16
  end
17
17
 
18
18
  should "capture downloads" do
19
- assert subject.columns.include?(:id=>"downloads", :label=>"Downloads")
19
+ assert subject.columns.include?(id: "downloads", label: "Downloads")
20
20
  end
21
21
  end
22
22
  end
@@ -44,26 +44,26 @@ test DashFu::Mario::RubyGems do
44
44
  end
45
45
 
46
46
  should "handle 404" do
47
- stub_request(:get, interactions.first.uri).to_return :status=>404
48
- assert_raise(RuntimeError) { source.update }
47
+ stub_request(:get, interactions.first.uri).to_return status: 404
48
+ source.update
49
49
  assert_equal "Could not find the Gem vanity", source.last_error
50
50
  end
51
51
 
52
52
  should "handle other error" do
53
- stub_request(:get, interactions.first.uri).to_return :status=>500
54
- assert_raise(RuntimeError) { source.update }
53
+ stub_request(:get, interactions.first.uri).to_return status: 500
54
+ source.update
55
55
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
56
56
  end
57
57
 
58
58
  should "handle invlid document entity" do
59
- stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
60
- assert_raise(RuntimeError) { source.update }
59
+ stub_request(:get, interactions.first.uri).to_return body: "Not JSON"
60
+ source.update
61
61
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
62
62
  end
63
63
 
64
64
  should "capture number of downloads" do
65
65
  source.update
66
- assert_equal({ :downloads=>3492 }, source.metric.values)
66
+ assert_equal({ downloads: 3492 }, source.metric.values)
67
67
  end
68
68
 
69
69
  should "not create any activity" do
@@ -75,16 +75,16 @@ test DashFu::Mario::RubyGems do
75
75
  setup do
76
76
  source.update
77
77
  data = JSON.parse(interactions.first.response.body).merge("downloads"=>9040, "version"=>"2.1.0")
78
- stub_request(:get, interactions.first.uri).to_return :body=>data.to_json
78
+ stub_request(:get, interactions.first.uri).to_return body: data.to_json
79
79
  source.update
80
80
  end
81
81
 
82
82
  should "update version number" do
83
- assert source.meta.include?(:title=>"Version", :text=>"2.1.0")
83
+ assert source.meta.include?(title: "Version", text: "2.1.0")
84
84
  end
85
85
 
86
86
  should "capture new number of downloads" do
87
- assert_equal({ :downloads=>9040 }, source.metric.values)
87
+ assert_equal({ downloads: 9040 }, source.metric.values)
88
88
  end
89
89
 
90
90
  should "create activity for new release" do
@@ -28,5 +28,5 @@ WebMock.disable_net_connect!
28
28
  VCR.config do |vcr|
29
29
  vcr.cassette_library_dir = File.dirname(__FILE__) + "/cassettes"
30
30
  vcr.http_stubbing_library = :webmock
31
- vcr.default_cassette_options = { :record=>ENV["RECORD"] ? :new_episodes : :none }
31
+ vcr.default_cassette_options = { record: ENV["RECORD"] ? :new_episodes : :none }
32
32
  end
@@ -914,3 +914,21 @@ Github: 200
914
914
  Github: 500
915
915
  RubyGems: 200
916
916
  RubyGems: 500
917
+ Backtweets: 500
918
+ Backtweets: 200
919
+ Github: 200
920
+ Github: 500
921
+ RubyGems: 200
922
+ RubyGems: 500
923
+ Backtweets: 500
924
+ Backtweets: 200
925
+ Github: 200
926
+ Github: 500
927
+ Backtweets: 500
928
+ Backtweets: 200
929
+ Github: 200
930
+ Github: 500
931
+ RubyGems: 200
932
+ RubyGems: 500
933
+ RubyGems: 200
934
+ RubyGems: 500
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 16
8
- version: "0.16"
7
+ - 17
8
+ version: "0.17"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Assaf Arkin
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-09-08 00:00:00 -07:00
16
+ date: 2010-09-12 00:00:00 -07:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -129,7 +129,7 @@ licenses: []
129
129
  post_install_message:
130
130
  rdoc_options:
131
131
  - --title
132
- - DashFu::Mario 0.16
132
+ - DashFu::Mario 0.17
133
133
  - --main
134
134
  - README.rdoc
135
135
  - --webcvs