Skip to content

Commit 8bf71de

Browse files
committed
docs(ruby/trouble): fixed rake tasks
1 parent 56893b2 commit 8bf71de

File tree

1 file changed

+57
-51
lines changed

1 file changed

+57
-51
lines changed

docusaurus/docs/ruby/troubleshooting.mdx

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ You might still need to use the `timeout` program to terminate tests and capture
205205
:::
206206

207207
<details>
208-
<summary>For legacy versions of `knapsack_pro` older than 7.7.0, please click here.</summary>
208+
<summary>For legacy versions of `knapsack_pro` older than 7.7.0, click here.</summary>
209209

210210
Tests freeze and CI node timeouts (the Ruby process is killed by a CI provider). Add the following script to `spec_helper.rb`. Thanks to that, you will see the backtrace showing what code line causes the hanging problem. Backtrace is visible only if the Ruby process got kill with `USR1` signal. Learn more from this [GitHub issue](https://github.com/rspec/rspec-rails/issues/1353#issuecomment-93173691).
211211

@@ -324,10 +324,10 @@ WebMock or VCR may trigger the following errors when Knapsack Pro interacts with
324324
- `VCR::Errors::UnhandledHTTPRequestError`
325325
- `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: tlsv1 alert internal error`
326326

327-
**`knapsack_pro` version 7.2 fixed those issues.**
327+
**Update the `knapsack_pro` gem to the latest version to fix those issues.**
328328

329329
<details>
330-
<summary>For legacy versions of `knapsack_pro` older than 7.2, please click here.</summary>
330+
<summary>For legacy versions of `knapsack_pro` older than 7.2, click here.</summary>
331331

332332
Add the Knapsack Pro API's subdomain to the [ignored hosts](https://benoittgt.github.io/vcr/#/configuration/ignore_request) and [`disable_web_connect!`](https://github.com/bblimke/webmock) in `spec/spec_helper.rb` (or wherever your WebMock/VCR configuration is located):
333333

@@ -442,69 +442,75 @@ You have a couple of options:
442442

443443
## Rake tasks under tests are run more than once in Queue Mode
444444

445-
Make sure the Rake task is loaded once for each test example in the spec file:
445+
**Update the `knapsack_pro` gem to the latest version to fix this issue.**
446446

447447
import Tabs from '@theme/Tabs';
448448
import TabItem from '@theme/TabItem';
449449

450-
<Tabs>
451-
<TabItem value="rake">
452-
453-
```ruby
454-
class DummyOutput
455-
class << self
456-
attr_accessor :count
457-
end
458-
end
459-
460-
namespace :dummy do
461-
task do_something_once: :environment do
462-
DummyOutput.count ||= 0
463-
DummyOutput.count += 1
464-
puts "Count: #{DummyOutput.count}"
465-
end
466-
end
467-
```
468-
469-
</TabItem>
470-
471-
<TabItem value="spec">
450+
<details>
451+
<summary>For legacy versions of `knapsack_pro` older than 8.1.1, click here.</summary>
472452

473-
```ruby
474-
require 'rake'
453+
Make sure the Rake task is loaded once for each test example in the spec file:
475454

476-
describe 'Dummy rake' do
477-
describe "dummy:do_something_once" do
478-
let(:task_name) { "dummy:do_something_once" }
479-
let(:task) { Rake::Task[task_name] }
455+
<Tabs>
456+
<TabItem value="rake">
480457

481-
before(:each) do # make sure the rake task is defined *once*
482-
Rake::Task[task_name].clear if Rake::Task.task_defined?(task_name)
483-
Rake.load_rakefile("tasks/dummy.rake")
484-
Rake::Task.define_task(:environment)
458+
```ruby
459+
class DummyOutput
460+
class << self
461+
attr_accessor :count
485462
end
463+
end
486464

487-
after(:each) do
488-
Rake::Task[task_name].reenable
489-
# Reset the state
490-
DummyOutput.count = 0
465+
namespace :dummy do
466+
task do_something_once: :environment do
467+
DummyOutput.count ||= 0
468+
DummyOutput.count += 1
469+
puts "Count: #{DummyOutput.count}"
491470
end
471+
end
472+
```
492473

493-
it "calls the rake task once (increases counter by one)" do
494-
expect { task.invoke }.to_not raise_error
495-
expect(DummyOutput.count).to eq(1)
496-
end
474+
</TabItem>
475+
476+
<TabItem value="spec">
497477

498-
it "calls the rake task once again (increases counter by one)" do
499-
expect { task.invoke }.to_not raise_error
500-
expect(DummyOutput.count).to eq(1)
478+
```ruby
479+
require 'rake'
480+
481+
describe 'Dummy rake' do
482+
describe "dummy:do_something_once" do
483+
let(:task_name) { "dummy:do_something_once" }
484+
let(:task) { Rake::Task[task_name] }
485+
486+
before(:each) do # make sure the rake task is defined *once*
487+
Rake::Task[task_name].clear if Rake::Task.task_defined?(task_name)
488+
Rake.load_rakefile("tasks/dummy.rake")
489+
Rake::Task.define_task(:environment)
490+
end
491+
492+
after(:each) do
493+
Rake::Task[task_name].reenable
494+
# Reset the state
495+
DummyOutput.count = 0
496+
end
497+
498+
it "calls the rake task once (increases counter by one)" do
499+
expect { task.invoke }.to_not raise_error
500+
expect(DummyOutput.count).to eq(1)
501+
end
502+
503+
it "calls the rake task once again (increases counter by one)" do
504+
expect { task.invoke }.to_not raise_error
505+
expect(DummyOutput.count).to eq(1)
506+
end
501507
end
502508
end
503-
end
504-
```
509+
```
505510

506-
</TabItem>
507-
</Tabs>
511+
</TabItem>
512+
</Tabs>
513+
</details>
508514

509515
## Tests distribution is unbalanced in Queue Mode
510516

0 commit comments

Comments
 (0)