wayfarer 0.4.5 → 0.4.7

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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yaml +25 -0
  3. data/.github/workflows/release.yaml +29 -0
  4. data/.github/workflows/tests.yaml +30 -0
  5. data/.gitignore +4 -0
  6. data/.rubocop.yml +5 -0
  7. data/.vale.ini +5 -0
  8. data/.yardopts +1 -3
  9. data/Dockerfile +5 -4
  10. data/Gemfile +3 -0
  11. data/Gemfile.lock +107 -102
  12. data/Rakefile +5 -56
  13. data/bin/wayfarer +1 -1
  14. data/docker-compose.yml +20 -9
  15. data/docs/cookbook/consent_screen.md +2 -2
  16. data/docs/cookbook/executing_javascript.md +3 -3
  17. data/docs/cookbook/navigation.md +12 -12
  18. data/docs/cookbook/querying_html.md +3 -3
  19. data/docs/cookbook/screenshots.md +2 -2
  20. data/docs/cookbook/user_agent.md +1 -1
  21. data/docs/design.md +36 -0
  22. data/docs/guides/callbacks.md +24 -126
  23. data/docs/guides/configuration.md +8 -8
  24. data/docs/guides/handlers.md +60 -0
  25. data/docs/guides/index.md +1 -0
  26. data/docs/guides/jobs/error_handling.md +40 -0
  27. data/docs/guides/jobs.md +99 -31
  28. data/docs/guides/navigation.md +1 -1
  29. data/docs/guides/networking/capybara.md +13 -22
  30. data/docs/guides/networking/custom_adapters.md +82 -41
  31. data/docs/guides/networking/ferrum.md +4 -4
  32. data/docs/guides/networking/http.md +9 -13
  33. data/docs/guides/networking/selenium.md +10 -11
  34. data/docs/guides/pages.md +76 -10
  35. data/docs/guides/redis.md +10 -0
  36. data/docs/guides/routing.md +74 -0
  37. data/docs/guides/tasks.md +33 -9
  38. data/docs/guides/tutorial.md +60 -0
  39. data/docs/guides/user_agents.md +113 -0
  40. data/docs/index.md +17 -40
  41. data/docs/reference/cli.md +35 -25
  42. data/docs/reference/configuration.md +36 -0
  43. data/lib/wayfarer/base.rb +124 -46
  44. data/lib/wayfarer/batch_completion.rb +56 -0
  45. data/lib/wayfarer/callbacks.rb +22 -48
  46. data/lib/wayfarer/cli/route_printer.rb +71 -57
  47. data/lib/wayfarer/cli.rb +121 -0
  48. data/lib/wayfarer/gc.rb +13 -6
  49. data/lib/wayfarer/handler.rb +15 -7
  50. data/lib/wayfarer/logging.rb +38 -0
  51. data/lib/wayfarer/middleware/base.rb +2 -0
  52. data/lib/wayfarer/middleware/batch_completion.rb +19 -0
  53. data/lib/wayfarer/middleware/content_type.rb +54 -0
  54. data/lib/wayfarer/middleware/controller.rb +19 -15
  55. data/lib/wayfarer/middleware/dedup.rb +16 -13
  56. data/lib/wayfarer/middleware/dispatch.rb +12 -4
  57. data/lib/wayfarer/middleware/normalize.rb +12 -11
  58. data/lib/wayfarer/middleware/redis.rb +15 -0
  59. data/lib/wayfarer/middleware/router.rb +33 -35
  60. data/lib/wayfarer/middleware/stage.rb +5 -5
  61. data/lib/wayfarer/middleware/uri_parser.rb +30 -0
  62. data/lib/wayfarer/middleware/user_agent.rb +49 -0
  63. data/lib/wayfarer/networking/capybara.rb +1 -1
  64. data/lib/wayfarer/networking/context.rb +2 -2
  65. data/lib/wayfarer/networking/ferrum.rb +2 -2
  66. data/lib/wayfarer/networking/follow.rb +12 -6
  67. data/lib/wayfarer/networking/http.rb +1 -1
  68. data/lib/wayfarer/networking/pool.rb +17 -12
  69. data/lib/wayfarer/networking/selenium.rb +3 -3
  70. data/lib/wayfarer/networking/strategy.rb +2 -2
  71. data/lib/wayfarer/page.rb +36 -14
  72. data/lib/wayfarer/parsing/xml.rb +6 -6
  73. data/lib/wayfarer/parsing.rb +24 -0
  74. data/lib/wayfarer/redis/barrier.rb +13 -21
  75. data/lib/wayfarer/redis/counter.rb +19 -9
  76. data/lib/wayfarer/redis/pool.rb +1 -1
  77. data/lib/wayfarer/redis/resettable.rb +19 -0
  78. data/lib/wayfarer/routing/dsl.rb +1 -0
  79. data/lib/wayfarer/routing/matchers/path.rb +4 -2
  80. data/lib/wayfarer/routing/root_route.rb +5 -1
  81. data/lib/wayfarer/routing/route.rb +4 -14
  82. data/lib/wayfarer/stringify.rb +22 -30
  83. data/lib/wayfarer/task.rb +12 -18
  84. data/lib/wayfarer.rb +29 -2
  85. data/mkdocs.yml +52 -7
  86. data/rake/docs.rake +26 -0
  87. data/rake/lint.rake +105 -0
  88. data/rake/release.rake +29 -0
  89. data/rake/tests.rake +28 -0
  90. data/requirements.txt +1 -1
  91. data/spec/base_spec.rb +140 -160
  92. data/spec/batch_completion_spec.rb +104 -0
  93. data/spec/cli/job_spec.rb +19 -23
  94. data/spec/cli/routing_spec.rb +101 -0
  95. data/spec/cli/version_spec.rb +1 -1
  96. data/spec/factories/task.rb +7 -1
  97. data/spec/fixtures/dummy_job.rb +5 -3
  98. data/spec/gc_spec.rb +8 -50
  99. data/spec/handler_spec.rb +1 -1
  100. data/spec/integration/callbacks_spec.rb +157 -45
  101. data/spec/integration/content_type_spec.rb +145 -0
  102. data/spec/integration/gc_spec.rb +44 -0
  103. data/spec/integration/handler_spec.rb +66 -0
  104. data/spec/integration/page_spec.rb +44 -29
  105. data/spec/integration/params_spec.rb +33 -25
  106. data/spec/integration/parsing_spec.rb +125 -0
  107. data/spec/integration/routing_spec.rb +18 -0
  108. data/spec/integration/stage_spec.rb +27 -20
  109. data/spec/middleware/batch_completion_spec.rb +34 -0
  110. data/spec/middleware/chain_spec.rb +8 -8
  111. data/spec/middleware/content_type_spec.rb +86 -0
  112. data/spec/middleware/controller_spec.rb +5 -5
  113. data/spec/middleware/dedup_spec.rb +38 -55
  114. data/spec/middleware/dispatch_spec.rb +23 -7
  115. data/spec/middleware/normalize_spec.rb +44 -13
  116. data/spec/middleware/router_spec.rb +29 -30
  117. data/spec/middleware/stage_spec.rb +8 -8
  118. data/spec/middleware/uri_parser_spec.rb +53 -0
  119. data/spec/middleware/{fetch_spec.rb → user_agent_spec.rb} +28 -27
  120. data/spec/networking/context_spec.rb +17 -0
  121. data/spec/networking/follow_spec.rb +2 -2
  122. data/spec/networking/pool_spec.rb +5 -5
  123. data/spec/networking/strategy.rb +2 -2
  124. data/spec/page_spec.rb +42 -20
  125. data/spec/parsing/xml_spec.rb +11 -12
  126. data/spec/redis/barrier_spec.rb +8 -48
  127. data/spec/redis/counter_spec.rb +13 -1
  128. data/spec/redis/pool_spec.rb +1 -1
  129. data/spec/spec_helpers.rb +27 -16
  130. data/spec/support/test_app.rb +8 -0
  131. data/spec/task_spec.rb +3 -24
  132. data/spec/wayfarer_spec.rb +1 -1
  133. data/wayfarer.gemspec +4 -3
  134. metadata +61 -51
  135. data/.github/workflows/ci.yaml +0 -32
  136. data/docs/guides/error_handling.md +0 -31
  137. data/docs/guides/networking.md +0 -94
  138. data/docs/guides/performance.md +0 -130
  139. data/docs/guides/reliability.md +0 -41
  140. data/docs/guides/routing/steering.md +0 -30
  141. data/docs/reference/api/base.md +0 -48
  142. data/docs/reference/configuration_keys.md +0 -42
  143. data/docs/reference/environment_variables.md +0 -83
  144. data/lib/wayfarer/cli/base.rb +0 -45
  145. data/lib/wayfarer/cli/generate.rb +0 -17
  146. data/lib/wayfarer/cli/job.rb +0 -56
  147. data/lib/wayfarer/cli/route.rb +0 -29
  148. data/lib/wayfarer/cli/runner.rb +0 -34
  149. data/lib/wayfarer/cli/templates/Gemfile.tt +0 -5
  150. data/lib/wayfarer/cli/templates/job.rb.tt +0 -10
  151. data/lib/wayfarer/config/capybara.rb +0 -10
  152. data/lib/wayfarer/config/ferrum.rb +0 -11
  153. data/lib/wayfarer/config/networking.rb +0 -26
  154. data/lib/wayfarer/config/redis.rb +0 -14
  155. data/lib/wayfarer/config/root.rb +0 -11
  156. data/lib/wayfarer/config/selenium.rb +0 -21
  157. data/lib/wayfarer/config/strconv.rb +0 -45
  158. data/lib/wayfarer/config/struct.rb +0 -72
  159. data/lib/wayfarer/middleware/fetch.rb +0 -56
  160. data/lib/wayfarer/redis/connection.rb +0 -13
  161. data/lib/wayfarer/redis/version.rb +0 -19
  162. data/lib/wayfarer/routing/router.rb +0 -28
  163. data/spec/callbacks_spec.rb +0 -102
  164. data/spec/cli/generate_spec.rb +0 -39
  165. data/spec/config/capybara_spec.rb +0 -18
  166. data/spec/config/ferrum_spec.rb +0 -24
  167. data/spec/config/networking_spec.rb +0 -73
  168. data/spec/config/redis_spec.rb +0 -32
  169. data/spec/config/root_spec.rb +0 -31
  170. data/spec/config/selenium_spec.rb +0 -56
  171. data/spec/config/strconv_spec.rb +0 -58
  172. data/spec/config/struct_spec.rb +0 -66
  173. data/spec/integration/steering_spec.rb +0 -57
  174. data/spec/redis/version_spec.rb +0 -13
  175. data/spec/routing/router_spec.rb +0 -24
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Callbacks do
6
- let(:url) { "https://alpha.com" }
7
- let(:task) { build(:task, batch: "batch", url: url) }
8
-
9
- let(:klass) do
10
- Class.new(Wayfarer::Base) do
11
- route { host "alpha.com", to: :alpha }
12
- route { host "beta.com", to: :beta }
13
-
14
- before_fetch do |job|
15
- Spy.before_fetch(self, job)
16
- end
17
-
18
- before_fetch(except: %i[alpha beta], only: :alpha) do |job|
19
- Spy.before_fetch_except_alpha_beta_only_alpha(self, job)
20
- end
21
-
22
- before_action do |job|
23
- Spy.before_action(self, job)
24
- end
25
-
26
- before_action(only: :alpha) do |job|
27
- Spy.before_action_only_alpha(self, job)
28
- end
29
-
30
- before_action(only: :beta) do |job|
31
- Spy.before_action_only_beta(self, job)
32
- end
33
-
34
- before_action(only: %i[alpha gamma]) do |job|
35
- Spy.before_action_only_alpha_gamma(self, job)
36
- end
37
-
38
- before_action(except: :alpha) do |job|
39
- Spy.before_action_except_alpha(self, job)
40
- end
41
-
42
- before_action(except: %i[beta gamma]) do |job|
43
- Spy.before_action_except_beta_gamma(self, job)
44
- end
45
-
46
- before_action :callback_a, only: :alpha
47
-
48
- before_action :callback_b
49
-
50
- before_action :callback_c, except: %i[beta]
51
-
52
- def alpha; end
53
-
54
- def beta; end
55
-
56
- private
57
-
58
- def callback_a
59
- Spy.before_action_callback_a_only_alpha(self)
60
- end
61
-
62
- def callback_b
63
- false
64
- end
65
-
66
- def callback_c
67
- Spy.before_action_callback_c(self)
68
- end
69
- end
70
- end
71
-
72
- let(:job) { klass.new }
73
-
74
- before do
75
- stub_const("DummyJob", klass)
76
- stub_const("Spy", spy)
77
-
78
- allow(job).to receive(:arguments).and_return([task])
79
- end
80
-
81
- describe "before_fetch" do
82
- it "fires" do
83
- expect(Spy).to receive(:before_fetch).exactly(:once).with(job, job)
84
- expect(Spy).not_to receive(:before_fetch_except_alpha_beta_only_alpha)
85
- job.perform(task)
86
- end
87
- end
88
-
89
- describe "before_action" do
90
- it "fires" do
91
- expect(Spy).to receive(:before_action).exactly(:once).with(job, job)
92
- expect(Spy).to receive(:before_action_only_alpha).exactly(:once).with(job, job)
93
- expect(Spy).not_to receive(:before_action_only_beta).with(job, job)
94
- expect(Spy).to receive(:before_action_only_alpha_gamma).exactly(:once).with(job, job)
95
- expect(Spy).not_to receive(:before_action_except_alpha).with(job, job)
96
- expect(Spy).to receive(:before_action_except_beta_gamma).exactly(:once).with(job, job)
97
- expect(Spy).to receive(:before_action_callback_a_only_alpha).exactly(:once).with(job)
98
- expect(Spy).not_to receive(:before_action_callback_c).with(job)
99
- job.perform(task)
100
- end
101
- end
102
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::CLI::Generate, cli: true do
6
- subject(:cli) { Wayfarer::CLI::Runner }
7
-
8
- describe "generate project" do
9
- it "outputs" do
10
- expected_output = <<-OUT
11
- create foobar
12
- create foobar/Gemfile
13
- create foobar/app/jobs/foobar.rb
14
- OUT
15
-
16
- expect {
17
- cli.start(%w[generate project foobar])
18
- }.to output(expected_output).to_stdout
19
- end
20
-
21
- it "creates the project directory" do
22
- expect {
23
- cli.start(%w[generate project foobar])
24
- }.to change { File.directory?("foobar") }.to(true)
25
- end
26
-
27
- it "creates the Gemfile" do
28
- expect {
29
- cli.start(%w[generate project foobar])
30
- }.to change { File.file?("foobar/Gemfile") }.to(true)
31
- end
32
-
33
- it "creates the job" do
34
- expect {
35
- cli.start(%w[generate project foobar])
36
- }.to change { File.file?("foobar/app/jobs/foobar.rb") }.to(true)
37
- end
38
- end
39
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Capybara do
6
- let(:env) { {} }
7
- subject(:capybara) { Wayfarer::Config::Capybara.new(env) }
8
-
9
- describe "#driver" do
10
- context "with env var set" do
11
- before { env["WAYFARER_CAPYBARA_DRIVER"] = "cuprite" }
12
-
13
- it "parses the env var" do
14
- expect(capybara.driver).to be(:cuprite)
15
- end
16
- end
17
- end
18
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Ferrum do
6
- let(:env) { {} }
7
- subject(:ferrum) { Wayfarer::Config::Ferrum.new(env) }
8
-
9
- describe "#options" do
10
- context "by default" do
11
- it "is {}" do
12
- expect(ferrum.options).to eq({})
13
- end
14
- end
15
-
16
- context "with env var set" do
17
- before { env["WAYFARER_FERRUM_OPTIONS"] = "url:http://chrome:3000,headless:false" }
18
-
19
- it "parses the env var" do
20
- expect(ferrum.options).to eq(url: "http://chrome:3000", headless: false)
21
- end
22
- end
23
- end
24
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Networking do
6
- let(:env) { {} }
7
- subject(:network) { Wayfarer::Config::Networking.new(env) }
8
-
9
- describe "#agent" do
10
- context "by default" do
11
- it "is :http" do
12
- expect(network.agent).to be(:http)
13
- end
14
- end
15
-
16
- context "with env var set" do
17
- before { env["WAYFARER_NETWORK_AGENT"] = "ferrum" }
18
-
19
- it "parses the env var" do
20
- expect(network.agent).to be(:ferrum)
21
- end
22
- end
23
- end
24
-
25
- describe "#pool_size" do
26
- context "by default" do
27
- it "is 1" do
28
- expect(network.pool_size).to be(1)
29
- end
30
- end
31
-
32
- context "with env var set" do
33
- before { env["WAYFARER_NETWORK_POOL_SIZE"] = "42" }
34
-
35
- it "parses the env var" do
36
- expect(network.pool_size).to be(42)
37
- end
38
- end
39
- end
40
-
41
- describe "#pool_timeout" do
42
- context "by default" do
43
- it "is 10" do
44
- expect(network.pool_timeout).to be(10)
45
- end
46
- end
47
-
48
- context "with env var set" do
49
- before { env["WAYFARER_NETWORK_POOL_SIZE"] = "1337" }
50
-
51
- it "parses the env var" do
52
- expect(network.pool_size).to be(1337)
53
- end
54
- end
55
- end
56
-
57
- describe "#http_headers" do
58
- context "by default" do
59
- it "is {}" do
60
- expect(network.http_headers).to eq({})
61
- end
62
- end
63
-
64
- context "with env var set" do
65
- before { env["WAYFARER_NETWORK_HTTP_HEADERS"] = "user-agent:foo,authorization:bar" }
66
-
67
- it "parses the env var" do
68
- expect(network.http_headers).to eq("user-agent": "foo",
69
- authorization: "bar")
70
- end
71
- end
72
- end
73
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Redis do
6
- let(:env) { {} }
7
- subject(:redis) { Wayfarer::Config::Redis.new(env) }
8
-
9
- describe "#url" do
10
- context "by default" do
11
- it "is redis://localhost:6379" do
12
- expect(redis.url).to eq("redis://localhost:6379")
13
- end
14
- end
15
-
16
- context "with env var set" do
17
- before { env["WAYFARER_REDIS_URL"] = "redis://redis:6379" }
18
-
19
- it "parses the env var" do
20
- expect(redis.url).to eq("redis://redis:6379")
21
- end
22
- end
23
- end
24
-
25
- describe "#factory" do
26
- context "by default" do
27
- it "instantiates Redis" do
28
- expect(redis.factory.call(redis)).to be_a(::Redis)
29
- end
30
- end
31
- end
32
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Root do
6
- subject(:config) { Wayfarer::Config::Root.new }
7
-
8
- describe "#ferrum" do
9
- it "returns a Ferrum config" do
10
- expect(config.ferrum).to be_a(Wayfarer::Config::Ferrum)
11
- end
12
- end
13
-
14
- describe "#network" do
15
- it "returns a network config" do
16
- expect(config.network).to be_a(Wayfarer::Config::Networking)
17
- end
18
- end
19
-
20
- describe "#redis" do
21
- it "returns a Redis config" do
22
- expect(config.redis).to be_a(Wayfarer::Config::Redis)
23
- end
24
- end
25
-
26
- describe "#selenium" do
27
- it "returns a Selenium config" do
28
- expect(config.selenium).to be_a(Wayfarer::Config::Selenium)
29
- end
30
- end
31
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Selenium do
6
- let(:env) { {} }
7
- subject(:selenium) { Wayfarer::Config::Selenium.new(env) }
8
-
9
- describe "#driver" do
10
- context "by default" do
11
- it "is :chrome" do
12
- expect(selenium.driver).to be(:chrome)
13
- end
14
- end
15
-
16
- context "with env var set" do
17
- before { env["WAYFARER_SELENIUM_DRIVER"] = "firefox" }
18
-
19
- it "parses the env var" do
20
- expect(selenium.driver).to be(:firefox)
21
- end
22
- end
23
- end
24
-
25
- describe "#options" do
26
- context "by default" do
27
- it "is {}" do
28
- expect(selenium.options).to eq({})
29
- end
30
- end
31
-
32
- context "with env var set" do
33
- before { env["WAYFARER_SELENIUM_OPTIONS"] = "url:http://firefox" }
34
-
35
- it "parses the env var" do
36
- expect(selenium.options).to eq(url: "http://firefox")
37
- end
38
- end
39
- end
40
-
41
- describe "#client_timeout" do
42
- context "by default" do
43
- it "is 60" do
44
- expect(selenium.client_timeout).to be(60)
45
- end
46
- end
47
-
48
- context "with env var set" do
49
- before { env["WAYFARER_SELENIUM_CLIENT_TIMEOUT"] = "10" }
50
-
51
- it "parses the env var" do
52
- expect(selenium.client_timeout).to be(10)
53
- end
54
- end
55
- end
56
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Strconv do
6
- subject(:strconv) { Wayfarer::Config::Strconv }
7
-
8
- describe "::parse" do
9
- describe Hash do
10
- it "parses" do
11
- input = "alpha:1,beta:two,gamma:true"
12
- output = strconv.parse(input, Hash)
13
- expect(output).to eq(alpha: 1, beta: "two", gamma: true)
14
- end
15
- end
16
-
17
- describe Array do
18
- it "parses" do
19
- input = "alpha, beta , gamma"
20
- output = strconv.parse(input, Array)
21
- expect(output).to eq(%w[alpha beta gamma])
22
- end
23
- end
24
-
25
- describe Symbol do
26
- it "parses" do
27
- expect(strconv.parse("foobar", Symbol)).to be(:foobar)
28
- end
29
- end
30
-
31
- describe Integer do
32
- it "parses" do
33
- expect(strconv.parse("42", Integer)).to be(42)
34
- end
35
- end
36
-
37
- describe "Primitives" do
38
- context "Booleans" do
39
- it "parses" do
40
- expect(strconv.parse("true")).to be(true)
41
- expect(strconv.parse("false")).to be(false)
42
- end
43
- end
44
-
45
- context "Numbers" do
46
- it "parses" do
47
- expect(strconv.parse("42")).to be(42)
48
- end
49
- end
50
-
51
- context "Strings" do
52
- it "parses" do
53
- expect(strconv.parse("foobar")).to be("foobar")
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Config::Struct do
6
- let(:struct) do
7
- Wayfarer::Config::Struct.new(members)
8
- end
9
-
10
- let(:members) { { foo: options } }
11
- let(:options) { {} }
12
- let(:env) { {} }
13
- subject { struct.new(env) }
14
-
15
- describe "Reader" do
16
- context "without environment values and default" do
17
- let(:options) { {} }
18
-
19
- it "returns nil" do
20
- expect(subject.foo).to be(nil)
21
- end
22
- end
23
-
24
- context "with default only" do
25
- let(:options) { { default: 42 } }
26
-
27
- it "returns the default" do
28
- expect(subject.foo).to be(42)
29
- end
30
- end
31
-
32
- context "with environment key specified" do
33
- let(:options) { { env_key: "FOO" } }
34
-
35
- context "with environment value" do
36
- let(:env) { { "FOO" => "hello" } }
37
-
38
- it "returns the value" do
39
- expect(subject.foo).to eq("hello")
40
- end
41
-
42
- context "with type specified" do
43
- let(:options) { { env_key: "FOO", type: Symbol } }
44
-
45
- it "parses the value" do
46
- expect(subject.foo).to be(:hello)
47
- end
48
- end
49
- end
50
-
51
- context "without environment value" do
52
- it "returns nil" do
53
- expect(subject.foo).to be(nil)
54
- end
55
- end
56
- end
57
- end
58
-
59
- describe "Writer" do
60
- it "allows overriding environment values and defaults" do
61
- expect {
62
- subject.foo = 3
63
- }.to change { subject.foo }.from(nil).to(3)
64
- end
65
- end
66
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe "Steering" do
6
- let(:url) { test_app_path("git-scm.com/book/en/v2.html") }
7
-
8
- describe Wayfarer::Base do
9
- specify do
10
- class self.class::DummyJob < Wayfarer::Base
11
- extend RSpec::Matchers
12
-
13
- route do |a, b|
14
- expect(a).to eq("foobar")
15
- expect(b).to eq("barqux")
16
- end
17
-
18
- steer do |task|
19
- [task.batch, "barqux"]
20
- end
21
- end
22
-
23
- self.class::DummyJob.crawl(url, batch: "foobar")
24
- perform_enqueued_jobs
25
- end
26
- end
27
-
28
- describe Wayfarer::Handler do
29
- specify do
30
- class self.class::DummyJob < Wayfarer::Base
31
- route do |_a, _b|
32
- to DummyHandler
33
- end
34
-
35
- steer do |_task|
36
- [123, "barqux"]
37
- end
38
-
39
- class DummyHandler < Wayfarer::Handler
40
- extend RSpec::Matchers
41
-
42
- route do |a, b|
43
- expect(a).to eq("foobar")
44
- expect(b).to eq("fooz")
45
- end
46
-
47
- steer do |task|
48
- [task.batch, "fooz"]
49
- end
50
- end
51
- end
52
-
53
- self.class::DummyJob.crawl(url, batch: "foobar")
54
- perform_enqueued_jobs
55
- end
56
- end
57
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helpers"
4
-
5
- describe Wayfarer::Redis::Version, redis: true do
6
- describe "::determine" do
7
- it "returns Redis major, minor, patch version" do
8
- Wayfarer::Redis::Version.instance_variable_set(:@determine, nil)
9
- expect(Wayfarer::Redis::Version).to receive(:server_version).and_return("1.20.300")
10
- expect(Wayfarer::Redis::Version.determine).to eq([1, 20, 300])
11
- end
12
- end
13
- end
@@ -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