Skip to content

Instantly share code, notes, and snippets.

View vlad-velciov's full-sized avatar

Vlad Velciov vlad-velciov

  • Timisoara
View GitHub Profile
# specs/falkiness_spec.rb
describe 'Flakiness' do
it 'fails randomly' do
expect(random_true).to be true
end
it 'might also fail randomly' do
expect(random_true).to be true
end
private
def random_true
@vlad-velciov
vlad-velciov / Gemfile
Created November 30, 2018 16:04
retry_tests/Gemfile
# Gemfile
source 'https://rubygems.org'
ruby '2.5.1'
gem 'rspec'
gem 'rspec-retry'
@vlad-velciov
vlad-velciov / spec_helper.rb
Created November 30, 2018 16:05
retry_tests/spec_helper1.r
# spec_helper.rb
require 'rspec/retry'
RSpec.configure do |config|
config.default_retry_count = 2
config.verbose_retry = true
...
@vlad-velciov
vlad-velciov / spec_helper.rb
Created November 30, 2018 16:07
retry_tests/spec_helper2.rb
# spec_helper.rb
RSpec.configure do |config|
...
# callback to be run between retries
config.retry_callback = proc do |example|
# marks this test as flaky so we can identify it even if it
# passed at later retries
example.metadata[:flaky] = true
end
...
@vlad-velciov
vlad-velciov / flakiness.rb
Last active December 10, 2018 10:46
retry_tests/lib/formatters/flakiness
# lib/formatters/flakiness.rb
require 'rspec/core/formatters/console_codes'
require 'rspec/core/formatters/documentation_formatter'
class Flakiness < RSpec::Core::Formatters::DocumentationFormatter
RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished,:example_passed, :example_pending, :example_failed
def example_passed(notification)
return super unless notification.example.metadata[:flaky]
output.puts flaky_output(notification.example)
@vlad-velciov
vlad-velciov / flattenable_array.rb
Created May 17, 2019 09:13
Recursively flatten an array
class FlattenableArray
def initialize(array)
@array = array
end
def flatten
flat = []
@array.each do |element|
if element.is_a? Array
@vlad-velciov
vlad-velciov / convert_envs.rb
Created January 13, 2021 08:12
A small tool to convert a file that has lots of export statements to a normalized .env file
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'digest/md5'
# TODO option to install git hook on pull
# TODO option to uninstall git hook on pull
# TODO option to install files in a .git/info/exclude