dash-bees 0.21 → 0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,134 +1,140 @@
1
1
  require_relative "setup"
2
2
 
3
- test DashFu::Bee::Backtweets do
4
- context "setup" do
5
- setup { source.setup "url"=>"vanity.labnotes.org" }
3
+ describe "Backtweets" do
4
+ testing :backtweets
6
5
 
7
- should "use normalize URL and remove scheme" do
6
+ describe "setup" do
7
+ before { source.setup "url"=>"vanity.labnotes.org" }
8
+
9
+ it "should use normalize URL and remove scheme" do
8
10
  source.setup "url"=>"http://Vanity.Labnotes.Org"
9
11
  assert_equal "Tweets for vanity.labnotes.org", source.name
10
12
  end
11
13
 
12
- context "metric" do
13
- subject { source.metric }
14
+ it "should set origin to Backtweets search page" do
15
+ assert_equal "Backtweets for vanity.labnotes.org", source.origin[:text]
16
+ assert_equal "http://backtweets.com/search?q=http://vanity.labnotes.org/", source.origin[:url]
17
+ end
14
18
 
15
- should "use URL" do
16
- assert_equal "Tweets for vanity.labnotes.org", subject.name
17
- end
19
+ it "should use URL in name" do
20
+ assert_equal "Tweets for vanity.labnotes.org", source.name
21
+ end
18
22
 
19
- should "measure totals" do
20
- assert subject.totals
23
+ describe "metric" do
24
+ it "should measure totals" do
25
+ assert source.metric.totals
21
26
  end
22
27
 
23
- should "capture tweets" do
24
- assert subject.columns.include?(id: "tweets", label: "Tweets")
28
+ it "should capture tweets" do
29
+ assert source.metric.columns.include?(id: "tweets", label: "Tweets")
25
30
  end
26
31
  end
27
32
  end
28
33
 
29
34
 
30
- context "validation" do
31
- should "raise error if URL missing" do
32
- assert_raise(RuntimeError) { source.setup "url"=>" " }
35
+ describe "validation" do
36
+ it "should raise error if URL missing" do
37
+ assert_raises(RuntimeError) { source.setup "url"=>" " }
33
38
  end
34
39
 
35
- should "create valid metric" do
40
+ it "should create valid metric" do
36
41
  source.setup "url"=>"vanity.labnotes.org"
37
42
  assert source.valid?
38
43
  end
39
44
  end
40
45
 
41
46
 
42
- context "update" do
43
- setup { source.setup "url"=>"vanity.labnotes.org" }
47
+ describe "update" do
48
+ before { source.setup "url"=>"vanity.labnotes.org" }
44
49
 
45
- should "include API key" do
50
+ it "should include API key" do
46
51
  source.update
47
- assert_requested :get, "http://backtweets.com/search.json?key=4554feeeeeeeeeeeeeee&q=vanity.labnotes.org"
52
+ assert_requested :get, "http://backtweets.com/search.json?key=4554feeeeeeeeeeeeeee&q=http://vanity.labnotes.org/"
48
53
  end
49
54
 
50
- should "properly encode URL" do
55
+ it "should properly encode URL" do
51
56
  stub_request(:get, /backtweets.com/).to_return body: interactions.first.response.body
52
- source.setup "url"=>"need&this=encoded"
57
+ source.setup "url"=>"http://foo?need&this=encoded"
53
58
  source.update
54
- assert_requested :get, "http://backtweets.com/search.json?key=#{bee.send :api_key}&q=need%26this%3Dencoded"
59
+ assert_requested :get, "http://backtweets.com/search.json?key=#{bee.send :api_key}&q=http://foo/?need%26this%3Dencoded"
55
60
  end
56
61
 
57
- should "handle errors" do
62
+ it "should handle errors" do
58
63
  stub_request(:get, interactions.first.uri).to_return status: 500
59
64
  source.update
60
65
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
61
66
  end
62
67
 
63
- should "handle invalid document entity" do
68
+ it "should handle invalid document entity" do
64
69
  stub_request(:get, interactions.first.uri).to_return body: "Not JSON"
65
70
  source.update
66
71
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
67
72
  end
68
73
 
69
- should "capture number of tweets" do
74
+ it "should capture number of tweets" do
70
75
  source.update
71
76
  assert_equal({ tweets: 2 }, source.metric.values)
72
77
  end
73
78
 
74
- context "activity" do
75
- setup { source.update }
76
- subject { source.activity }
79
+ describe "activity" do
80
+ before { source.update }
77
81
 
78
- should "capture tweet identifier" do
79
- assert_equal "20959239143", subject.uid
82
+ it "should capture tweet identifier" do
83
+ assert_equal "20959239143", activity.uid
80
84
  end
81
85
 
82
- should "capture tweet text" do
83
- assert_equal <<-HTML, subject.html
86
+ it "should capture tweet text" do
87
+ assert_equal <<-HTML, activity.html
84
88
  <a href="http://twitter.com/dude/20959239143">tweeted</a>:
85
89
  <blockquote>Super awesome <a href="http://vanity.labnotes.org/">http://j.mp/aOrUnsz</a></blockquote>
86
90
  HTML
87
91
  end
88
92
 
89
- should "capture tweet URL" do
90
- assert_equal "http://twitter.com/dude/20959239143", subject.url
93
+ it "should capture tweet URL" do
94
+ assert_equal "http://twitter.com/dude/20959239143", activity.url
91
95
  end
92
96
 
93
- should "capture tweet timestamp" do
94
- assert_equal Time.parse("2010-8-12T08:30:04").utc, subject.timestamp
97
+ it "should capture tweet timestamp" do
98
+ assert_equal Time.parse("2010-8-12T08:30:04").utc, activity.timestamp
95
99
  end
96
100
 
97
- should "tag as tweeter and mention" do
98
- assert_contains subject.tags, "twitter"
99
- assert_contains subject.tags, "mention"
101
+ it "should tag as tweeter and mention" do
102
+ assert activity.tags.include?("twitter")
103
+ assert activity.tags.include?("mention")
100
104
  end
101
105
 
102
- should "be valid" do
103
- assert subject.valid?
106
+ it "should mark as public" do
107
+ assert activity.public?
104
108
  end
105
109
 
106
- context "author" do
107
- subject { source.activity.person }
110
+ it "should be valid" do
111
+ assert activity.valid?
112
+ end
108
113
 
109
- should "capture full name" do
110
- assert_equal "dude", subject.fullname
114
+ describe "author" do
115
+ it "should capture full name" do
116
+ assert_equal "dude", person.fullname
111
117
  end
112
118
 
113
- should "capture screen name" do
114
- assert_contains subject.identities, "twitter.com:dude"
119
+ it "should capture screen name" do
120
+ assert person.identities.include?("twitter.com:dude")
115
121
  end
116
122
 
117
- should "capture photo" do
118
- assert_equal "http://img.tweetimag.es/i/dude_n", subject.photo_url
123
+ it "should capture photo" do
124
+ assert_equal "http://img.tweetimag.es/i/dude_n", person.photo_url
119
125
  end
120
126
  end
121
127
  end
122
128
 
123
- context "repeating" do
124
- setup do
129
+ describe "repeating" do
130
+ before do
125
131
  source.update
126
132
  second = interactions.last
127
133
  stub_request(:get, second.uri).to_return body: second.response.body
128
134
  source.update
129
135
  end
130
136
 
131
- should "capture new tweets" do
137
+ it "should capture new tweets" do
132
138
  assert_equal 3, source.activities.count
133
139
  assert_match "The last of its kind", source.activity.html
134
140
  end
@@ -136,13 +142,4 @@ test DashFu::Bee::Backtweets do
136
142
  end
137
143
  end
138
144
 
139
-
140
- context "meta" do
141
- setup { source.setup "url"=>"vanity.labnotes.org" }
142
- subject { source.meta }
143
-
144
- should "link to search results" do
145
- assert subject.include?(text: "Search yourself", url: "http://backtweets.com/search?q=vanity.labnotes.org")
146
- end
147
- end
148
145
  end
@@ -2,7 +2,7 @@
2
2
  - !ruby/struct:VCR::HTTPInteraction
3
3
  request: !ruby/struct:VCR::Request
4
4
  method: :get
5
- uri: http://backtweets.com:80/search.json?key=4554feeeeeeeeeeeeeee&q=vanity.labnotes.org
5
+ uri: http://backtweets.com:80/search.json?key=4554feeeeeeeeeeeeeee&q=http://vanity.labnotes.org/
6
6
  body:
7
7
  headers:
8
8
  accept:
@@ -39,7 +39,7 @@
39
39
  - !ruby/struct:VCR::HTTPInteraction
40
40
  request: !ruby/struct:VCR::Request
41
41
  method: :get
42
- uri: http://backtweets.com:80/search.json?key=4554feeeeeeeeeeeeeee&q=vanity.labnotes.org
42
+ uri: http://backtweets.com:80/search.json?key=4554feeeeeeeeeeeeeee&q=http://vanity.labnotes.org/
43
43
  body:
44
44
  response: !ruby/struct:VCR::Response
45
45
  status: !ruby/struct:VCR::ResponseStatus
@@ -17,6 +17,7 @@
17
17
  </subtitle>
18
18
  <updated>2005-07-31T12:29:29Z</updated>
19
19
  <id>tag:example.org,2003:3</id>
20
+ <icon>http://www.flickr.com/photos/nerduo/3770972018/</icon>
20
21
  <link rel="alternate" type="text/html"
21
22
  hreflang="en" href="http://example.org/"/>
22
23
  <link rel="self" type="application/atom+xml"
@@ -1,171 +1,182 @@
1
1
  require_relative "setup"
2
2
 
3
- test DashFu::Bee::Feed do
4
- context "setup" do
5
- subject { source.setup "url"=>"http://example.org/feed.xml" }
3
+ describe "Feed" do
4
+ testing :feed
5
+
6
+ describe "setup" do
7
+ before { source.setup "url"=>"http://example.org/feed.xml" }
8
+
9
+ it "should link to site" do
10
+ assert_equal "dive into mark", source.origin[:text]
11
+ assert_equal "http://example.org/", source.origin[:url]
12
+ end
13
+
14
+ it "should set source name from feed title" do
15
+ stub_request(:get, "http://example.org/feed.xml").to_return body: { title: "The Awesome Feed" }.to_xml(root: "feed")
16
+ source.setup "url"=>"http://example.org/feed.xml"
17
+ assert_equal "The Awesome Feed", source.name
18
+ end
19
+
20
+ it "should set source name from feed URL if no title" do
21
+ stub_request(:get, "http://example.org/feed.xml").to_return body: { title: "" }.to_xml(root: "feed")
22
+ source.setup "url"=>"http://example.org/feed.xml"
23
+ assert_equal "http://example.org/feed.xml", source.name
24
+ end
25
+
26
+ it "should provide site icon" do
27
+ assert_equal "http://www.flickr.com/photos/nerduo/3770972018/", source.fields[ICON]
28
+ end
29
+
30
+ it "should accept feed URL (short form)" do
31
+ source.setup "url"=>"feed://example.org/feed.xml"
32
+ assert_equal "dive into mark", source.name
33
+ end
34
+
35
+ it "should accept feed URL (long form)" do
36
+ source.setup "url"=>"feed:http://example.org/feed.xml"
37
+ assert_equal "dive into mark", source.name
38
+ end
6
39
  end
7
40
 
8
- context "validation" do
9
- should "fail if URL is invalid" do
41
+
42
+ describe "validation" do
43
+ it "should fail if URL is invalid" do
10
44
  assert_raises(RuntimeError) { source.setup("url"=>"/feed.xml") }
11
45
  end
12
46
 
13
- should "fail if URL is not HTTP" do
47
+ it "should fail if URL is not HTTP" do
14
48
  assert_raises(RuntimeError) { source.setup("url"=>"ftp://example.org/feed.xml") }
15
49
  end
16
50
 
17
- should "fail if URL is not accessible" do
51
+ it "should fail if URL is not accessible" do
18
52
  stub_request(:get, "http://example.org/feed.xml").to_timeout
