What is the order of RSpec hooks in the Queue Mode?
By default, RSpec runs
after hooks, and they are called in the following order:
before :suite before :context before :example after :example after :context after :suite
When you use the Queue Mode in the knapsack_pro gem, you fetch a batch of test files from Knapsack Pro Queue API, and
RSpec::Core::Runner executes it. For the given set of test files, the above hooks are called.
When tests are completed and another batch of tests is fetched from Queue API, the tests are executed by
RSpec::Core::Runner again. This means the above hooks are called again.
before/after :suite hooks would be called multiple times. This might be important for some users. For instance if you run some code in the
before :suite hook, and perform cleanup in the
after :suite hook expecting both hooks to be called only once. To execute hooks only once, you can use Queue Mode hooks.
Here you can find other hooks available for your test runner in the Queue Mode.
In the Queue Mode, the flow for
before/after :suite would look like this:
1st batch of tests fetched from Queue API:
before KnapsackPro::Hooks::Queue.before_queue is called (only here) before :suite is called a_spec.rb and b_spec.rb is executed after :suite is called
2nd batch of tests is fetched from Queue API (let's assume this is the last batch):
before :suite is called c_spec.rb and d_spec.rb is executed after :suite is called KnapsackPro::Hooks::Queue.after_queue is called (only here)