How to set before(:suite) and after(:suite) RSpec hooks in Queue Mode (Percy.io example)?
percy-capybara gem version < 4 (old)
Some tools like Percy.io requires to set hooks for RSpec
Knapsack Pro Queue Mode runs subset of test files from the work queue many times. This means the RSpec hooks
after(:suite) will execute multiple times. If you want to run some code only once before Queue Mode starts work and after it finishes then you should do it this way:
# spec_helper.rb or rails_helper.rb # step for percy-capybara gem version < 4 KnapsackPro::Hooks::Queue.before_queue do |queue_id| # executes before Queue Mode starts work Percy::Capybara.initialize_build end KnapsackPro::Hooks::Queue.after_queue do |queue_id| # executes after Queue Mode finishes work Percy::Capybara.finalize_build end
percy-capybara gem version >= 4
If you use percy-capybara 4.x then you don't need to set RSpec hooks. Insted you need to run
knapsack_pro via percy npm command.
npx percy exec -- rake knapsack_pro:queue:rspec # or you can use knapsack_pro binary version instead of rake task npx percy exec -- knapsack_pro queue:rspec
Read more about knapsack_pro binary version.
Also you need to follow Percy step for parallelism.
PERCY_PARALLEL_NONCE- A unique identifier for this build. This can be anything, but it must be the same across parallel build nodes. Usually, this is just the CI build number or a shared timestamp. You can google environment variables for CI provider you use to check what's the env var for build ID.
You can also find CI build number for your CI provider in knapsack_pro source code. knapsackpro has built in environment variables integration for various CI providers. See for example CircleCI - look for method `nodebuild_id`.
# example for using CircleCI build ID export PERCY_PARALLEL_NONCE=$CIRCLE_BUILD_NUM
PERCY_PARALLEL_TOTAL- The total number of parallel build nodes.