Skip to content

Instantly share code, notes, and snippets.

@ArturT
Created September 29, 2023 12:15
Show Gist options
  • Save ArturT/12a46b7dd65d4d409321d1acd30ef4ca to your computer and use it in GitHub Desktop.
Save ArturT/12a46b7dd65d4d409321d1acd30ef4ca to your computer and use it in GitHub Desktop.

Revisions

  1. ArturT created this gist Sep 29, 2023.
    40 changes: 40 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    before_suite_block = proc {
    puts '+'*100
    puts 'RSpec before suite hook called only once'
    }

    unless KnapsackPro::Config::Env.queue_recording_enabled?
    RSpec.configure do |config|
    config.before(:suite) do
    before_suite_block.call
    puts 'Run this only when not using Knapsack Pro Queue Mode'
    end
    end
    end

    KnapsackPro::Hooks::Queue.before_queue do |queue_id|
    before_suite_block.call
    puts 'Run this only when using Knapsack Pro Queue Mode'
    puts 'This code is executed within the context of RSpec before(:suite) hook'
    end


    after_suite_block = proc {
    puts '+'*100
    puts 'after suite hook called only once'
    }

    unless KnapsackPro::Config::Env.queue_recording_enabled?
    RSpec.configure do |config|
    config.after(:suite) do
    after_suite_block.call
    puts 'Run this only when not using Knapsack Pro Queue Mode'
    end
    end
    end

    KnapsackPro::Hooks::Queue.after_queue do |queue_id|
    after_suite_block.call
    puts 'Run this only when using Knapsack Pro Queue Mode'
    puts "This code is executed outside of the RSpec after(:suite) hook context because it's impossible to determine which after(:suite) is the last one to execute until it's executed."
    end