onebox 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +7 -452
  4. data/Gemfile +1 -1
  5. data/README.md +23 -45
  6. data/lib/onebox.rb +21 -13
  7. data/lib/onebox/engine.rb +53 -43
  8. data/lib/onebox/engine/amazon_onebox.rb +34 -7
  9. data/lib/onebox/engine/classic_google_maps_onebox.rb +37 -0
  10. data/lib/onebox/engine/github_blob_onebox.rb +27 -7
  11. data/lib/onebox/engine/github_commit_onebox.rb +8 -15
  12. data/lib/onebox/engine/github_gist_onebox.rb +10 -10
  13. data/lib/onebox/engine/github_pullrequest_onebox.rb +7 -15
  14. data/lib/onebox/engine/google_play_app_onebox.rb +30 -0
  15. data/lib/onebox/engine/html.rb +10 -1
  16. data/lib/onebox/engine/image_onebox.rb +13 -0
  17. data/lib/onebox/engine/stack_exchange_onebox.rb +25 -11
  18. data/lib/onebox/engine/standard_embed.rb +48 -0
  19. data/lib/onebox/engine/twitter_status_onebox.rb +100 -0
  20. data/lib/onebox/engine/whitelisted_generic_onebox.rb +223 -0
  21. data/lib/onebox/engine/wikipedia_onebox.rb +27 -5
  22. data/lib/onebox/engine/youtube_onebox.rb +22 -0
  23. data/lib/onebox/helpers.rb +24 -0
  24. data/lib/onebox/layout.rb +67 -0
  25. data/lib/onebox/layout_support.rb +16 -0
  26. data/lib/onebox/matcher.rb +6 -1
  27. data/lib/onebox/preview.rb +19 -6
  28. data/lib/onebox/version.rb +1 -1
  29. data/lib/onebox/view.rb +7 -12
  30. data/onebox.gemspec +7 -5
  31. data/spec/fixtures/amazon.response +1336 -2971
  32. data/spec/fixtures/githubblob.response +49 -921
  33. data/spec/fixtures/{android.response → googleplayapp.response} +1 -1
  34. data/spec/fixtures/stackexchange.response +1 -1889
  35. data/spec/fixtures/twitterstatus.response +3006 -0
  36. data/spec/fixtures/youtube-json.response +1 -0
  37. data/spec/fixtures/youtube.response +1625 -0
  38. data/spec/lib/onebox/engine/amazon_onebox_spec.rb +5 -20
  39. data/spec/lib/onebox/engine/classic_google_maps_onebox_spec.rb +28 -0
  40. data/spec/lib/onebox/engine/github_blob_onebox_spec.rb +6 -15
  41. data/spec/lib/onebox/engine/github_commit_onebox_spec.rb +14 -22
  42. data/spec/lib/onebox/engine/github_gist_onebox_spec.rb +6 -14
  43. data/spec/lib/onebox/engine/github_pullrequest_onebox_spec.rb +14 -26
  44. data/spec/lib/onebox/engine/google_play_app_onebox_spec.rb +28 -0
  45. data/spec/lib/onebox/engine/html_spec.rb +4 -6
  46. data/spec/lib/onebox/engine/json_spec.rb +4 -6
  47. data/spec/lib/onebox/engine/stack_exchange_onebox_spec.rb +4 -17
  48. data/spec/lib/onebox/engine/twitter_status_onebox_spec.rb +103 -0
  49. data/spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb +51 -0
  50. data/spec/lib/onebox/engine/wikipedia_onebox_spec.rb +4 -17
  51. data/spec/lib/onebox/engine/youtube_onebox_spec.rb +17 -0
  52. data/spec/lib/onebox/engine_spec.rb +35 -32
  53. data/spec/lib/onebox/layout_spec.rb +77 -0
  54. data/spec/lib/onebox/matcher_spec.rb +0 -15
  55. data/spec/lib/onebox/preview_spec.rb +39 -9
  56. data/spec/lib/onebox_spec.rb +15 -11
  57. data/spec/spec_helper.rb +60 -4
  58. data/spec/support/html_spec_helper.rb +2 -1
  59. data/templates/_layout.mustache +11 -4
  60. data/templates/amazon.mustache +4 -3
  61. data/templates/githubblob.mustache +7 -5
  62. data/templates/githubcommit.mustache +20 -11
  63. data/templates/githubpullrequest.mustache +19 -12
  64. data/templates/googleplayapp.mustache +4 -0
  65. data/templates/stackexchange.mustache +19 -3
  66. data/templates/twitterstatus.mustache +12 -0
  67. data/templates/whitelistedgeneric.mustache +5 -0
  68. data/templates/wikipedia.mustache +4 -3
  69. metadata +57 -166
  70. data/lib/onebox/engine/bliptv_onebox.rb +0 -28
  71. data/lib/onebox/engine/clikthrough_onebox.rb +0 -25
  72. data/lib/onebox/engine/college_humor_onebox.rb +0 -27
  73. data/lib/onebox/engine/dailymotion_onebox.rb +0 -28
  74. data/lib/onebox/engine/dotsub_onebox.rb +0 -27
  75. data/lib/onebox/engine/example_onebox.rb +0 -24
  76. data/lib/onebox/engine/flickr_onebox.rb +0 -26
  77. data/lib/onebox/engine/funny_or_die_onebox.rb +0 -28
  78. data/lib/onebox/engine/hulu_onebox.rb +0 -29
  79. data/lib/onebox/engine/imgur_image_onebox.rb +0 -26
  80. data/lib/onebox/engine/itunes_onebox.rb +0 -28
  81. data/lib/onebox/engine/kinomap_onebox.rb +0 -27
  82. data/lib/onebox/engine/nfb_onebox.rb +0 -28
  83. data/lib/onebox/engine/open_graph.rb +0 -11
  84. data/lib/onebox/engine/qik_onebox.rb +0 -25
  85. data/lib/onebox/engine/revision3_onebox.rb +0 -27
  86. data/lib/onebox/engine/slideshare_onebox.rb +0 -27
  87. data/lib/onebox/engine/sound_cloud_onebox.rb +0 -27
  88. data/lib/onebox/engine/spotify_onebox.rb +0 -27
  89. data/lib/onebox/engine/ted_onebox.rb +0 -28
  90. data/lib/onebox/engine/twitter_onebox.rb +0 -31
  91. data/lib/onebox/engine/viddler_onebox.rb +0 -28
  92. data/lib/onebox/engine/vimeo_onebox.rb +0 -27
  93. data/lib/onebox/engine/yfrog_onebox.rb +0 -28
  94. data/spec/fixtures/bliptv.response +0 -724
  95. data/spec/fixtures/clikthrough.response +0 -1472
  96. data/spec/fixtures/collegehumor.response +0 -1272
  97. data/spec/fixtures/dailymotion.response +0 -575
  98. data/spec/fixtures/dotsub.response +0 -1257
  99. data/spec/fixtures/example.response +0 -50
  100. data/spec/fixtures/flickr.response +0 -1292
  101. data/spec/fixtures/funnyordie.response +0 -2010
  102. data/spec/fixtures/githubgist.response +0 -468
  103. data/spec/fixtures/hulu.response +0 -339
  104. data/spec/fixtures/imguralbum.response +0 -941
  105. data/spec/fixtures/imgurimage.response +0 -872
  106. data/spec/fixtures/itunes.response +0 -402
  107. data/spec/fixtures/kinomap.response +0 -299
  108. data/spec/fixtures/nfb.response +0 -810
  109. data/spec/fixtures/opengraph.response +0 -27
  110. data/spec/fixtures/qik.response +0 -371
  111. data/spec/fixtures/revision3.response +0 -985
  112. data/spec/fixtures/rottentomatoesfresh.response +0 -3275
  113. data/spec/fixtures/rottentomatoesincomplete.response +0 -2313
  114. data/spec/fixtures/rottentomatoesrotten.response +0 -3549
  115. data/spec/fixtures/slideshare.response +0 -1745
  116. data/spec/fixtures/soundcloud.response +0 -1409
  117. data/spec/fixtures/spotify.response +0 -250
  118. data/spec/fixtures/ted.response +0 -1341
  119. data/spec/fixtures/twitter.response +0 -1712
  120. data/spec/fixtures/viddler.response +0 -442
  121. data/spec/fixtures/vimeo.response +0 -571
  122. data/spec/fixtures/yfrog.response +0 -464
  123. data/spec/lib/onebox/engine/bliptv_onebox_spec.rb +0 -37
  124. data/spec/lib/onebox/engine/clikthrough_onebox_spec.rb +0 -29
  125. data/spec/lib/onebox/engine/college_humor_onebox_spec.rb +0 -37
  126. data/spec/lib/onebox/engine/dailymotion_onebox_spec.rb +0 -39
  127. data/spec/lib/onebox/engine/dotsub_onebox_spec.rb +0 -39
  128. data/spec/lib/onebox/engine/example_onebox_spec.rb +0 -21
  129. data/spec/lib/onebox/engine/flickr_onebox_spec.rb +0 -33
  130. data/spec/lib/onebox/engine/funny_or_die_onebox_spec.rb +0 -37
  131. data/spec/lib/onebox/engine/hulu_onebox_spec.rb +0 -37
  132. data/spec/lib/onebox/engine/imgur_image_onebox_spec.rb +0 -29
  133. data/spec/lib/onebox/engine/itunes_onebox_spec.rb +0 -29
  134. data/spec/lib/onebox/engine/kinomap_onebox_spec.rb +0 -37
  135. data/spec/lib/onebox/engine/nfb_onebox_spec.rb +0 -38
  136. data/spec/lib/onebox/engine/open_graph_spec.rb +0 -27
  137. data/spec/lib/onebox/engine/qik_onebox_spec.rb +0 -38
  138. data/spec/lib/onebox/engine/revision3_onebox_spec.rb +0 -39
  139. data/spec/lib/onebox/engine/slideshare_onebox_spec.rb +0 -33
  140. data/spec/lib/onebox/engine/sound_cloud_onebox_spec.rb +0 -39
  141. data/spec/lib/onebox/engine/spotify_onebox_spec.rb +0 -36
  142. data/spec/lib/onebox/engine/ted_onebox_spec.rb +0 -33
  143. data/spec/lib/onebox/engine/twitter_onebox_spec.rb +0 -47
  144. data/spec/lib/onebox/engine/viddler_onebox_spec.rb +0 -39
  145. data/spec/lib/onebox/engine/vimeo_onebox_spec.rb +0 -37
  146. data/spec/lib/onebox/engine/yfrog_onebox_spec.rb +0 -33
  147. data/spec/lib/onebox/view_spec.rb +0 -16
  148. data/templates/bliptv.mustache +0 -5
  149. data/templates/clikthrough.mustache +0 -4
  150. data/templates/collegehumor.mustache +0 -5
  151. data/templates/dailymotion.mustache +0 -5
  152. data/templates/dotsub.mustache +0 -5
  153. data/templates/example.mustache +0 -2
  154. data/templates/flickr.mustache +0 -4
  155. data/templates/funnyordie.mustache +0 -6
  156. data/templates/githubgist.mustache +0 -3
  157. data/templates/hulu.mustache +0 -6
  158. data/templates/imgurimage.mustache +0 -3
  159. data/templates/itunes.mustache +0 -4
  160. data/templates/kinomap.mustache +0 -5
  161. data/templates/nfb.mustache +0 -5
  162. data/templates/qik.mustache +0 -4
  163. data/templates/revision3.mustache +0 -5
  164. data/templates/slideshare.mustache +0 -4
  165. data/templates/soundcloud.mustache +0 -5
  166. data/templates/spotify.mustache +0 -4
  167. data/templates/ted.mustache +0 -5
  168. data/templates/twitter.mustache +0 -7
  169. data/templates/viddler.mustache +0 -5
  170. data/templates/vimeo.mustache +0 -5
  171. data/templates/yfrog.mustache +0 -4
@@ -3,35 +3,20 @@ require "spec_helper"
3
3
  describe Onebox::Engine::AmazonOnebox do
4
4
  before(:all) do
5
5
  @link = "http://www.amazon.com/Knit-Noro-Accessories-Colorful-Little/dp/193609620X"
6
- fake(@link, response(described_class.template_name))
6
+ @uri = "http://www.amazon.com/gp/aw/d/193609620X"
7
7
  end
8
- before(:each) { Onebox.defaults.cache.clear }
9
-
10
- let(:link) { @link }
11
8
 
9
+ include_context "engines"
12
10
  it_behaves_like "an engine"
13
11
 
14
12
  describe "#to_html" do
15
- let(:html) { described_class.new(link).to_html }
16
-
17
- it "returns the product title" do
18
- expect(html).to include("Knit Noro: Accessories: 30 Colorful Little Knits [Hardcover]")
19
- end
20
-
21
- it "returns the product image" do
22
- expect(html).to include("61mI3YmHVnL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg")
13
+ it "includes image" do
14
+ expect(html).to include("img")
23
15
  end
24
16
 
25
- it "returns the product description" do
17
+ it "includes description" do
26
18
  expect(html).to include("Using only the finest natural materials and ecologically sound")
27
19
  end
28
20
 
29
- it "returns the product price" do
30
- expect(html).to include("$18.77")
31
- end
32
-
33
- it "returns the product URL" do
34
- expect(html).to include(link)
35
- end
36
21
  end
37
22
  end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe Onebox::Engine::ClassicGoogleMapsOnebox do
4
+ describe 'long form url' do
5
+ before do
6
+ @link = "https://maps.google.ca/maps?q=Eiffel+Tower,+Avenue+Anatole+France,+Paris,+France&hl=en&sll=43.656878,-79.32085&sspn=0.932941,1.50238&oq=eiffel+&t=m&z=17&iwloc=A"
7
+ end
8
+
9
+ include_context "engines"
10
+ it_behaves_like "an engine"
11
+
12
+ describe "#to_html" do
13
+ it "embeds the iframe to display the map" do
14
+ expect(html).to include("iframe")
15
+ end
16
+ end
17
+ end
18
+
19
+ describe 'short form url' do
20
+ let(:long_url) { "https://maps.google.ca/maps?q=Brooklyn+Bridge,+Brooklyn,+NY,+United+States&hl=en&sll=43.656878,-79.32085&sspn=0.932941,1.50238&oq=brooklyn+bridge&t=m&z=17&iwloc=A" }
21
+
22
+ it "retrieves the long form url" do
23
+ onebox = described_class.new("http://goo.gl/maps/XffUa")
24
+ onebox.expects(:get_long_url).once.returns(long_url)
25
+ expect(onebox.url).to eq(long_url)
26
+ end
27
+ end
28
+ end
@@ -1,30 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Onebox::Engine::GithubBlobOnebox do
4
- let(:link) { "https://github.com/discourse/discourse/blob/master/lib/oneboxer/github_blob_onebox.rb" }
5
- before do
6
- fake(link, response("githubblob"))
4
+ before(:all) do
5
+ @link = "https://github.com/discourse/discourse/blob/master/lib/oneboxer/github_blob_onebox.rb"
6
+ fake("https://raw.github.com/discourse/discourse/master/lib/oneboxer/github_blob_onebox.rb", response(described_class.onebox_name))
7
7
  end
8
8
 
9
+ include_context "engines"
9
10
  it_behaves_like "an engine"
10
11
 
11
12
  describe "#to_html" do
12
- let(:html) { described_class.new(link).to_html }
13
-
14
- it "has file name" do
13
+ it "includes file name" do
15
14
  expect(html).to include("github_blob_onebox.rb")
16
15
  end
17
16
 
18
- it "has number of lines" do
19
- expect(html).to include("50")
20
- end
21
-
22
- it "has blob contents" do
17
+ it "includes blob contents" do
23
18
  expect(html).to include("module Oneboxer")
24
19
  end
25
-
26
- it "has URL" do
27
- expect(html).to include(link)
28
- end
29
20
  end
30
21
  end
@@ -3,59 +3,51 @@ require "spec_helper"
3
3
  describe Onebox::Engine::GithubCommitOnebox do
4
4
  before(:all) do
5
5
  @link = "https://github.com/discourse/discourse/commit/803d023e2307309f8b776ab3b8b7e38ba91c0919"
6
- fake(@link, response(described_class.template_name))
6
+ @uri = "https://api.github.com/repos/discourse/discourse/commits/803d023e2307309f8b776ab3b8b7e38ba91c0919"
7
7
  end
8
- before(:each) { Onebox.defaults.cache.clear }
9
-
10
- let(:link) { @link }
11
8
 
9
+ include_context "engines"
12
10
  it_behaves_like "an engine"
13
11
 
14
12
  describe "#to_html" do
15
- let(:html) { described_class.new(link).to_html }
16
-
17
- it "has repo owner" do
13
+ it "includes owner" do
18
14
  expect(html).to include("discourse")
19
15
  end
20
16
 
21
- it "has repo name" do
17
+ it "includes repository name" do
22
18
  expect(html).to include("discourse")
23
19
  end
24
20
 