19
53
  assert_raises(RuntimeError) { source.setup("url"=>"http://example.org/feed.xml") }
20
54
  end
21
55
 
22
- should "fail if status is not 200" do
56
+ it "should fail if status is not 200" do
23
57
  stub_request(:get, "http://example.org/feed.xml").to_return status: 400
24
58
  assert_raises(RuntimeError) { source.setup("url"=>"http://example.org/feed.xml") }
25
59
  end
26
60
 
27
- should "fail if document is not a feed" do
61
+ it "should fail if document is not a feed" do
28
62
  stub_request(:get, "http://example.org/feed.xml").to_return body: { not: "feed" }.to_json
29
63
  assert_raises(RuntimeError) { source.setup("url"=>"http://example.org/feed.xml") }
30
64
  end
31
-
32
- should "set source name from feed title" do
33
- stub_request(:get, "http://example.org/feed.xml").to_return body: { title: "The Awesome Feed" }.to_xml(root: "feed")
34
- source.setup "url"=>"http://example.org/feed.xml"
35
- assert_equal "The Awesome Feed", source.name
36
- end
37
-
38
- should "accept feed URL (short form)" do
39
- source.setup "url"=>"feed://example.org/feed.xml"
40
- assert_equal "dive into mark", source.name
41
- end
42
-
43
- should "accept feed URL (long form)" do
44
- source.setup "url"=>"feed:http://example.org/feed.xml"
45
- assert_equal "dive into mark", source.name
46
- end
47
65
  end
48
66
 
49
67
 
50
- context "update" do
51
- setup { source.setup "url"=>"http://example.org/feed.xml" }
68
+ describe "update" do
69
+ before { source.setup "url"=>"http://example.org/feed.xml" }
52
70
 
53
- should "handle 401" do
71
+ it "should handle 401" do
54
72
  stub_request(:get, interactions.first.uri).to_return :status=>404
55
73
  source.update
56
74
  assert_equal "Could not find the feed http://example.org/feed.xml", source.last_error
57
75
  end
58
76
 
59
- should "handle 401" do
77
+ it "should handle 401" do
60
78
  stub_request(:get, interactions.first.uri).to_return :status=>401
61
79
  source.update
62
80
  assert_equal "You are not authorized to access this feed", source.last_error
63
81
  end
64
82
 
65
- should "handle other error" do
83
+ it "should handle other error" do
66
84
  stub_request(:get, interactions.first.uri).to_return :status=>500
67
85
  source.update
68
86
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
69
87
  end
70
88
 
71
- should "handle invlid document entity" do
89
+ it "should handle invlid document entity" do
72
90
  stub_request(:get, interactions.first.uri).to_return :body=>"Not a feed"
73
91
  source.update
74
92
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
75
93
  end
76
94
 
77
- context "activity" do
78
- setup { source.update }
79
- subject { source.activity }
95
+ describe "activity" do
96
+ before { source.update }
80
97
 
81
- should "capture entry id" do
82
- assert_equal "tag:example.org,2003:3.2397", subject.uid
98
+ it "should capture entry id" do
99
+ assert_equal "tag:example.org,2003:3.2397", activity.uid
83
100
  end
84
101
 
85
- should "capture published date" do
86
- assert_equal Time.parse("2003-12-13T08:29:29-04:00"), subject.timestamp
102
+ it "should capture published date" do
103
+ assert_equal Time.parse("2003-12-13T08:29:29-04:00"), activity.timestamp
87
104
  end
88
105
 
89
- should "capture URL" do
90
- assert_equal "http://example.org/2005/04/02/atom", subject.url
106
+ it "should capture URL" do
107
+ assert_equal "http://example.org/2005/04/02/atom", activity.url
91
108
  end
92
109
 
93
- should "capture title and content" do
94
- assert_equal <<-HTML.strip, subject.html
110
+ it "should capture title and content" do
111
+ assert_equal <<-HTML.strip, activity.html
95
112
  posted <a href=\"http://example.org/2005/04/02/atom\">Atom draft-07 snapshot</a>:
