webmention 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe Webmention::Client do
4
- before do
5
- WebMock.stub_request(:any, 'http://source.example.com/post/100').to_return(
6
- :status => 200,
7
- :body => SampleData.sample_source_post_html,
8
- :headers => {}
9
- )
10
-
11
- @client = Webmention::Client.new "http://source.example.com/post/100"
12
- end
13
-
14
- describe "#crawl" do
15
- describe "when a valid url" do
16
- it "should return a count and list of links" do
17
- @client.crawl.must_be :>, 0
18
- @client.links.must_include 'http://target.example.com/post/4'
19
- @client.links.must_include 'http://target.example.com/post/5'
20
- end
21
- end
22
- end
23
- end
@@ -1,124 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe Webmention::Client do
4
- before do
5
- WebMock.stub_request(:any, 'http://example.com/header').to_return(
6
- :status => 200,
7
- :body => '<html>example</html>',
8
- :headers => {
9
- 'Link' => 'rel="webmention"; <http://webmention.io/example/webmention>'
10
- }
11
- )
12
-
13
- WebMock.stub_request(:any, 'http://example.com/html').to_return(
14
- :status => 200,
15
- :body => '<html><head><link rel="webmention" href="http://webmention.io/example/webmention"></head><body>example</body></html>'
16
- )
17
-
18
- WebMock.stub_request(:any, 'http://example.com/none').to_return(
19
- :status => 200,
20
- :body => '<html><head></head><body>example</body></html>'
21
- )
22
- end
23
-
24
- describe "#discover_webmention_endpoint_from_url" do
25
- it "should find endpoint from html head" do
26
- Webmention::Client.supports_webmention?("http://example.com/html").must_equal "http://webmention.io/example/webmention"
27
- end
28
-
29
- it "should find endpoint from http header" do
30
- Webmention::Client.supports_webmention?("http://example.com/header").must_equal "http://webmention.io/example/webmention"
31
- end
32
-
33
- it "should return false when no endpoint found" do
34
- Webmention::Client.supports_webmention?("http://example.com/none").must_equal false
35
- end
36
- end
37
-
38
- describe "#discover_webmention_endpoint_from_string" do
39
- it "should find rel=\"webmention\" followed by href in header" do
40
- Webmention::Client.discover_webmention_endpoint_from_header('rel="webmention"; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
41
- end
42
-
43
- it "should find rel=webmention followed by href in header" do
44
- Webmention::Client.discover_webmention_endpoint_from_header('rel=webmention; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
45
- end
46
-
47
- it "should find href followed by rel=\"webmention\" in header" do
48
- Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel="webmention"').must_equal "http://webmention.io/example/webmention"
49
- end
50
-
51
- it "should find href followed by rel=webmention in header" do
52
- Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel=webmention').must_equal "http://webmention.io/example/webmention"
53
- end
54
-
55
- it "should find rel=http://webmention.org followed by href in header" do
56
- Webmention::Client.discover_webmention_endpoint_from_header('rel="http://webmention.org"; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
57
- end
58
-
59
- it "should find href followed by rel=http://webmention.org in header" do
60
- Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel="http://webmention.org"').must_equal "http://webmention.io/example/webmention"
61
- end
62
-
63
- it "should find rel=http://webmention.org/ followed by href in header" do
64
- Webmention::Client.discover_webmention_endpoint_from_header('rel="http://webmention.org/"; <http://webmention.io/example/webmention>').must_equal "http://webmention.io/example/webmention"
65
- end
66
-
67
- it "should find href followed by rel=http://webmention.org/ in header" do
68
- Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel="http://webmention.org"').must_equal "http://webmention.io/example/webmention"
69
- end
70
-
71
- it "should find rel=webmention followed by href in html" do
72
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_href).must_equal "http://webmention.io/example/webmention"
73
- end
74
-
75
- it "should find href followed by rel=webmention in html" do
76
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_href_webmention).must_equal "http://webmention.io/example/webmention"
77
- end
78
-
79
- it "should find rel=http://webmention.org followed by href in html" do
80
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_org_href).must_equal "http://webmention.io/example/webmention"
81
- end
82
-
83
- it "should find href followed by rel=http://webmention.org in html" do
84
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_href_webmention_org).must_equal "http://webmention.io/example/webmention"
85
- end
86
-
87
- it "should find rel=http://webmention.org/ followed by href in html" do
88
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_org_slash_href).must_equal "http://webmention.io/example/webmention"
89
- end
90
-
91
- it "should find href followed by rel=http://webmention.org/ in html" do
92
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_href_webmention_org_slash).must_equal "http://webmention.io/example/webmention"
93
- end
94
-
95
- it "should find rel=webmention followed by relative href with path in header" do
96
- Webmention::Client.discover_webmention_endpoint_from_header('</example/webmention>; rel="http://webmention.org"').must_equal "/example/webmention"
97
- end
98
-
99
- it "should find rel=webmention followed by relative href with path in html" do
100
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_relative_with_path).must_equal "/example/webmention"
101
- end
102
-
103
- it "should find rel=webmention followed by relative href without path in header" do
104
- Webmention::Client.discover_webmention_endpoint_from_header('<webmention.php>; rel="http://webmention.org"').must_equal "webmention.php"
105
- end
106
-
107
- it "should find rel=webmention followed by relative href without path in html" do
108
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.rel_webmention_relative_without_path).must_equal "webmention.php"
109
- end
110
-
111
- it "should find webmention in a link tag among multiple rel values" do
112
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.link_tag_multiple_rel_values).must_equal "http://webmention.io/example/webmention"
113
- end
114
-
115
- it "should find webmention in a link header among multiple rel values" do
116
- Webmention::Client.discover_webmention_endpoint_from_header('<http://webmention.io/example/webmention>; rel="webmention foo bar"').must_equal "http://webmention.io/example/webmention"
117
- end
118
-
119
- it "should find rel=webmention in a link tag with an empty href" do
120
- Webmention::Client.discover_webmention_endpoint_from_html(SampleData.empty_link_tag_no_href).must_equal ""
121
- end
122
- end
123
-
124
- end
@@ -1,38 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe Webmention::Client do
4
- before do
5
- WebMock.stub_request(:any, 'http://source.example.com/post/100').to_return(
6
- :status => 202,
7
- :body => SampleData.sample_source_post_html,
8
- :headers => {}
9
- )
10
-
11
- WebMock.stub_request(:any, 'http://target.example.com/post/4').to_return(
12
- :status => 202,
13
- :body => SampleData.rel_webmention_href,
14
- :headers => {}
15
- )
16
-
17
- WebMock.stub_request(:any, 'http://target.example.com/post/5').to_return(
18
- :status => 202,
19
- :body => '',
20
- :headers => {
21
- 'Link' => 'rel="webmention"; <http://webmention.io/example/webmention>'
22
- }
23
- )
24
-
25
- WebMock.stub_request(:any, 'http://webmention.io/example/webmention').to_return(
26
- :status => 202
27
- )
28
-
29
- @client = Webmention::Client.new "http://source.example.com/post/100"
30
- end
31
-
32
- describe "#send_mentions" do
33
- it "should return number of mentions sent" do
34
- @client = Webmention::Client.new "http://source.example.com/post/100"
35
- @client.send_mentions.must_equal 2
36
- end
37
- end
38
- end
@@ -1,45 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe Webmention::Client do
4
- describe "#new" do
5
- describe "when a valid url" do
6
- it "should not throw an error for http" do
7
- client = Webmention::Client.new "http://google.com"
8
- client.url.must_equal URI.parse("http://google.com")
9
- end
10
-
11
- it "should not throw an error for https" do
12
- client = Webmention::Client.new "https://google.com"
13
- client.url.must_equal URI.parse("https://google.com")
14
- end
15
- end
16
-
17
- describe "when an invalid url" do
18
- it "should raise an error for ftp" do
19
- lambda do
20
- Webmention::Client.new "ftp://google.com"
21
- end.must_raise(ArgumentError)
22
- end
23
-
24
- it "should raise an error for no protocol" do
25
- lambda do
26
- Webmention::Client.new "google.com"
27
- end.must_raise(ArgumentError)
28
- end
29
- end
30
- end
31
-
32
- describe "#absolute_endpoint" do
33
- it "should expand an endpoint url with a path to an absolute url based on the webmention url" do
34
- Webmention::Client.absolute_endpoint('/webmention', 'http://webmention.io/example/1').must_equal "http://webmention.io/webmention"
35
- end
36
-
37
- it "should expand an endpoint url without a path to an absolute url based on the webmention url" do
38
- Webmention::Client.absolute_endpoint('webmention.php', 'http://webmention.io/example/1').must_equal "http://webmention.io/example/webmention.php"
39
- end
40
-
41
- it "should take an empty endpoint url and return the webmention url" do
42
- Webmention::Client.absolute_endpoint('', 'http://webmention.io/example/1').must_equal "http://webmention.io/example/1"
43
- end
44
- end
45
- end
@@ -1,9 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe Webmention do
4
-
5
- it "must be defined" do
6
- Webmention::VERSION.wont_be_nil
7
- end
8
-
9
- end
@@ -1,5 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'webmock/minitest'
3
-
4
- require File.expand_path('../../lib/webmention.rb', __FILE__)
5
- require File.expand_path('../data/sample_html.rb', __FILE__)