25
- it "has commit sha" do
21
+ it "includes commit sha" do
26
22
  expect(html).to include("803d023e2307309f8b776ab3b8b7e38ba91c0919")
27
23
  end
28
24
 
29
- it "has commit author gravatar" do
25
+ it "includes commit author gravatar" do
30
26
  expect(html).to include("2F7d3010c11d08cf990b7614d2c2ca9098.png")
31
27
  end
32
28
 
33
- it "has commit message" do
29
+ it "includes commit message" do
34
30
  expect(html).to include("Fixed GitHub auth")
35
31
  end
36
32
 
37
- it "has commit author" do
33
+ it "includes commit author" do
38
34
  expect(html).to include("SamSaffron")
39
35
  end
40
36
 
41
- it "has commit time and date" do
42
- expect(html).to include("2013-08-02T02:16:44Z")
37
+ it "includes commit time and date" do
38
+ expect(html).to include("02:03AM - 02 Aug 13")
43
39
  end
44
40
 
45
- it "has number of files changed" do
46
- expect(html).to include("1 changed file")
41
+ it "includes number of files changed" do
42
+ expect(html).to include("1 file")
47
43
  end
48
44
 
49
- it "has number of additions" do
45
+ it "includes number of additions" do
50
46
  expect(html).to include("18 additions")
51
47
  end
52
48
 
53
- it "has number of deletions" do
49
+ it "includes number of deletions" do
54
50
  expect(html).to include("2 deletions")
55
51
  end
56
-
57
- it "has URL" do
58
- expect(html).to include(link)
59
- end
60
52
  end
61
53
  end
@@ -3,27 +3,19 @@ require "spec_helper"
3
3
  describe Onebox::Engine::GithubGistOnebox do
4
4
  before(:all) do
5
5
  @link = "https://gist.github.com/anikalindtner/153044e9bea3331cc103"
6
- fake(@link, response(described_class.template_name))
6
+ @uri = "https://api.github.com/gists/153044e9bea3331cc103"
7
7
  end
8
- before(:each) { Onebox.defaults.cache.clear }
9
-
10
- let(:link) { @link }
11
8
 
9
+ include_context "engines"
12
10
  it_behaves_like "an engine"
13
11
 
14
12
  describe "#to_html" do
15
- let(:html) { described_class.new(link).to_html }
16
-
17
- it "has raw file contents" do
18
- expect(html).to include("# Create a new blog post on GitHub")
19
- end
20
-
21
- it "has author" do
22
- expect(html).to include("anikalindtner")
13
+ it "includes sha" do
14
+ expect(html).to include("153044e9bea3331cc103")
23
15
  end
24
16
 
25
- it "has URL" do
26
- expect(html).to include(link)
17
+ it "includes script" do
18
+ expect(html).to include("script")
27
19
  end
28
20
  end
29
21
  end
@@ -1,58 +1,46 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Onebox::Engine::GithubPullRequestOnebox do
4
- let(:link) { "https://github.com/discourse/discourse/pull/1253/" }
5
- before do
6
- fake(link, response("githubpullrequest"))
4
+ before(:all) do
5
+ @link = "https://github.com/discourse/discourse/pull/1253/"
6
+ @uri = "https://api.github.com/repos/discourse/discourse/pulls/1253"
7
+ fake(@uri, response(described_class.onebox_name))
7
8
  end
8
9
 
10
+ include_context "engines"
9
11
  it_behaves_like "an engine"
10
12
 
11
13
  describe "#to_html" do
12
- let(:html) { described_class.new(link).to_html }
13
-
14
- it "has pull request author" do
14
+ it "includes pull request author" do
15
15
  expect(html).to include("jamesaanderson")
16
16
  end
17
17
 
18
- it "has pull request title" do
19
- expect(html).to include("Add audio onebox")
20
- end
21
-
22
- it "has repo name" do
18
+ it "includes repository name" do
23
19
  expect(html).to include("discourse")
24
20
  end
25
21
 
26
- it "has commit author gravatar" do
22
+ it "includes commit author gravatar" do
27
23
  expect(html).to include("b3e9977094ce189bbb493cf7f9adea21")
28
24
  end
29
25
 
30
- it "has commit description" do
31
- expect(html).to include("8168")
26
+ it "includes commit time and date" do
27
+ expect(html).to include("02:05AM - 26 Jul 13")
32
28
  end