96
113
  <blockquote><p><i>[Update: The Atom draft is finished.]</i></p></blockquote>
97
114
  HTML
98
115
  end
99
116
 
100
- context "person" do
101
- subject { source.activity.person }
102
-
103
- should "capture full name" do
104
- assert_equal "Mark Pilgrim", subject.fullname
117
+ describe "person" do
118
+ it "should capture full name" do
119
+ assert_equal "Mark Pilgrim", person.fullname
105
120
  end
106
121
 
107
- should "capture email" do
108
- assert_equal "f8dy@example.com", subject.email
122
+ it "should capture email" do
123
+ assert_equal "f8dy@example.com", person.email
109
124
  end
110
125
 
111
- should "capture identity" do
112
- assert_contains subject.identities, "http://example.org/"
126
+ it "should capture identity" do
127
+ assert person.identities.include?("http://example.org/")
113
128
  end
114
129
  end
115
130
 
116
131
  end
117
132
 
118
- context "with summary" do
119
- setup do
133
+ describe "with summary" do
134
+ before do
120
135
  source.setup "url"=>"http://example.org/summary.xml"
121
136
  source.update
122
137
  end
123
- subject { source.activity }
124
138
 
125
- should "capture title and summary" do
126
- assert_equal <<-HTML.strip, subject.html
139
+ it "should capture title and summary" do
140
+ assert_equal <<-HTML.strip, activity.html
127
141
  posted <a href=\"http://example.org/2005/04/02/atom\">Atom draft-07 snapshot</a>:
128
142
  <blockquote><q>Quickly stated</q></blockquote>
129
143
  HTML
130
144
  end
131
145
  end
132
146
 
133
- context "with update but no published date" do
134
- setup do
147
+ describe "with update but no published date" do
148
+ before do
135
149
  source.setup "url"=>"http://example.org/update.xml"
136
150
  source.update
137
151
  end
138
- subject { source.activity }
139
152
 
140
- should "capture published date" do
141
- assert_equal Time.parse("2003-12-13T08:29:29-04:00"), subject.timestamp
153
+ it "should capture published date" do
154
+ assert_equal Time.parse("2003-12-13T08:29:29-04:00"), activity.timestamp
142
155
  end
143
156
  end
144
157
 
145
- context "with HTML content" do
146
- setup do
158
+ describe "with HTML content" do
159
+ before do
147
160
  source.setup "url"=>"http://example.org/html.xml"
148
161
  source.update
149
162
  end
150
- subject { source.activity }
151
163
 
152
- should "capture title and summary" do
153
- assert_equal <<-HTML.strip, subject.html
164
+ it "should capture title and summary" do
165
+ assert_equal <<-HTML.strip, activity.html
154
166
  posted <a href=\"\">Atom draft-07 snapshot</a>:
155
167
  <blockquote><i>HTML <br> content</i></blockquote>
156
168
  HTML
157
169
  end
158
170
  end
159
171
 
160
- context "with truncated content" do
161
- setup do
172
+ describe "with truncated content" do
173
+ before do
162
174
  source.setup "url"=>"http://example.org/truncated.xml"
163
175
  source.update
164
176
  end
165
- subject { source.activity }
166
177
 
167
- should "capture title and summary" do
168
- assert_equal <<-HTML.strip, subject.html
178
+ it "should capture title and summary" do
179
+ assert_equal <<-HTML.strip, activity.html
169
180
  posted <a href=\"\">Atom draft-07 snapshot</a>:
170
181
  <blockquote><p><em>Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated Truncated\n Truncated Truncated Truncated Truncated Truncated Truncat</em></p>
171
182
  ...</blockquote>
@@ -176,13 +187,4 @@ posted <a href=\"\">Atom draft-07 snapshot</a>:
176
187
  end
177
188
 
178
189
 
179
- context "meta" do
180
- setup { source.setup "url"=>"http://example.org/feed.xml" }
181
- subject { source.meta }
182
-
183
- should "link to site" do
184
- assert_contains subject, :title=>"Source", :text=>"dive into mark", :url=>"http://example.org/"
185
- end
186
- end
187
-
188
190
  end