wayfarer 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +1 -1
- data/Gemfile.lock +20 -15
- data/docs/cookbook/user_agent.md +1 -1
- data/docs/guides/browser_automation/capybara.md +64 -1
- data/docs/guides/browser_automation/custom_adapters.md +100 -0
- data/docs/guides/browser_automation/ferrum.md +3 -3
- data/docs/guides/browser_automation/selenium.md +7 -5
- data/docs/guides/callbacks.md +117 -10
- data/docs/guides/configuration.md +16 -10
- data/docs/guides/error_handling.md +9 -5
- data/docs/guides/networking.md +77 -3
- data/docs/index.md +9 -1
- data/docs/reference/api/base.md +4 -4
- data/docs/reference/configuration_keys.md +42 -0
- data/docs/reference/environment_variables.md +25 -27
- data/lib/wayfarer/base.rb +7 -17
- data/lib/wayfarer/callbacks.rb +71 -0
- data/lib/wayfarer/cli/base.rb +5 -1
- data/lib/wayfarer/cli/job.rb +7 -3
- data/lib/wayfarer/cli/route.rb +2 -2
- data/lib/wayfarer/cli/route_printer.rb +7 -7
- data/lib/wayfarer/config/capybara.rb +10 -0
- data/lib/wayfarer/config/ferrum.rb +11 -0
- data/lib/wayfarer/config/networking.rb +26 -0
- data/lib/wayfarer/config/redis.rb +14 -0
- data/lib/wayfarer/config/root.rb +11 -0
- data/lib/wayfarer/config/selenium.rb +21 -0
- data/lib/wayfarer/config/strconv.rb +45 -0
- data/lib/wayfarer/config/struct.rb +72 -0
- data/lib/wayfarer/gc.rb +3 -7
- data/lib/wayfarer/middleware/fetch.rb +7 -3
- data/lib/wayfarer/middleware/router.rb +2 -2
- data/lib/wayfarer/middleware/worker.rb +12 -9
- data/lib/wayfarer/networking/capybara.rb +28 -0
- data/lib/wayfarer/networking/context.rb +36 -0
- data/lib/wayfarer/networking/ferrum.rb +17 -52
- data/lib/wayfarer/networking/http.rb +34 -0
- data/lib/wayfarer/networking/pool.rb +15 -10
- data/lib/wayfarer/networking/result.rb +1 -1
- data/lib/wayfarer/networking/selenium.rb +20 -47
- data/lib/wayfarer/networking/strategy.rb +38 -0
- data/lib/wayfarer/page.rb +2 -3
- data/lib/wayfarer/redis/pool.rb +3 -1
- data/lib/wayfarer/routing/dsl.rb +8 -8
- data/lib/wayfarer/routing/matchers/custom.rb +23 -0
- data/lib/wayfarer/routing/matchers/host.rb +19 -0
- data/lib/wayfarer/routing/matchers/path.rb +48 -0
- data/lib/wayfarer/routing/matchers/query.rb +63 -0
- data/lib/wayfarer/routing/matchers/scheme.rb +17 -0
- data/lib/wayfarer/routing/matchers/suffix.rb +17 -0
- data/lib/wayfarer/routing/matchers/url.rb +17 -0
- data/lib/wayfarer/routing/route.rb +1 -1
- data/lib/wayfarer.rb +9 -9
- data/spec/base_spec.rb +14 -0
- data/spec/callbacks_spec.rb +102 -0
- data/spec/cli/job_spec.rb +6 -6
- data/spec/config/capybara_spec.rb +18 -0
- data/spec/config/ferrum_spec.rb +24 -0
- data/spec/config/networking_spec.rb +73 -0
- data/spec/config/redis_spec.rb +32 -0
- data/spec/config/root_spec.rb +31 -0
- data/spec/config/selenium_spec.rb +56 -0
- data/spec/config/strconv_spec.rb +58 -0
- data/spec/config/struct_spec.rb +66 -0
- data/spec/gc_spec.rb +8 -6
- data/spec/middleware/fetch_spec.rb +20 -8
- data/spec/middleware/router_spec.rb +7 -0
- data/spec/middleware/worker_spec.rb +64 -27
- data/spec/networking/capybara_spec.rb +12 -0
- data/spec/networking/context_spec.rb +127 -0
- data/spec/networking/ferrum_spec.rb +6 -22
- data/spec/networking/http_spec.rb +12 -0
- data/spec/networking/pool_spec.rb +37 -12
- data/spec/networking/selenium_spec.rb +6 -22
- data/spec/networking/strategy.rb +170 -0
- data/spec/redis/pool_spec.rb +1 -1
- data/spec/routing/dsl_spec.rb +10 -10
- data/spec/routing/integration_spec.rb +22 -22
- data/spec/routing/{custom_matcher_spec.rb → matchers/custom_spec.rb} +4 -4
- data/spec/routing/{host_matcher_spec.rb → matchers/host_spec.rb} +6 -6
- data/spec/routing/{path_matcher_spec.rb → matchers/path_spec.rb} +6 -6
- data/spec/routing/{query_matcher_spec.rb → matchers/query_spec.rb} +15 -15
- data/spec/routing/{scheme_matcher_spec.rb → matchers/scheme_spec.rb} +4 -4
- data/spec/routing/{suffix_matcher_spec.rb → matchers/suffix_spec.rb} +4 -4
- data/spec/routing/{uri_matcher_spec.rb → matchers/uri_spec.rb} +4 -4
- data/spec/routing/path_finder_spec.rb +1 -1
- data/spec/routing/root_route_spec.rb +2 -2
- data/spec/routing/route_spec.rb +2 -2
- data/spec/spec_helpers.rb +13 -5
- data/spec/wayfarer_spec.rb +1 -1
- data/wayfarer.gemspec +8 -7
- metadata +74 -33
- data/lib/wayfarer/config.rb +0 -67
- data/lib/wayfarer/networking/healer.rb +0 -21
- data/lib/wayfarer/networking/net_http.rb +0 -52
- data/lib/wayfarer/routing/custom_matcher.rb +0 -21
- data/lib/wayfarer/routing/host_matcher.rb +0 -23
- data/lib/wayfarer/routing/path_matcher.rb +0 -46
- data/lib/wayfarer/routing/query_matcher.rb +0 -67
- data/lib/wayfarer/routing/scheme_matcher.rb +0 -21
- data/lib/wayfarer/routing/suffix_matcher.rb +0 -21
- data/lib/wayfarer/routing/url_matcher.rb +0 -21
- data/spec/config_spec.rb +0 -144
- data/spec/networking/adapter.rb +0 -135
- data/spec/networking/healer_spec.rb +0 -46
- data/spec/networking/net_http_spec.rb +0 -37
data/spec/routing/dsl_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Wayfarer::Routing::DSL do
|
|
10
10
|
it "adds a child with an always-matching matcher" do
|
11
11
|
expect(root.to(:foobar)).to be_a(Wayfarer::Routing::Route)
|
12
12
|
expect(child.action).to be(:foobar)
|
13
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
13
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Custom)
|
14
14
|
expect(child.parent).to be(root)
|
15
15
|
|
16
16
|
%w[http://example.com http://w3c.org http://google.com].each do |url|
|
@@ -22,7 +22,7 @@ describe Wayfarer::Routing::DSL do
|
|
22
22
|
describe "#url" do
|
23
23
|
it "adds a child with an URL matcher" do
|
24
24
|
expect(root.url("http://example.com")).to be_a(Wayfarer::Routing::Route)
|
25
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
25
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::URL)
|
26
26
|
expect(child.matcher.url).to eq("http://example.com")
|
27
27
|
expect(child.parent).to be(root)
|
28
28
|
end
|
@@ -31,7 +31,7 @@ describe Wayfarer::Routing::DSL do
|
|
31
31
|
describe "#host" do
|
32
32
|
it "adds a child with a host matcher" do
|
33
33
|
expect(root.host("example.com")).to be_a(Wayfarer::Routing::Route)
|
34
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
34
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Host)
|
35
35
|
expect(child.matcher.host).to eq("example.com")
|
36
36
|
expect(child.parent).to be(root)
|
37
37
|
end
|
@@ -40,7 +40,7 @@ describe Wayfarer::Routing::DSL do
|
|
40
40
|
describe "#path" do
|
41
41
|
it "adds a child with a path matcher" do
|
42
42
|
expect(root.path("/foo/bar")).to be_a(Wayfarer::Routing::Route)
|
43
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
43
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Path)
|
44
44
|
expect(child.matcher.path).to eq("/foo/bar")
|
45
45
|
expect(child.parent).to be(root)
|
46
46
|
end
|
@@ -49,7 +49,7 @@ describe Wayfarer::Routing::DSL do
|
|
49
49
|
describe "#query" do
|
50
50
|
it "adds a child with a query matcher" do
|
51
51
|
expect(root.query(foo: "bar")).to be_a(Wayfarer::Routing::Route)
|
52
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
52
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Query)
|
53
53
|
expect(child.matcher.fields).to eq({ foo: "bar" })
|
54
54
|
expect(child.parent).to be(root)
|
55
55
|
end
|
@@ -58,7 +58,7 @@ describe Wayfarer::Routing::DSL do
|
|
58
58
|
describe "#scheme" do
|
59
59
|
it "adds a child with a scheme matcher" do
|
60
60
|
expect(root.scheme(:https)).to be_a(Wayfarer::Routing::Route)
|
61
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
61
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Scheme)
|
62
62
|
expect(child.matcher.scheme).to be(:https)
|
63
63
|
expect(child.parent).to be(root)
|
64
64
|
end
|
@@ -67,7 +67,7 @@ describe Wayfarer::Routing::DSL do
|
|
67
67
|
describe "#suffix" do
|
68
68
|
it "adds a child with a suffix matcher" do
|
69
69
|
expect(root.suffix(".png")).to be_a(Wayfarer::Routing::Route)
|
70
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
70
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Suffix)
|
71
71
|
expect(child.matcher.suffix).to eq(".png")
|
72
72
|
expect(child.parent).to be(root)
|
73
73
|
end
|
@@ -76,7 +76,7 @@ describe Wayfarer::Routing::DSL do
|
|
76
76
|
describe "#custom" do
|
77
77
|
it "adds a child with a custom matcher" do
|
78
78
|
expect(root.custom(->(_) { true })).to be_a(Wayfarer::Routing::Route)
|
79
|
-
expect(child.matcher).to be_a(Wayfarer::Routing::
|
79
|
+
expect(child.matcher).to be_a(Wayfarer::Routing::Matchers::Custom)
|
80
80
|
expect(child.matcher.delegate).to be_a(Proc)
|
81
81
|
expect(child.parent).to be(root)
|
82
82
|
end
|
@@ -89,10 +89,10 @@ describe Wayfarer::Routing::DSL do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
expect(root.children.count).to be(1)
|
92
|
-
expect(root.children.first.matcher).to be_a(Wayfarer::Routing::
|
92
|
+
expect(root.children.first.matcher).to be_a(Wayfarer::Routing::Matchers::Host)
|
93
93
|
|
94
94
|
expect(root.children.first.children.count).to be(1)
|
95
|
-
expect(root.children.first.children.first.matcher).to be_a(Wayfarer::Routing::
|
95
|
+
expect(root.children.first.children.first.matcher).to be_a(Wayfarer::Routing::Matchers::Path)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -8,17 +8,17 @@ describe Wayfarer::Routing::DSL do
|
|
8
8
|
it "matches URLs" do
|
9
9
|
route.path "/"
|
10
10
|
|
11
|
-
result = route.invoke(URI("https://example.com/"))
|
11
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/"))
|
12
12
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
13
13
|
|
14
|
-
result = route.invoke(URI("https://example.com/foo"))
|
14
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
15
15
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "matches URLs" do
|
19
19
|
route.host "example.com", path: "/foo"
|
20
20
|
|
21
|
-
result = route.invoke(URI("https://example.com/foo"))
|
21
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
22
22
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
23
23
|
end
|
24
24
|
|
@@ -27,16 +27,16 @@ describe Wayfarer::Routing::DSL do
|
|
27
27
|
query page: 1..10
|
28
28
|
end
|
29
29
|
|
30
|
-
result = route.invoke(URI("https://example.com/foo?page=4"))
|
30
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=4"))
|
31
31
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
32
32
|
|
33
|
-
result = route.invoke(URI("https://example.com/foo?page=11"))
|
33
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=11"))
|
34
34
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
35
35
|
|
36
|
-
result = route.invoke(URI("https://example.com/foo"))
|
36
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
37
37
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
38
38
|
|
39
|
-
result = route.invoke(URI("https://example.com?page=2"))
|
39
|
+
result = route.invoke(Addressable::URI.parse("https://example.com?page=2"))
|
40
40
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
41
41
|
end
|
42
42
|
|
@@ -45,16 +45,16 @@ describe Wayfarer::Routing::DSL do
|
|
45
45
|
query page: 1..10
|
46
46
|
end
|
47
47
|
|
48
|
-
result = route.invoke(URI("https://example.com/foo?page=4"))
|
48
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=4"))
|
49
49
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
50
50
|
|
51
|
-
result = route.invoke(URI("https://example.com/foo?page=11"))
|
51
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=11"))
|
52
52
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
53
53
|
|
54
|
-
result = route.invoke(URI("https://example.com/foo"))
|
54
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
55
55
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
56
56
|
|
57
|
-
result = route.invoke(URI("https://example.com?page=2"))
|
57
|
+
result = route.invoke(Addressable::URI.parse("https://example.com?page=2"))
|
58
58
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
59
59
|
end
|
60
60
|
|
@@ -64,19 +64,19 @@ describe Wayfarer::Routing::DSL do
|
|
64
64
|
path "/users/:id"
|
65
65
|
end
|
66
66
|
|
67
|
-
result = route.invoke(URI("https://example.com/contact"))
|
67
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/contact"))
|
68
68
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
69
69
|
|
70
|
-
result = route.invoke(URI("https://example.com/contact/foo"))
|
70
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/contact/foo"))
|
71
71
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
72
72
|
|
73
|
-
result = route.invoke(URI("https://example.com/users/123"))
|
73
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123"))
|
74
74
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
75
75
|
|
76
|
-
result = route.invoke(URI("https://example.com/users/123/images"))
|
76
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/images"))
|
77
77
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
78
78
|
|
79
|
-
result = route.invoke(URI("https://example.com/users"))
|
79
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users"))
|
80
80
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
81
81
|
end
|
82
82
|
|
@@ -89,22 +89,22 @@ describe Wayfarer::Routing::DSL do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
result = route.invoke(URI("https://example.com/contact"))
|
92
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/contact"))
|
93
93
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
94
94
|
|
95
|
-
result = route.invoke(URI("https://example.com/users/123"))
|
95
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123"))
|
96
96
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
97
97
|
|
98
|
-
result = route.invoke(URI("https://example.com/users/123/images/23"))
|
98
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/images/23"))
|
99
99
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
100
100
|
|
101
|
-
result = route.invoke(URI("https://example.com/users/123/images/23/foo"))
|
101
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/images/23/foo"))
|
102
102
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
103
103
|
|
104
|
-
result = route.invoke(URI("https://example.com/users/123/friends"))
|
104
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/friends"))
|
105
105
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
106
106
|
|
107
|
-
result = route.invoke(URI("https://example.com/users/123/foobar"))
|
107
|
+
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/foobar"))
|
108
108
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
109
109
|
end
|
110
110
|
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
6
|
-
let(:url) { URI("http://example.com") }
|
5
|
+
describe Wayfarer::Routing::Matchers::Custom do
|
6
|
+
let(:url) { Addressable::URI.parse("http://example.com") }
|
7
7
|
|
8
8
|
describe "#match" do
|
9
9
|
context "with a block" do
|
10
10
|
context "when block is truthy" do
|
11
11
|
subject(:matcher) do
|
12
|
-
Wayfarer::Routing::
|
12
|
+
Wayfarer::Routing::Matchers::Custom.new ->(_) { true }
|
13
13
|
end
|
14
14
|
|
15
15
|
it "returns true" do
|
@@ -19,7 +19,7 @@ describe Wayfarer::Routing::CustomMatcher do
|
|
19
19
|
|
20
20
|
context "when block is falsy" do
|
21
21
|
subject(:matcher) do
|
22
|
-
Wayfarer::Routing::
|
22
|
+
Wayfarer::Routing::Matchers::Custom.new ->(_) { false }
|
23
23
|
end
|
24
24
|
|
25
25
|
it "returns true" do
|
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
6
|
-
subject(:matcher) { Wayfarer::Routing::
|
5
|
+
describe Wayfarer::Routing::Matchers::Host do
|
6
|
+
subject(:matcher) { Wayfarer::Routing::Matchers::Host.new(str_or_regexp) }
|
7
7
|
|
8
8
|
describe "#matches?" do
|
9
9
|
describe "String matching" do
|
10
10
|
let(:str_or_regexp) { "example.com" }
|
11
11
|
|
12
12
|
context "with matching URL" do
|
13
|
-
let(:url) { URI("http://example.com/foo/bar") }
|
13
|
+
let(:url) { Addressable::URI.parse("http://example.com/foo/bar") }
|
14
14
|
|
15
15
|
it "returns true" do
|
16
16
|
expect(matcher).to match(url)
|
@@ -18,7 +18,7 @@ describe Wayfarer::Routing::HostMatcher do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
context "with mismatching URL" do
|
21
|
-
let(:url) { URI("http://google.com/bar/qux") }
|
21
|
+
let(:url) { Addressable::URI.parse("http://google.com/bar/qux") }
|
22
22
|
|
23
23
|
it "returns false" do
|
24
24
|
expect(matcher).not_to match(url)
|
@@ -30,7 +30,7 @@ describe Wayfarer::Routing::HostMatcher do
|
|
30
30
|
let(:str_or_regexp) { /example.com/ }
|
31
31
|
|
32
32
|
context "with matching URL" do
|
33
|
-
let(:url) { URI("http://sub.example.com") }
|
33
|
+
let(:url) { Addressable::URI.parse("http://sub.example.com") }
|
34
34
|
|
35
35
|
it "returns true" do
|
36
36
|
expect(matcher).to match(url)
|
@@ -38,7 +38,7 @@ describe Wayfarer::Routing::HostMatcher do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
context "with mismatching URL" do
|
41
|
-
let(:url) { URI("http://example.sub.com") }
|
41
|
+
let(:url) { Addressable::URI.parse("http://example.sub.com") }
|
42
42
|
|
43
43
|
it "returns false" do
|
44
44
|
expect(matcher).not_to match(url)
|
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
5
|
+
describe Wayfarer::Routing::Matchers::Path, mri: true do
|
6
6
|
let(:route) { Wayfarer::Routing::RootRoute.new }
|
7
|
-
subject(:matcher) { Wayfarer::Routing::
|
7
|
+
subject(:matcher) { Wayfarer::Routing::Matchers::Path.new(path, route) }
|
8
8
|
|
9
9
|
describe "#match?" do
|
10
10
|
context "with matching URL" do
|
11
11
|
let(:path) { "/{alpha}/{beta}" }
|
12
12
|
|
13
13
|
it "returns true" do
|
14
|
-
expect(matcher).to match(URI("http://example.com/foo/bar"))
|
14
|
+
expect(matcher).to match(Addressable::URI.parse("http://example.com/foo/bar"))
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -19,7 +19,7 @@ describe Wayfarer::Routing::PathMatcher, mri: true do
|
|
19
19
|
let(:path) { "/{alpha}/{beta}" }
|
20
20
|
|
21
21
|
it "returns false" do
|
22
|
-
expect(matcher).not_to match(URI("http://example.com/foo"))
|
22
|
+
expect(matcher).not_to match(Addressable::URI.parse("http://example.com/foo"))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,7 +27,7 @@ describe Wayfarer::Routing::PathMatcher, mri: true do
|
|
27
27
|
let(:path) { "/" }
|
28
28
|
|
29
29
|
it "returns false" do
|
30
|
-
expect(matcher).not_to match(URI("http://example.com/foo"))
|
30
|
+
expect(matcher).not_to match(Addressable::URI.parse("http://example.com/foo"))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -36,7 +36,7 @@ describe Wayfarer::Routing::PathMatcher, mri: true do
|
|
36
36
|
let(:path) { "/{alpha}/{beta}" }
|
37
37
|
|
38
38
|
it "returns the correct parameters" do
|
39
|
-
url = URI("http://example.com/foo/bar")
|
39
|
+
url = Addressable::URI.parse("http://example.com/foo/bar")
|
40
40
|
expect(matcher.params(url)).to eq("alpha" => "foo", "beta" => "bar")
|
41
41
|
end
|
42
42
|
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
6
|
-
subject(:matcher) { Wayfarer::Routing::
|
5
|
+
describe Wayfarer::Routing::Matchers::Query do
|
6
|
+
subject(:matcher) { Wayfarer::Routing::Matchers::Query.new(constraints) }
|
7
7
|
|
8
8
|
describe "String constraints" do
|
9
9
|
let(:constraints) { Hash[arg: "foo"] }
|
10
10
|
|
11
11
|
context "with matching query field value" do
|
12
|
-
let(:url) { URI("http://example.com?arg=foo") }
|
12
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
13
13
|
|
14
14
|
it "returns true" do
|
15
15
|
expect(matcher).to match(url)
|
@@ -17,7 +17,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context "with mismatching query field value" do
|
20
|
-
let(:url) { URI("http://example.com?arg=bar") }
|
20
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=bar") }
|
21
21
|
|
22
22
|
it "returns false" do
|
23
23
|
expect(matcher).not_to match(url)
|
@@ -29,7 +29,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
29
29
|
let(:constraints) { Hash[arg: 0] }
|
30
30
|
|
31
31
|
context "with matching query field value" do
|
32
|
-
let(:url) { URI("http://example.com?arg=0") }
|
32
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=0") }
|
33
33
|
|
34
34
|
it "returns true" do
|
35
35
|
expect(matcher).to match(url)
|
@@ -37,7 +37,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context "with mismatching query field value" do
|
40
|
-
let(:url) { URI("http://example.com?arg=1") }
|
40
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=1") }
|
41
41
|
|
42
42
|
it "returns false" do
|
43
43
|
expect(matcher).not_to match(url)
|
@@ -45,7 +45,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
context "with non-numeric query field value" do
|
48
|
-
let(:url) { URI("http://example.com?arg=foo") }
|
48
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
49
49
|
|
50
50
|
it "returns false" do
|
51
51
|
expect(matcher).not_to match(url)
|
@@ -57,7 +57,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
57
57
|
let(:constraints) { Hash[arg: /foo/] }
|
58
58
|
|
59
59
|
context "with matching query field value" do
|
60
|
-
let(:url) { URI("http://example.com?arg=foo") }
|
60
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
61
61
|
|
62
62
|
it "returns true" do
|
63
63
|
expect(matcher).to match(url)
|
@@ -65,7 +65,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
context "with mismatching query field value" do
|
68
|
-
let(:url) { URI("http://example.com?arg=bar") }
|
68
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=bar") }
|
69
69
|
|
70
70
|
it "returns false" do
|
71
71
|
expect(matcher).not_to match(url)
|
@@ -77,7 +77,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
77
77
|
let(:constraints) { Hash[arg: 1..10] }
|
78
78
|
|
79
79
|
context "with matching query field value" do
|
80
|
-
let(:url) { URI("http://example.com?arg=5") }
|
80
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=5") }
|
81
81
|
|
82
82
|
it "returns true" do
|
83
83
|
expect(matcher).to match(url)
|
@@ -85,7 +85,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
context "with mismatching query field value" do
|
88
|
-
let(:url) { URI("http://example.com?arg=11") }
|
88
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=11") }
|
89
89
|
|
90
90
|
it "returns false" do
|
91
91
|
expect(matcher).not_to match(url)
|
@@ -93,7 +93,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
context "with non-numeric query field value" do
|
96
|
-
let(:url) { URI("http://example.com?arg=foo") }
|
96
|
+
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
97
97
|
|
98
98
|
it "returns false" do
|
99
99
|
expect(matcher).not_to match(url)
|
@@ -107,7 +107,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
context "with matching query field values" do
|
110
|
-
let(:url) { URI("http://example.com?foo=4&bar=bazqux&qux=zot&toto=2") }
|
110
|
+
let(:url) { Addressable::URI.parse("http://example.com?foo=4&bar=bazqux&qux=zot&toto=2") }
|
111
111
|
|
112
112
|
it "returns true" do
|
113
113
|
expect(matcher).to match(url)
|
@@ -115,7 +115,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
context "with mismatching query field values" do
|
118
|
-
let(:url) { URI("http://example.com?foo=bar&bar=qux&qux=6toto=0") }
|
118
|
+
let(:url) { Addressable::URI.parse("http://example.com?foo=bar&bar=qux&qux=6toto=0") }
|
119
119
|
|
120
120
|
it "returns false" do
|
121
121
|
expect(matcher).not_to match(url)
|
@@ -129,7 +129,7 @@ describe Wayfarer::Routing::QueryMatcher do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "returns the correct parameters" do
|
132
|
-
url = URI("http://example.com?foo=4&bar=bazqux&qux=zot&toto=2")
|
132
|
+
url = Addressable::URI.parse("http://example.com?foo=4&bar=bazqux&qux=zot&toto=2")
|
133
133
|
expect(matcher.params(url)).to \
|
134
134
|
eq("foo" => "4", "bar" => "bazqux", "qux" => "zot", "toto" => "2")
|
135
135
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
5
|
+
describe Wayfarer::Routing::Matchers::Scheme do
|
6
6
|
describe "#match" do
|
7
|
-
subject(:matcher) { Wayfarer::Routing::
|
7
|
+
subject(:matcher) { Wayfarer::Routing::Matchers::Scheme.new(:http) }
|
8
8
|
|
9
9
|
context "with matching URL" do
|
10
|
-
let(:url) { URI("http://example.com") }
|
10
|
+
let(:url) { Addressable::URI.parse("http://example.com") }
|
11
11
|
|
12
12
|
it "returns true" do
|
13
13
|
expect(matcher).to match(url)
|
@@ -15,7 +15,7 @@ describe Wayfarer::Routing::SchemeMatcher do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
context "with mismatching URL" do
|
18
|
-
let(:url) { URI("https://example.com") }
|
18
|
+
let(:url) { Addressable::URI.parse("https://example.com") }
|
19
19
|
|
20
20
|
it "returns true" do
|
21
21
|
expect(matcher).not_to match(url)
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
6
|
-
subject(:matcher) { Wayfarer::Routing::
|
5
|
+
describe Wayfarer::Routing::Matchers::Suffix do
|
6
|
+
subject(:matcher) { Wayfarer::Routing::Matchers::Suffix.new(".png") }
|
7
7
|
|
8
8
|
describe "#match" do
|
9
9
|
context "with matching URL" do
|
@@ -13,7 +13,7 @@ describe Wayfarer::Routing::SuffixMatcher do
|
|
13
13
|
https://example.com/a/b.png/c.png
|
14
14
|
http://example.com/foobar.html.png
|
15
15
|
https://example.com/foo.png/bar.png
|
16
|
-
].map { |u| URI(u) }
|
16
|
+
].map { |u| Addressable::URI.parse(u) }
|
17
17
|
|
18
18
|
urls.each do |url|
|
19
19
|
expect(matcher).to match(url)
|
@@ -30,7 +30,7 @@ describe Wayfarer::Routing::SuffixMatcher do
|
|
30
30
|
http://example.com.html
|
31
31
|
http://example.com/foobar.html
|
32
32
|
https://example.com/foo.png/bar.png.html
|
33
|
-
].map { |u| URI(u) }
|
33
|
+
].map { |u| Addressable::URI.parse(u) }
|
34
34
|
|
35
35
|
urls.each do |url|
|
36
36
|
expect(matcher).not_to match(url)
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
|
-
describe Wayfarer::Routing::
|
5
|
+
describe Wayfarer::Routing::Matchers::URL do
|
6
6
|
subject(:matcher) do
|
7
|
-
Wayfarer::Routing::
|
7
|
+
Wayfarer::Routing::Matchers::URL.new("http://example.com/foo/bar")
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#match" do
|
11
11
|
context "with matching URL" do
|
12
|
-
let(:url) { URI("http://example.com/foo/bar") }
|
12
|
+
let(:url) { Addressable::URI.parse("http://example.com/foo/bar") }
|
13
13
|
|
14
14
|
it "returns true" do
|
15
15
|
expect(matcher).to match(url)
|
@@ -17,7 +17,7 @@ describe Wayfarer::Routing::URLMatcher do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context "with mismatching URL" do
|
20
|
-
let(:url) { URI("http://example.com/foo/qux") }
|
20
|
+
let(:url) { Addressable::URI.parse("http://example.com/foo/qux") }
|
21
21
|
|
22
22
|
it "returns true" do
|
23
23
|
expect(matcher).not_to match(url)
|
@@ -9,7 +9,7 @@ describe Wayfarer::Routing::PathFinder do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
subject(:result) { Wayfarer::Routing::PathFinder.result(route, URI(url)) }
|
12
|
+
subject(:result) { Wayfarer::Routing::PathFinder.result(route, Addressable::URI.parse(url)) }
|
13
13
|
|
14
14
|
describe "::result" do
|
15
15
|
context "with matching URL" do
|
@@ -13,7 +13,7 @@ describe Wayfarer::Routing::Route do
|
|
13
13
|
|
14
14
|
it "returns true" do
|
15
15
|
%w[http://example.com http://w3c.org http://google.com].each do |url|
|
16
|
-
expect(matcher).to match(URI(url))
|
16
|
+
expect(matcher).to match(Addressable::URI.parse(url))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -21,7 +21,7 @@ describe Wayfarer::Routing::Route do
|
|
21
21
|
context "without child routes" do
|
22
22
|
it "returns false" do
|
23
23
|
%w[http://example.com http://w3c.org http://google.com].each do |url|
|
24
|
-
expect(matcher).not_to match(URI(url))
|
24
|
+
expect(matcher).not_to match(Addressable::URI.parse(url))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/spec/routing/route_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Wayfarer::Routing::Route do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
result = root.invoke(URI("http://example.com/foo/bar?page=42"))
|
17
|
+
result = root.invoke(Addressable::URI.parse("http://example.com/foo/bar?page=42"))
|
18
18
|
|
19
19
|
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
20
20
|
expect(result.action).to be(:overrider)
|
@@ -34,7 +34,7 @@ describe Wayfarer::Routing::Route do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
result = root.invoke(URI("http://w3c.org/foo/bar?page=42"))
|
37
|
+
result = root.invoke(Addressable::URI.parse("http://w3c.org/foo/bar?page=42"))
|
38
38
|
|
39
39
|
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
40
40
|
end
|
data/spec/spec_helpers.rb
CHANGED
@@ -59,8 +59,8 @@ RSpec.configure do |config|
|
|
59
59
|
end
|
60
60
|
|
61
61
|
config.before do
|
62
|
-
Wayfarer.config = Wayfarer::Config.
|
63
|
-
Wayfarer.config.
|
62
|
+
Wayfarer.config = Wayfarer::Config::Root.new
|
63
|
+
Wayfarer.config.redis.url = redis_host
|
64
64
|
|
65
65
|
::Redis.new(url: redis_host).flushall
|
66
66
|
|
@@ -73,9 +73,17 @@ RSpec.configure do |config|
|
|
73
73
|
# For unknown reasons, Wayfarer::Networking::Ferrum#renew can take a very
|
74
74
|
# long time to instantiate a new ::Ferrum::Browser and requires the 60s
|
75
75
|
# timeout. TODO: Figure out what's going on
|
76
|
-
Wayfarer.config.
|
77
|
-
Wayfarer.config.
|
76
|
+
Wayfarer.config.ferrum.options = { url: "http://chrome:3000", timeout: 120 }
|
77
|
+
Wayfarer.config.selenium.driver = :firefox
|
78
|
+
Wayfarer.config.selenium.options = { url: "http://firefox:4444" }
|
79
|
+
Wayfarer.config.selenium.client_timeout = 10
|
78
80
|
end
|
81
|
+
|
82
|
+
# TODO: Undo side-effect
|
83
|
+
Capybara.register_driver(:cuprite) do |app|
|
84
|
+
Capybara::Cuprite::Driver.new(app, Wayfarer.config.ferrum.options)
|
85
|
+
end
|
86
|
+
Wayfarer.config.capybara.driver = :cuprite
|
79
87
|
end
|
80
88
|
|
81
89
|
config.around(cli: true) do |example|
|
@@ -83,7 +91,7 @@ RSpec.configure do |config|
|
|
83
91
|
tmp = Dir.mktmpdir
|
84
92
|
Dir.chdir(tmp)
|
85
93
|
example.run
|
86
|
-
FileUtils.rm_r(tmp)
|
87
94
|
Dir.chdir(origin)
|
95
|
+
FileUtils.rm_r(tmp)
|
88
96
|
end
|
89
97
|
end
|
data/spec/wayfarer_spec.rb
CHANGED