33
29
 
34
- it "has commit time and date" do
35
- expect(html).to include("2013-07-26T02:05:53Z")
36
- end
37
-
38
- it "has number of commits" do
30
+ it "includes number of commits" do
39
31
  expect(html).to include("1")
40
32
  end
41
33
 
42
- it "has number of files changed" do
34
+ it "includes number of files changed" do
43
35
  expect(html).to include("4")
44
36
  end
45
37
 
46
- it "has number of additions" do
38
+ it "includes number of additions" do
47
39
  expect(html).to include("19")
48
40
  end
49
41
 
50
- it "has number of deletions" do
42
+ it "includes number of deletions" do
51
43
  expect(html).to include("1")
52
44
  end
53
-
54
- it "has URL" do
55
- expect(html).to include(link)
56
- end
57
45
  end
58
46
  end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe Onebox::Engine::GooglePlayAppOnebox do
4
+ before(:all) do
5
+ @link = "https://play.google.com/store/apps/details?id=com.hulu.plus&hl=en"
6
+ end
7
+
8
+ include_context "engines"
9
+ it_behaves_like "an engine"
10
+
11
+ describe "#to_html" do
12
+ it "has developer" do
13
+ expect(html).to include("Hulu")
14
+ end
15
+
16
+ it "has image" do
17
+ expect(html).to include("JH08z41G8hlCw=w300-rw")
18
+ end
19
+
20
+ it "has description" do
21
+ expect(html).to include("Instantly watch current TV shows")
22
+ end
23
+
24
+ it "has price" do
25
+ expect(html).to include("Free")
26
+ end
27
+ end
28
+ end
@@ -2,12 +2,10 @@ require "spec_helper"
2
2
 
3
3
  describe Onebox::Engine::HTML do
4
4
  before(:all) do
5
- @link = "http://example.com"
6
- fake(@link, response("example"))
5
+ @link = "http://amazon.com"
6
+ fake(@link, response("amazon"))
7
7
  end
8
- before(:each) { Onebox.defaults.cache.clear }
9
-
10
- let(:link) { @link }
8
+ before(:each) { Onebox.options.cache.clear }
11
9
 
12
10
  describe "#raw" do
13
11
  class OneboxEngineHTML
@@ -20,7 +18,7 @@ describe Onebox::Engine::HTML do
20
18
  end
21
19
 
22
20
  it "returns a Nokogiri object that has a css method" do
23
- object = OneboxEngineHTML.new("http://example.com").send(:raw)
21
+ object = OneboxEngineHTML.new("http://amazon.com").send(:raw)
24
22
  expect(object).to respond_to(:css)
25
23
  end
26
24
  end
@@ -2,12 +2,10 @@ require "spec_helper"
2
2
 
3
3
  describe Onebox::Engine::JSON do
4
4
  before(:all) do
5
- @link = "http://gist.github.com"
6
- fake(@link, response("githubgist"))
5
+ @link = "http://stackoverflow.com"
6
+ fake(@link, response("stackexchange"))
7
7
  end
8
- before(:each) { Onebox.defaults.cache.clear }
9
-
10
- let(:link) { @link }
8
+ before(:each) { Onebox.options.cache.clear }
11
9
 
12
10
  describe "#raw" do
13
11
  class OneboxEngineJSON
@@ -20,7 +18,7 @@ describe Onebox::Engine::JSON do
20
18
  end
21
19
 
22
20
  it "returns a hash" do
23
- object = OneboxEngineJSON.new("http://gist.github.com").send(:raw)
21
+ object = OneboxEngineJSON.new(@link).send(:raw)
24
22
  expect(object).to be_a(Hash)
25
23
  end
26
24
  end
@@ -3,28 +3,15 @@ require "spec_helper"
3
3
  describe Onebox::Engine::StackExchangeOnebox do
4
4
  before(:all) do
5
5
  @link = "http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code"
6
- fake(@link, response(described_class.template_name))
6
+ fake("http://api.stackexchange.com/2.1/questions/17992553?site=stackoverflow", response(described_class.onebox_name))
7
7
  end
8
- before(:each) { Onebox.defaults.cache.clear }
9
-
10
- let(:link) { @link }
11
8
 
9
+ include_context "engines"
12
10
  it_behaves_like "an engine"
13
11
 
14
12
  describe "#to_html" do
