Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Queue] [RSpec] Update docs: Get tests and the status of each batch of tests in RSpec #172

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion docusaurus/docs/ruby/hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ KnapsackPro::Hooks::Queue.after_queue do |queue_id|
end
```

## RSpec
## RSpec

<details>
<summary>For legacy versions of `knapsack_pro` older than 7.0, please click here.</summary>
Expand Down Expand Up @@ -126,6 +126,43 @@ end
</Tabs>
</details>

### Get tests and the status of each batch of tests in RSpec

The `KnapsackPro::Hooks::Queue.before_subset_queue` and `KnapsackPro::Hooks::Queue.after_subset_queue` hooks get a 3rd variable - the `queue`.

The `queue` variable stores an enumerable collection with each batch of tests fetched from the Queue API. The batch has:

* a list of test file paths (`KnapsackPro::Batch#test_file_paths` returns an array like `['a_spec.rb', 'b_spec.rb']`)
* a status of the given set of tests in the batch (`KnapsackPro::Batch#status` returns `:not_executed`, `:passed` or `:failed`)

Example usage:

```ruby title="spec_helper.rb"
KnapsackPro::Hooks::Queue.before_subset_queue do |queue_id, subset_queue_id, queue|
print "Tests from all batches fetched from the Queue API so far: "
puts queue.map(&:test_file_paths).inspect

queue.each(&:test_file_paths) # you can use each as well

print "Current batch tests: "
puts queue.current_batch.test_file_paths.inspect

print "Current batch status: "
puts queue.current_batch.status # returns :not_executed in the `before_subset_queue` hook
end

KnapsackPro::Hooks::Queue.after_subset_queue do |queue_id, subset_queue_id, queue|
print "Tests from all batches fetched from the Queue API so far: "
puts queue.map(&:test_file_paths).inspect

print "Current batch tests: "
puts queue.current_batch.test_file_paths.inspect

print "Current batch status: "
puts queue.current_batch.status # returns :passed or :failed in the `after_subset_queue` hook
end
```

## `percy-capybara`

### `percy-capybara` >= 4
Expand Down
Loading