This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 270
/
Rakefile
147 lines (122 loc) · 4.19 KB
/
Rakefile
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require "rake/testtask"
require "bundler/gem_tasks"
# -- Testing stuff --
desc "Test everything"
task "test:all" => "test:adapters"
# Ruby versions we're testing with.
RUBIES = %w{1.9.3 2.0.0 jruby-1.7.13}
# Use rake test:rubies to run all combination of tests (see test:adapters) using
# all the versions of Ruby specified in RUBIES. Or to test a specific version of
# Ruby, rake test:rubies[1.8.7].
#
# This task uses RVM to install all the Ruby versions it needs, and creates a
# vanity gemset in each one that includes Bundler and all the gems specified in
# Gemfile. If anything goes south you can always wipe these gemsets or uninstall
# these Rubies and start over.
desc "Test using multiple versions of Ruby"
task "test:rubies", :ruby do |_t, args|
rubies = args.ruby ? [args.ruby] : RUBIES
rubies.each do |ruby|
puts "** Setup #{ruby}"
sh "env rvm_install_on_use_flag=1 rvm_gemset_create_on_use_flag=1 rvm use #{ruby}@vanity"
sh "rvm #{ruby}@vanity do rake test:setup"
puts
puts "** Test using #{ruby}"
sh "rvm #{ruby}@vanity do rake test:adapters #{'--trace' if Rake.application.options.trace}"
end
end
task "test:setup" do
# Intended to be used from test:rubies, within specific RVM context.
begin # Make sure we got Bundler installed.
require "bundler"
rescue LoadError
sh "gem install bundler"
end
# Make sure we got all the dependencies
sh "bundle check || bundle install"
sh "appraisal install" # Make sure that all of the gemsets are set up
end
# These are all the adapters we're going to test with.
ADAPTERS = %w{redis mongodb active_record}
desc "Test using different back-ends"
task "test:adapters", :adapter do |_t, args|
# Make sure we have appraisal installed and available
require "appraisal"
adapters = args.adapter ? [args.adapter] : ADAPTERS
adapters.each do |adapter|
puts "** Testing #{adapter} adapter"
sh "bundle exec appraisal rake test DB=#{adapter} #{'--trace' if Rake.application.options.trace}"
end
rescue LoadError
warn "The appraisal gem must be available"
end
# Run the test suit.
Rake::TestTask.new(:test) do |task|
task.libs << "lib"
task.libs << "test"
task.pattern = "test/**/*_test.rb"
task.verbose = false
task.warning = false
end
task default: :test
desc "Run all tests"
task(:clobber) { rm_rf "tmp" }
# -- Documenting stuff -- #TODO make sure works under 1.9/2.0
desc "Jekyll generates the main documentation (sans API)"
task(:jekyll) { sh "jekyll build -s doc -d html" }
desc "Create documentation in docs directory"
task docs: [:jekyll]
desc "Remove temporary files and directories"
task(:clobber) { rm_rf "html" }
desc "Publish documentation to vanity.labnotes.org via Github Pages on gh-pages git branch"
task publish: [:clobber, :docs] do
# TODO
end
# -- Misc --
task :report do
$LOAD_PATH.unshift "lib"
require "vanity"
require "timecop"
Vanity.playground.load_path = "test/experiments"
Vanity.playground.experiments.values.each(&:destroy)
Vanity.playground.metrics.values.each(&:destroy!)
Vanity.playground.reload!
# Control 182 35 19.23% N/A
# Treatment A 180 45 25.00% 1.33
# Treatment B 189 28 14.81% -1.13
# Treatment C 188 61 32.45% 2.94
Vanity.playground.experiment(:null_abc).instance_eval do
fake nil => [182, 35], :red => [180, 45], :green => [189, 28], :blue => [188, 61]
@created_at = (Date.today - 40).to_time
@completed_at = (Date.today - 35).to_time
end
Vanity.playground.experiment(:age_and_zipcode).instance_eval do
fake false => [80, 35], true => [84, 32]
@created_at = (Date.today - 30).to_time
@completed_at = (Date.today - 15).to_time
end
Vanity.context = Object.new
Vanity.context.instance_eval do
def vanity_identity
0
end
end
signups = 50
(Date.today - 90..Date.today).each do |date|
Timecop.travel date do
signups += rand(-5..9)
Vanity.playground.track! :signups, signups
end
end
cheers = 0
yawns = 0
(Date.today - 80..Date.today).each do |date|
Timecop.travel date do
cheers = cheers - 5 + rand(20)
Vanity.playground.track! :yawns, cheers
yawns = yawns - 5 + rand(30)
Vanity.playground.track! :cheers, yawns
end
end
Vanity::Commands.report ENV["OUTPUT"]
end