/
test_helper.rb
51 lines (45 loc) · 1.78 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# add Coveralls and SimpleCov support
begin
require 'simplecov'
require 'coveralls'
simplecov_params = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(simplecov_params)
SimpleCov.start do
add_filter ['.bundle', 'lib/extensions', 'test']
end
rescue LoadError
puts 'Coverage disabled, enable by installing simplecov'
end
require 'test/unit'
require 'rubygems'
require 'timecop'
require 'yaml'
YAML::ENGINE.yamler = 'psych' if defined? YAML::ENGINE
require File.expand_path(File.dirname(__FILE__) + '/../lib/faker')
# configure I18n
locales_path = File.expand_path(File.dirname(__FILE__) + '../lib/locales')
I18n.available_locales = Dir[locales_path + '/*'].map do |file|
file.split('.').first
end
I18n.enforce_available_locales = true
# deterministically_verify executes the test provided in the block successive
# times with the same deterministic_random seed.
# @param subject_proc [Proc] a proc object that returns the subject under test
# when called.
# @param depth [Integer] the depth of deterministic comparisons to run.
# @param random [Integer] A random number seed; Used to override the default.
#
# @example
# deterministically_verify ->{ @tester.user_name('bo peep') } do |subject|
# assert subject.match(/(bo(_|\.)peep|peep(_|\.)bo)/)
# end
#
def deterministically_verify(subject_proc, depth: 2, random: nil)
raise 'need block' unless block_given?
# rubocop:disable Style/MultilineBlockChain
depth.times.inject([]) do |results, _index|
Faker::Config.random = random || Random.new(42)
results << subject_proc.call.freeze.tap { |s| yield(s) }
end.repeated_combination(2) { |(first, second)| assert_equal first, second }
# rubocop:enable Style/MultilineBlockChain
end