15
- let(:html) { described_class.new(link).to_html }
16
-
17
- it "returns the question title" do
18
- expect(html).to include("Concept behind these 4 lines of tricky C++ code")
19
- end
20
-
21
- it "returns the question" do
22
- expect(html).to include("Why does this code gives output C++Sucks? Can anyone explain the concept behind it?")
23
- end
24
-
25
- it "returns the question URL" do
26
- expect(html).to include(link)
13
+ it "includes question" do
14
+ expect(html).to include("Concept behind these four lines of tricky C++ code")
27
15
  end
28
16
  end
29
17
  end
30
-
@@ -0,0 +1,103 @@
1
+ require "spec_helper"
2
+
3
+ describe Onebox::Engine::TwitterStatusOnebox do
4
+ before(:all) do
5
+ @link = "https://twitter.com/vyki_e/status/363116819147538433"
6
+ end
7
+
8
+ shared_examples_for "#to_html" do
9
+ it "includes tweet" do
10
+ expect(html).to include("I'm a sucker for pledges.")
11
+ end
12
+
13
+ it "includes timestamp" do
14
+ pending
15
+ expect(html).to include("6:59 PM - 1 Aug 13")
16
+ end
17
+
18
+ it "includes username" do
19
+ expect(html).to include("vyki_e")
20
+ end
21
+
22
+ it "includes user avatar" do
23
+ expect(html).to include("39b969d32a10b2437563e246708c8f9d_normal.jpeg")
24
+ end
25
+
26
+ it "includes tweet favorite count" do
27
+ pending
28
+ expect(html).to include("")
29
+ end
30
+
31
+ it "includes retweet count" do
32
+ pending
33
+ expect(html).to include("")
34
+ end
35
+ end
36
+
37
+ context "with html" do
38
+ include_context "engines"
39
+ it_behaves_like "an engine"
40
+ it_behaves_like "#to_html"
41
+ end
42
+
43
+ context "with twitter client" do
44
+ before(:each) do
45
+ @twitter_client = double("TwitterClient")
46
+ @twitter_client.stub("status") do
47
+ {
48
+ created_at: "Fri Aug 02 01:59:30 +0000 2013",
49
+ id: 363_116_819_147_538_433,
50
+ id_str: "363116819147538433",
51
+ text:
52
+ "I'm a sucker for pledges. @Peers Pledge #sharingeconomy http://t.co/T4Sc47KAzh",
53
+ source:
54
+ "<a href=\"http://twitter.com/tweetbutton\" rel=\"nofollow\">Tweet Button</a>",
55
+ user:
56
+ { id: 1_087_064_150,
57
+ id_str: "1087064150",
58
+ name: "Vyki Englert",
59
+ screen_name: "vyki_e",
60
+ location: "Los Angeles, CA",
61
+ description: "I am woman, hear me #RoR.",
62
+ url: "http://t.co/umZG76wmv2",
63
+ protected: false,
64
+ followers_count: 249,
65
+ friends_count: 907,
66
+ listed_count: 6,
67
+ created_at: "Sun Jan 13 19:53:00 +0000 2013",
68
+ favourites_count: 506,
69
+ statuses_count: 926,
70
+ lang: "en",
71
+ contributors_enabled: false,
72
+ is_translator: false,
73
+ profile_image_url:
74
+ "http://pbs.twimg.com/profile_images/3518892092/39b969d32a10b2437563e246708c8f9d_normal.jpeg",
75
+ profile_image_url_https:
76
+ "https://pbs.twimg.com/profile_images/3518892092/39b969d32a10b2437563e246708c8f9d_normal.jpeg",
77
+ following: true,
78
+ follow_request_sent: false,
79
+ notifications: nil },
80
+ geo: nil,
81
+ coordinates: nil,
82
+ place: nil,
83
+ contributors: nil,
84
+ retweet_count: 0,
85
+ favorite_count: 0,
86
+ favorited: false,
87
+ retweeted: false,
88
+ possibly_sensitive: false,
89
+ lang: "en"
90
+ }
91
+ end
92
+ Onebox.options = { twitter_client: @twitter_client }
93
+ end
94
+
95
+ after(:each) do
96
+ Onebox.options = { twitter_client: nil }
97
+ end
98
+
99
+ include_context "engines"
100
+ it_behaves_like "an engine"
101
+ it_behaves_like "#to_html"
102
+ end
103
+ end