Skip to content

Instantly share code, notes, and snippets.

@odlp
Last active January 21, 2021 17:57
Show Gist options
  • Save odlp/5b692223d26e62a778bf43a91bf0838b to your computer and use it in GitHub Desktop.
Save odlp/5b692223d26e62a778bf43a91bf0838b to your computer and use it in GitHub Desktop.
Hit a spec
# spec/support/hit.rb
module HitSpec
def hit(*args, &block)
n = 100
if args.last.is_a?(Hash) && args.last.key?(:n)
n = args.last.delete(:n)
end
n.times do
it(*args, &block)
end
end
end
RSpec.configure do |config|
config.extend HitSpec
end
# spec/hit_example_spec.rb
require "support/hit"
RSpec.describe "repeating a spec" do
hit "defaults to 100" do
expect(true).to be true
end
hit "is convenient", n: 1000 do
expect(true).to be true
end
end
@odlp
Copy link
Author

odlp commented Jan 21, 2021

Inspired by Que's hit helper for Minitest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment