Skip to content

Commit

Permalink
Merge pull request #172 from KnapsackPro/rspec-track-queue-batches
Browse files Browse the repository at this point in the history
[Queue] [RSpec] Update docs: Get tests and the status of each batch of tests in RSpec
  • Loading branch information
ArturT authored May 17, 2024
2 parents 4e4a5c2 + 8ca3508 commit 5dc6242
Showing 1 changed file with 38 additions and 1 deletion.
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

0 comments on commit 5dc6242

Please sign in to comment.