wayfarer 0.4.6 → 0.4.8
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/.env +17 -0
- data/.github/workflows/lint.yaml +27 -0
- data/.github/workflows/release.yaml +30 -0
- data/.github/workflows/tests.yaml +21 -0
- data/.gitignore +5 -1
- data/.rubocop.yml +36 -0
- data/.vale.ini +8 -0
- data/.yardopts +1 -3
- data/Dockerfile +6 -4
- data/Gemfile +24 -0
- data/Gemfile.lock +274 -164
- data/Rakefile +7 -51
- data/bin/wayfarer +1 -1
- data/docker-compose.yml +23 -13
- data/docs/cookbook/consent_screen.md +2 -2
- data/docs/cookbook/executing_javascript.md +3 -3
- data/docs/cookbook/navigation.md +12 -12
- data/docs/cookbook/querying_html.md +3 -3
- data/docs/cookbook/screenshots.md +2 -2
- data/docs/guides/callbacks.md +25 -125
- data/docs/guides/cli.md +71 -0
- data/docs/guides/configuration.md +10 -35
- data/docs/guides/development.md +67 -0
- data/docs/guides/handlers.md +60 -0
- data/docs/guides/index.md +1 -0
- data/docs/guides/jobs.md +142 -31
- data/docs/guides/navigation.md +1 -1
- data/docs/guides/networking/capybara.md +13 -22
- data/docs/guides/networking/custom_adapters.md +103 -41
- data/docs/guides/networking/ferrum.md +4 -4
- data/docs/guides/networking/http.md +9 -13
- data/docs/guides/networking/selenium.md +10 -11
- data/docs/guides/pages.md +78 -10
- data/docs/guides/redis.md +10 -0
- data/docs/guides/routing.md +156 -0
- data/docs/guides/tasks.md +53 -9
- data/docs/guides/tutorial.md +66 -0
- data/docs/guides/user_agents.md +115 -0
- data/docs/index.md +17 -40
- data/lib/wayfarer/base.rb +125 -46
- data/lib/wayfarer/batch_completion.rb +60 -0
- data/lib/wayfarer/callbacks.rb +22 -48
- data/lib/wayfarer/cli/route_printer.rb +85 -89
- data/lib/wayfarer/cli.rb +103 -0
- data/lib/wayfarer/gc.rb +18 -6
- data/lib/wayfarer/handler.rb +15 -7
- data/lib/wayfarer/kv.rb +28 -0
- data/lib/wayfarer/logging.rb +38 -0
- data/lib/wayfarer/middleware/base.rb +2 -0
- data/lib/wayfarer/middleware/batch_completion.rb +19 -0
- data/lib/wayfarer/middleware/chain.rb +7 -1
- data/lib/wayfarer/middleware/content_type.rb +59 -0
- data/lib/wayfarer/middleware/controller.rb +19 -15
- data/lib/wayfarer/middleware/dedup.rb +22 -13
- data/lib/wayfarer/middleware/dispatch.rb +17 -4
- data/lib/wayfarer/middleware/normalize.rb +7 -14
- data/lib/wayfarer/middleware/redis.rb +15 -0
- data/lib/wayfarer/middleware/router.rb +33 -35
- data/lib/wayfarer/middleware/stage.rb +5 -5
- data/lib/wayfarer/middleware/uri_parser.rb +31 -0
- data/lib/wayfarer/middleware/user_agent.rb +49 -0
- data/lib/wayfarer/networking/capybara.rb +1 -1
- data/lib/wayfarer/networking/context.rb +14 -3
- data/lib/wayfarer/networking/ferrum.rb +1 -4
- data/lib/wayfarer/networking/follow.rb +14 -7
- data/lib/wayfarer/networking/http.rb +1 -1
- data/lib/wayfarer/networking/pool.rb +23 -13
- data/lib/wayfarer/networking/selenium.rb +15 -7
- data/lib/wayfarer/networking/strategy.rb +2 -2
- data/lib/wayfarer/page.rb +34 -14
- data/lib/wayfarer/parsing/xml.rb +6 -6
- data/lib/wayfarer/parsing.rb +21 -0
- data/lib/wayfarer/redis/barrier.rb +26 -21
- data/lib/wayfarer/redis/counter.rb +18 -9
- data/lib/wayfarer/redis/pool.rb +1 -1
- data/lib/wayfarer/redis/resettable.rb +19 -0
- data/lib/wayfarer/routing/dsl.rb +166 -30
- data/lib/wayfarer/routing/hash_stack.rb +33 -0
- data/lib/wayfarer/routing/matchers/custom.rb +8 -5
- data/lib/wayfarer/routing/matchers/{suffix.rb → empty_params.rb} +2 -6
- data/lib/wayfarer/routing/matchers/host.rb +15 -9
- data/lib/wayfarer/routing/matchers/path.rb +11 -31
- data/lib/wayfarer/routing/matchers/query.rb +41 -17
- data/lib/wayfarer/routing/matchers/result.rb +12 -0
- data/lib/wayfarer/routing/matchers/scheme.rb +13 -5
- data/lib/wayfarer/routing/matchers/url.rb +13 -5
- data/lib/wayfarer/routing/path_consumer.rb +130 -0
- data/lib/wayfarer/routing/path_finder.rb +151 -23
- data/lib/wayfarer/routing/result.rb +1 -1
- data/lib/wayfarer/routing/root_route.rb +17 -1
- data/lib/wayfarer/routing/route.rb +66 -19
- data/lib/wayfarer/routing/serializable.rb +28 -0
- data/lib/wayfarer/routing/sub_route.rb +53 -0
- data/lib/wayfarer/routing/target_route.rb +17 -1
- data/lib/wayfarer/stringify.rb +21 -30
- data/lib/wayfarer/task.rb +9 -17
- data/lib/wayfarer/uri/normalization.rb +120 -0
- data/lib/wayfarer.rb +72 -5
- data/mise.toml +2 -0
- data/mkdocs.yml +44 -8
- data/rake/docs.rake +26 -0
- data/rake/lint.rake +9 -0
- data/rake/release.rake +23 -0
- data/rake/tests.rake +32 -0
- data/requirements.txt +1 -1
- data/spec/factories/job.rb +8 -0
- data/spec/factories/middleware.rb +2 -2
- data/spec/factories/path_finder.rb +11 -0
- data/spec/factories/redis.rb +19 -0
- data/spec/factories/task.rb +46 -2
- data/spec/spec_helpers.rb +55 -51
- data/spec/support/active_job_helpers.rb +8 -0
- data/spec/support/integration_helpers.rb +21 -0
- data/spec/support/redis_helpers.rb +9 -0
- data/spec/support/test_app.rb +66 -37
- data/spec/wayfarer/base_spec.rb +200 -0
- data/spec/wayfarer/batch_completion_spec.rb +142 -0
- data/spec/wayfarer/cli/job_spec.rb +88 -0
- data/spec/wayfarer/cli/routing_spec.rb +322 -0
- data/spec/{cli → wayfarer/cli}/version_spec.rb +1 -1
- data/spec/wayfarer/gc_spec.rb +29 -0
- data/spec/wayfarer/handler_spec.rb +9 -0
- data/spec/wayfarer/integration/callbacks_spec.rb +200 -0
- data/spec/wayfarer/integration/content_type_spec.rb +37 -0
- data/spec/wayfarer/integration/custom_routing_spec.rb +51 -0
- data/spec/wayfarer/integration/gc_spec.rb +40 -0
- data/spec/wayfarer/integration/handler_spec.rb +65 -0
- data/spec/wayfarer/integration/page_spec.rb +79 -0
- data/spec/wayfarer/integration/params_spec.rb +64 -0
- data/spec/wayfarer/integration/parsing_spec.rb +99 -0
- data/spec/wayfarer/integration/retry_spec.rb +112 -0
- data/spec/wayfarer/integration/stage_spec.rb +58 -0
- data/spec/wayfarer/middleware/batch_completion_spec.rb +33 -0
- data/spec/{middleware → wayfarer/middleware}/chain_spec.rb +24 -19
- data/spec/wayfarer/middleware/content_type_spec.rb +83 -0
- data/spec/{middleware → wayfarer/middleware}/controller_spec.rb +24 -22
- data/spec/wayfarer/middleware/dedup_spec.rb +66 -0
- data/spec/wayfarer/middleware/normalize_spec.rb +32 -0
- data/spec/wayfarer/middleware/router_spec.rb +102 -0
- data/spec/wayfarer/middleware/stage_spec.rb +63 -0
- data/spec/wayfarer/middleware/uri_parser_spec.rb +63 -0
- data/spec/wayfarer/middleware/user_agent_spec.rb +158 -0
- data/spec/wayfarer/networking/capybara_spec.rb +13 -0
- data/spec/{networking → wayfarer/networking}/context_spec.rb +46 -38
- data/spec/wayfarer/networking/ferrum_spec.rb +13 -0
- data/spec/{networking → wayfarer/networking}/follow_spec.rb +11 -6
- data/spec/wayfarer/networking/http_spec.rb +12 -0
- data/spec/{networking → wayfarer/networking}/pool_spec.rb +16 -14
- data/spec/wayfarer/networking/selenium_spec.rb +12 -0
- data/spec/{networking → wayfarer/networking}/strategy.rb +33 -54
- data/spec/wayfarer/page_spec.rb +69 -0
- data/spec/{parsing → wayfarer/parsing}/json_spec.rb +1 -1
- data/spec/wayfarer/parsing/xml_parse_spec.rb +25 -0
- data/spec/wayfarer/redis/barrier_spec.rb +39 -0
- data/spec/wayfarer/redis/counter_spec.rb +34 -0
- data/spec/{redis → wayfarer/redis}/pool_spec.rb +4 -3
- data/spec/{routing → wayfarer/routing}/dsl_spec.rb +12 -22
- data/spec/wayfarer/routing/hash_stack_spec.rb +63 -0
- data/spec/wayfarer/routing/integration_spec.rb +101 -0
- data/spec/wayfarer/routing/matchers/custom_spec.rb +39 -0
- data/spec/wayfarer/routing/matchers/host_spec.rb +56 -0
- data/spec/wayfarer/routing/matchers/matcher.rb +17 -0
- data/spec/wayfarer/routing/matchers/path_spec.rb +43 -0
- data/spec/wayfarer/routing/matchers/query_spec.rb +123 -0
- data/spec/wayfarer/routing/matchers/scheme_spec.rb +45 -0
- data/spec/wayfarer/routing/matchers/url_spec.rb +33 -0
- data/spec/wayfarer/routing/path_consumer_spec.rb +123 -0
- data/spec/wayfarer/routing/path_finder_spec.rb +409 -0
- data/spec/wayfarer/routing/root_route_spec.rb +51 -0
- data/spec/wayfarer/routing/route_spec.rb +74 -0
- data/spec/wayfarer/routing/sub_route_spec.rb +103 -0
- data/spec/wayfarer/task_spec.rb +13 -0
- data/spec/wayfarer/uri/normalization_spec.rb +98 -0
- data/spec/wayfarer_spec.rb +2 -2
- data/wayfarer.gemspec +18 -28
- metadata +797 -265
- data/.github/workflows/ci.yaml +0 -32
- data/.rbenv-gemsets +0 -1
- data/.ruby-version +0 -1
- data/RELEASING.md +0 -17
- data/docs/cookbook/user_agent.md +0 -7
- data/docs/guides/error_handling.md +0 -53
- data/docs/guides/networking.md +0 -94
- data/docs/guides/performance.md +0 -130
- data/docs/guides/reliability.md +0 -41
- data/docs/guides/routing/steering.md +0 -30
- data/docs/reference/api/base.md +0 -48
- data/docs/reference/cli.md +0 -61
- data/docs/reference/configuration_keys.md +0 -43
- data/docs/reference/environment_variables.md +0 -83
- data/lib/wayfarer/cli/base.rb +0 -45
- data/lib/wayfarer/cli/generate.rb +0 -17
- data/lib/wayfarer/cli/job.rb +0 -56
- data/lib/wayfarer/cli/route.rb +0 -29
- data/lib/wayfarer/cli/runner.rb +0 -34
- data/lib/wayfarer/cli/templates/Gemfile.tt +0 -5
- data/lib/wayfarer/cli/templates/job.rb.tt +0 -10
- data/lib/wayfarer/config/capybara.rb +0 -10
- data/lib/wayfarer/config/ferrum.rb +0 -11
- data/lib/wayfarer/config/networking.rb +0 -29
- data/lib/wayfarer/config/redis.rb +0 -14
- data/lib/wayfarer/config/root.rb +0 -11
- data/lib/wayfarer/config/selenium.rb +0 -21
- data/lib/wayfarer/config/strconv.rb +0 -45
- data/lib/wayfarer/config/struct.rb +0 -72
- data/lib/wayfarer/middleware/fetch.rb +0 -56
- data/lib/wayfarer/redis/connection.rb +0 -13
- data/lib/wayfarer/redis/version.rb +0 -19
- data/lib/wayfarer/routing/router.rb +0 -28
- data/spec/base_spec.rb +0 -224
- data/spec/callbacks_spec.rb +0 -102
- data/spec/cli/generate_spec.rb +0 -39
- data/spec/cli/job_spec.rb +0 -78
- data/spec/config/capybara_spec.rb +0 -18
- data/spec/config/ferrum_spec.rb +0 -24
- data/spec/config/networking_spec.rb +0 -73
- data/spec/config/redis_spec.rb +0 -32
- data/spec/config/root_spec.rb +0 -31
- data/spec/config/selenium_spec.rb +0 -56
- data/spec/config/strconv_spec.rb +0 -58
- data/spec/config/struct_spec.rb +0 -66
- data/spec/fixtures/dummy_job.rb +0 -7
- data/spec/gc_spec.rb +0 -59
- data/spec/handler_spec.rb +0 -11
- data/spec/integration/callbacks_spec.rb +0 -85
- data/spec/integration/page_spec.rb +0 -62
- data/spec/integration/params_spec.rb +0 -56
- data/spec/integration/stage_spec.rb +0 -51
- data/spec/integration/steering_spec.rb +0 -57
- data/spec/middleware/dedup_spec.rb +0 -88
- data/spec/middleware/dispatch_spec.rb +0 -43
- data/spec/middleware/fetch_spec.rb +0 -155
- data/spec/middleware/normalize_spec.rb +0 -29
- data/spec/middleware/router_spec.rb +0 -105
- data/spec/middleware/stage_spec.rb +0 -62
- data/spec/networking/capybara_spec.rb +0 -12
- data/spec/networking/ferrum_spec.rb +0 -12
- data/spec/networking/http_spec.rb +0 -12
- data/spec/networking/selenium_spec.rb +0 -12
- data/spec/page_spec.rb +0 -47
- data/spec/parsing/xml_spec.rb +0 -25
- data/spec/redis/barrier_spec.rb +0 -78
- data/spec/redis/counter_spec.rb +0 -32
- data/spec/redis/version_spec.rb +0 -13
- data/spec/routing/integration_spec.rb +0 -110
- data/spec/routing/matchers/custom_spec.rb +0 -31
- data/spec/routing/matchers/host_spec.rb +0 -49
- data/spec/routing/matchers/path_spec.rb +0 -43
- data/spec/routing/matchers/query_spec.rb +0 -137
- data/spec/routing/matchers/scheme_spec.rb +0 -25
- data/spec/routing/matchers/suffix_spec.rb +0 -41
- data/spec/routing/matchers/uri_spec.rb +0 -27
- data/spec/routing/path_finder_spec.rb +0 -33
- data/spec/routing/root_route_spec.rb +0 -29
- data/spec/routing/route_spec.rb +0 -43
- data/spec/routing/router_spec.rb +0 -24
- data/spec/task_spec.rb +0 -34
- data/spec/{stringify_spec.rb → wayfarer/stringify_spec.rb} +2 -2
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::DSL do
|
6
|
-
let(:route) { Wayfarer::Routing::RootRoute.new }
|
7
|
-
|
8
|
-
it "matches URLs" do
|
9
|
-
route.path "/"
|
10
|
-
|
11
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/"))
|
12
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
13
|
-
|
14
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
15
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "matches URLs" do
|
19
|
-
route.host "example.com", path: "/foo"
|
20
|
-
|
21
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
22
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "matches URLs" do
|
26
|
-
route.host "example.com", path: "/foo" do
|
27
|
-
query page: 1..10
|
28
|
-
end
|
29
|
-
|
30
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=4"))
|
31
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
32
|
-
|
33
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=11"))
|
34
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
35
|
-
|
36
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
37
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
38
|
-
|
39
|
-
result = route.invoke(Addressable::URI.parse("https://example.com?page=2"))
|
40
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "matches URLs" do
|
44
|
-
route.host "example.com", path: "/foo" do
|
45
|
-
query page: 1..10
|
46
|
-
end
|
47
|
-
|
48
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=4"))
|
49
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
50
|
-
|
51
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo?page=11"))
|
52
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
53
|
-
|
54
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/foo"))
|
55
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
56
|
-
|
57
|
-
result = route.invoke(Addressable::URI.parse("https://example.com?page=2"))
|
58
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "matches URLs" do
|
62
|
-
route.host "example.com" do
|
63
|
-
path "/contact"
|
64
|
-
path "/users/:id"
|
65
|
-
end
|
66
|
-
|
67
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/contact"))
|
68
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
69
|
-
|
70
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/contact/foo"))
|
71
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
72
|
-
|
73
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123"))
|
74
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
75
|
-
|
76
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/images"))
|
77
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
78
|
-
|
79
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users"))
|
80
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "matches URLs" do
|
84
|
-
route.host "example.com" do
|
85
|
-
path "/contact"
|
86
|
-
path "/users/:user_id" do
|
87
|
-
path "/images/:id"
|
88
|
-
path "/friends"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/contact"))
|
93
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
94
|
-
|
95
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123"))
|
96
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
97
|
-
|
98
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/images/23"))
|
99
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
100
|
-
|
101
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/images/23/foo"))
|
102
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
103
|
-
|
104
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/friends"))
|
105
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
106
|
-
|
107
|
-
result = route.invoke(Addressable::URI.parse("https://example.com/users/123/foobar"))
|
108
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
109
|
-
end
|
110
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::Custom do
|
6
|
-
let(:url) { Addressable::URI.parse("http://example.com") }
|
7
|
-
|
8
|
-
describe "#match" do
|
9
|
-
context "with a block" do
|
10
|
-
context "when block is truthy" do
|
11
|
-
subject(:matcher) do
|
12
|
-
Wayfarer::Routing::Matchers::Custom.new ->(_) { true }
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns true" do
|
16
|
-
expect(matcher).to match(url)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when block is falsy" do
|
21
|
-
subject(:matcher) do
|
22
|
-
Wayfarer::Routing::Matchers::Custom.new ->(_) { false }
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns true" do
|
26
|
-
expect(matcher).not_to match(url)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::Host do
|
6
|
-
subject(:matcher) { Wayfarer::Routing::Matchers::Host.new(str_or_regexp) }
|
7
|
-
|
8
|
-
describe "#matches?" do
|
9
|
-
describe "String matching" do
|
10
|
-
let(:str_or_regexp) { "example.com" }
|
11
|
-
|
12
|
-
context "with matching URL" do
|
13
|
-
let(:url) { Addressable::URI.parse("http://example.com/foo/bar") }
|
14
|
-
|
15
|
-
it "returns true" do
|
16
|
-
expect(matcher).to match(url)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "with mismatching URL" do
|
21
|
-
let(:url) { Addressable::URI.parse("http://google.com/bar/qux") }
|
22
|
-
|
23
|
-
it "returns false" do
|
24
|
-
expect(matcher).not_to match(url)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "RegExp matching" do
|
30
|
-
let(:str_or_regexp) { /example.com/ }
|
31
|
-
|
32
|
-
context "with matching URL" do
|
33
|
-
let(:url) { Addressable::URI.parse("http://sub.example.com") }
|
34
|
-
|
35
|
-
it "returns true" do
|
36
|
-
expect(matcher).to match(url)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with mismatching URL" do
|
41
|
-
let(:url) { Addressable::URI.parse("http://example.sub.com") }
|
42
|
-
|
43
|
-
it "returns false" do
|
44
|
-
expect(matcher).not_to match(url)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::Path, mri: true do
|
6
|
-
let(:route) { Wayfarer::Routing::RootRoute.new }
|
7
|
-
subject(:matcher) { Wayfarer::Routing::Matchers::Path.new(path, route) }
|
8
|
-
|
9
|
-
describe "#match?" do
|
10
|
-
context "with matching URL" do
|
11
|
-
let(:path) { "/{alpha}/{beta}" }
|
12
|
-
|
13
|
-
it "returns true" do
|
14
|
-
expect(matcher).to match(Addressable::URI.parse("http://example.com/foo/bar"))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with mismatching URL" do
|
19
|
-
let(:path) { "/{alpha}/{beta}" }
|
20
|
-
|
21
|
-
it "returns false" do
|
22
|
-
expect(matcher).not_to match(Addressable::URI.parse("http://example.com/foo"))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with mismatching URL" do
|
27
|
-
let(:path) { "/" }
|
28
|
-
|
29
|
-
it "returns false" do
|
30
|
-
expect(matcher).not_to match(Addressable::URI.parse("http://example.com/foo"))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#params" do
|
36
|
-
let(:path) { "/{alpha}/{beta}" }
|
37
|
-
|
38
|
-
it "returns the correct parameters" do
|
39
|
-
url = Addressable::URI.parse("http://example.com/foo/bar")
|
40
|
-
expect(matcher.params(url)).to eq("alpha" => "foo", "beta" => "bar")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::Query do
|
6
|
-
subject(:matcher) { Wayfarer::Routing::Matchers::Query.new(constraints) }
|
7
|
-
|
8
|
-
describe "String constraints" do
|
9
|
-
let(:constraints) { Hash[arg: "foo"] }
|
10
|
-
|
11
|
-
context "with matching query field value" do
|
12
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
13
|
-
|
14
|
-
it "returns true" do
|
15
|
-
expect(matcher).to match(url)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with mismatching query field value" do
|
20
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=bar") }
|
21
|
-
|
22
|
-
it "returns false" do
|
23
|
-
expect(matcher).not_to match(url)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "Integer constraints" do
|
29
|
-
let(:constraints) { Hash[arg: 0] }
|
30
|
-
|
31
|
-
context "with matching query field value" do
|
32
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=0") }
|
33
|
-
|
34
|
-
it "returns true" do
|
35
|
-
expect(matcher).to match(url)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with mismatching query field value" do
|
40
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=1") }
|
41
|
-
|
42
|
-
it "returns false" do
|
43
|
-
expect(matcher).not_to match(url)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "with non-numeric query field value" do
|
48
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
49
|
-
|
50
|
-
it "returns false" do
|
51
|
-
expect(matcher).not_to match(url)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "Regexp constraints" do
|
57
|
-
let(:constraints) { Hash[arg: /foo/] }
|
58
|
-
|
59
|
-
context "with matching query field value" do
|
60
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
61
|
-
|
62
|
-
it "returns true" do
|
63
|
-
expect(matcher).to match(url)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "with mismatching query field value" do
|
68
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=bar") }
|
69
|
-
|
70
|
-
it "returns false" do
|
71
|
-
expect(matcher).not_to match(url)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "Range constraints" do
|
77
|
-
let(:constraints) { Hash[arg: 1..10] }
|
78
|
-
|
79
|
-
context "with matching query field value" do
|
80
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=5") }
|
81
|
-
|
82
|
-
it "returns true" do
|
83
|
-
expect(matcher).to match(url)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "with mismatching query field value" do
|
88
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=11") }
|
89
|
-
|
90
|
-
it "returns false" do
|
91
|
-
expect(matcher).not_to match(url)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "with non-numeric query field value" do
|
96
|
-
let(:url) { Addressable::URI.parse("http://example.com?arg=foo") }
|
97
|
-
|
98
|
-
it "returns false" do
|
99
|
-
expect(matcher).not_to match(url)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "Compound constraints" do
|
105
|
-
let(:constraints) do
|
106
|
-
Hash[foo: 1..5, bar: /baz/, qux: "zot", toto: 2]
|
107
|
-
end
|
108
|
-
|
109
|
-
context "with matching query field values" do
|
110
|
-
let(:url) { Addressable::URI.parse("http://example.com?foo=4&bar=bazqux&qux=zot&toto=2") }
|
111
|
-
|
112
|
-
it "returns true" do
|
113
|
-
expect(matcher).to match(url)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "with mismatching query field values" do
|
118
|
-
let(:url) { Addressable::URI.parse("http://example.com?foo=bar&bar=qux&qux=6toto=0") }
|
119
|
-
|
120
|
-
it "returns false" do
|
121
|
-
expect(matcher).not_to match(url)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#params" do
|
127
|
-
let(:constraints) do
|
128
|
-
Hash[foo: 1..5, bar: /baz/, qux: "zot", toto: 2]
|
129
|
-
end
|
130
|
-
|
131
|
-
it "returns the correct parameters" do
|
132
|
-
url = Addressable::URI.parse("http://example.com?foo=4&bar=bazqux&qux=zot&toto=2")
|
133
|
-
expect(matcher.params(url)).to \
|
134
|
-
eq("foo" => "4", "bar" => "bazqux", "qux" => "zot", "toto" => "2")
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::Scheme do
|
6
|
-
describe "#match" do
|
7
|
-
subject(:matcher) { Wayfarer::Routing::Matchers::Scheme.new(:http) }
|
8
|
-
|
9
|
-
context "with matching URL" do
|
10
|
-
let(:url) { Addressable::URI.parse("http://example.com") }
|
11
|
-
|
12
|
-
it "returns true" do
|
13
|
-
expect(matcher).to match(url)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "with mismatching URL" do
|
18
|
-
let(:url) { Addressable::URI.parse("https://example.com") }
|
19
|
-
|
20
|
-
it "returns true" do
|
21
|
-
expect(matcher).not_to match(url)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::Suffix do
|
6
|
-
subject(:matcher) { Wayfarer::Routing::Matchers::Suffix.new(".png") }
|
7
|
-
|
8
|
-
describe "#match" do
|
9
|
-
context "with matching URL" do
|
10
|
-
it "returns true" do
|
11
|
-
urls = %w[
|
12
|
-
http://example.com/foo.png
|
13
|
-
https://example.com/a/b.png/c.png
|
14
|
-
http://example.com/foobar.html.png
|
15
|
-
https://example.com/foo.png/bar.png
|
16
|
-
].map { |u| Addressable::URI.parse(u) }
|
17
|
-
|
18
|
-
urls.each do |url|
|
19
|
-
expect(matcher).to match(url)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "with mismatching URL" do
|
25
|
-
it "returns false" do
|
26
|
-
urls = %w[
|
27
|
-
http://example.png
|
28
|
-
http://example.com.png
|
29
|
-
https://example.com/a/b.png/c
|
30
|
-
http://example.com.html
|
31
|
-
http://example.com/foobar.html
|
32
|
-
https://example.com/foo.png/bar.png.html
|
33
|
-
].map { |u| Addressable::URI.parse(u) }
|
34
|
-
|
35
|
-
urls.each do |url|
|
36
|
-
expect(matcher).not_to match(url)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Matchers::URL do
|
6
|
-
subject(:matcher) do
|
7
|
-
Wayfarer::Routing::Matchers::URL.new("http://example.com/foo/bar")
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#match" do
|
11
|
-
context "with matching URL" do
|
12
|
-
let(:url) { Addressable::URI.parse("http://example.com/foo/bar") }
|
13
|
-
|
14
|
-
it "returns true" do
|
15
|
-
expect(matcher).to match(url)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "with mismatching URL" do
|
20
|
-
let(:url) { Addressable::URI.parse("http://example.com/foo/qux") }
|
21
|
-
|
22
|
-
it "returns true" do
|
23
|
-
expect(matcher).not_to match(url)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::PathFinder do
|
6
|
-
let(:route) do
|
7
|
-
Wayfarer::Routing::RootRoute.new.to(:foobar) do
|
8
|
-
host "example.com", path: "/:a/:b"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
subject(:result) { Wayfarer::Routing::PathFinder.result(route, Addressable::URI.parse(url)) }
|
13
|
-
|
14
|
-
describe "::result" do
|
15
|
-
context "with matching URL" do
|
16
|
-
let(:url) { "https://example.com/alpha/beta" }
|
17
|
-
|
18
|
-
it "returns a Match" do
|
19
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
20
|
-
expect(result.action).to be(:foobar)
|
21
|
-
expect(result.params).to eq("a" => "alpha", "b" => "beta")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with mismatching URL" do
|
26
|
-
let(:url) { "https://yahoo.com/alpha/zyklon" }
|
27
|
-
|
28
|
-
it "returns a Mismatch" do
|
29
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Route do
|
6
|
-
let(:route) { Wayfarer::Routing::RootRoute.new }
|
7
|
-
|
8
|
-
describe "#matcher" do
|
9
|
-
subject(:matcher) { route.matcher }
|
10
|
-
|
11
|
-
context "with child routes" do
|
12
|
-
before { route.host("http://google.com") }
|
13
|
-
|
14
|
-
it "returns true" do
|
15
|
-
%w[http://example.com http://w3c.org http://google.com].each do |url|
|
16
|
-
expect(matcher).to match(Addressable::URI.parse(url))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "without child routes" do
|
22
|
-
it "returns false" do
|
23
|
-
%w[http://example.com http://w3c.org http://google.com].each do |url|
|
24
|
-
expect(matcher).not_to match(Addressable::URI.parse(url))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/routing/route_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Route do
|
6
|
-
subject(:root) { Wayfarer::Routing::RootRoute.new }
|
7
|
-
|
8
|
-
describe "#invoke" do
|
9
|
-
context "with matching matchers" do
|
10
|
-
it "returns a Match" do
|
11
|
-
root.host "example.com", to: :overridden do
|
12
|
-
path "/:a/:b" do
|
13
|
-
to :overrider, query: { page: 42 }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
result = root.invoke(Addressable::URI.parse("http://example.com/foo/bar?page=42"))
|
18
|
-
|
19
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
20
|
-
expect(result.action).to be(:overrider)
|
21
|
-
expect(result.params).to eq({
|
22
|
-
"a" => "foo",
|
23
|
-
"b" => "bar",
|
24
|
-
"page" => "42"
|
25
|
-
})
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "with mismatching matchers" do
|
30
|
-
it "returns a Mismatch" do
|
31
|
-
root.host "example.com", to: :overridden do
|
32
|
-
path "/:a/:b" do
|
33
|
-
query({ page: 42 }, { to: :overrider })
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
result = root.invoke(Addressable::URI.parse("http://w3c.org/foo/bar?page=42"))
|
38
|
-
|
39
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Mismatch)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/spec/routing/router_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Routing::Router do
|
6
|
-
subject(:router) do
|
7
|
-
described_class.new.tap do |router|
|
8
|
-
router.draw do |alpha, beta|
|
9
|
-
path alpha, to: :alpha
|
10
|
-
path beta, to: :beta
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#invoke" do
|
16
|
-
let(:url) { Addressable::URI.parse("https://example.com/alpha") }
|
17
|
-
|
18
|
-
it "evaluates routes" do
|
19
|
-
result = router.invoke(url, %w[/alpha /beta])
|
20
|
-
expect(result).to be_a(Wayfarer::Routing::Result::Match)
|
21
|
-
expect(result.action).to be(:alpha)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/spec/task_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helpers"
|
4
|
-
|
5
|
-
describe Wayfarer::Task do
|
6
|
-
subject(:task) { build(:task) }
|
7
|
-
|
8
|
-
describe "#metadata" do
|
9
|
-
it "returns an OpenStruct" do
|
10
|
-
expect(task.metadata).to be_an(OpenStruct)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#barrier" do
|
15
|
-
it "returns its batch barrier" do
|
16
|
-
expect(task.barrier).to be_a(Wayfarer::Redis::Barrier)
|
17
|
-
expect(task.barrier.batch).to eq(task.batch)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#counter" do
|
22
|
-
it "returns its batch counter" do
|
23
|
-
expect(task.counter).to be_a(Wayfarer::Redis::Counter)
|
24
|
-
expect(task.counter.batch).to eq(task.batch)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#gc" do
|
29
|
-
it "returns a garbage collector" do
|
30
|
-
expect(task.gc).to be_a(Wayfarer::GC)
|
31
|
-
expect(task.gc.task).to be(task)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
require "spec_helpers"
|
4
4
|
|
5
5
|
describe Wayfarer::Stringify do
|
6
|
+
subject(:instance) { klass.new(1, 2.0, :three, "four") }
|
7
|
+
|
6
8
|
let(:klass) do
|
7
9
|
Class.new(Struct.new(:a, :b, :c, :d)) do
|
8
10
|
include Wayfarer::Stringify
|
@@ -11,8 +13,6 @@ describe Wayfarer::Stringify do
|
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
subject(:instance) { klass.new(1, 2.0, :three, "four") }
|
15
|
-
|
16
16
|
before { stub_const("Foobar", klass) }
|
17
17
|
|
18
18
|
describe "#to_s" do
|