yacc-vanity 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +243 -0
- data/Gemfile +24 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +74 -0
- data/Rakefile +189 -0
- data/bin/vanity +69 -0
- data/lib/vanity.rb +36 -0
- data/lib/vanity/adapters/abstract_adapter.rb +135 -0
- data/lib/vanity/adapters/active_record_adapter.rb +304 -0
- data/lib/vanity/adapters/mock_adapter.rb +157 -0
- data/lib/vanity/adapters/mongodb_adapter.rb +162 -0
- data/lib/vanity/adapters/redis_adapter.rb +154 -0
- data/lib/vanity/backport.rb +26 -0
- data/lib/vanity/commands/list.rb +21 -0
- data/lib/vanity/commands/report.rb +64 -0
- data/lib/vanity/commands/upgrade.rb +34 -0
- data/lib/vanity/experiment/ab_test.rb +482 -0
- data/lib/vanity/experiment/base.rb +212 -0
- data/lib/vanity/frameworks/rails.rb +245 -0
- data/lib/vanity/helpers.rb +59 -0
- data/lib/vanity/metric/active_record.rb +83 -0
- data/lib/vanity/metric/base.rb +244 -0
- data/lib/vanity/metric/google_analytics.rb +83 -0
- data/lib/vanity/metric/remote.rb +53 -0
- data/lib/vanity/playground.rb +332 -0
- data/lib/vanity/templates/_ab_test.erb +26 -0
- data/lib/vanity/templates/_experiment.erb +5 -0
- data/lib/vanity/templates/_experiments.erb +7 -0
- data/lib/vanity/templates/_metric.erb +14 -0
- data/lib/vanity/templates/_metrics.erb +13 -0
- data/lib/vanity/templates/_report.erb +27 -0
- data/lib/vanity/templates/flot.min.js +1 -0
- data/lib/vanity/templates/jquery.min.js +19 -0
- data/lib/vanity/templates/vanity.css +26 -0
- data/lib/vanity/templates/vanity.js +82 -0
- data/lib/vanity/version.rb +11 -0
- data/test/experiment/ab_test.rb +700 -0
- data/test/experiment/base_test.rb +136 -0
- data/test/experiments/age_and_zipcode.rb +19 -0
- data/test/experiments/metrics/cheers.rb +3 -0
- data/test/experiments/metrics/signups.rb +2 -0
- data/test/experiments/metrics/yawns.rb +3 -0
- data/test/experiments/null_abc.rb +5 -0
- data/test/metric/active_record_test.rb +249 -0
- data/test/metric/base_test.rb +293 -0
- data/test/metric/google_analytics_test.rb +104 -0
- data/test/metric/remote_test.rb +108 -0
- data/test/myapp/app/controllers/application_controller.rb +2 -0
- data/test/myapp/app/controllers/main_controller.rb +7 -0
- data/test/myapp/config/boot.rb +110 -0
- data/test/myapp/config/environment.rb +10 -0
- data/test/myapp/config/environments/production.rb +0 -0
- data/test/myapp/config/routes.rb +3 -0
- data/test/passenger_test.rb +43 -0
- data/test/playground_test.rb +10 -0
- data/test/rails_test.rb +294 -0
- data/test/test_helper.rb +134 -0
- data/vanity.gemspec +25 -0
- metadata +161 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
$LOAD_PATH.delete_if { |path| path[/gems\/vanity-\d/] }
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
|
3
|
+
|
4
|
+
RAILS_ROOT = File.expand_path("..")
|
5
|
+
require "test/unit"
|
6
|
+
require "mocha"
|
7
|
+
require "action_controller"
|
8
|
+
require "action_controller/test_case"
|
9
|
+
require "active_record"
|
10
|
+
require "initializer"
|
11
|
+
Rails.configuration = Rails::Configuration.new
|
12
|
+
require "phusion_passenger/events"
|
13
|
+
require "lib/vanity"
|
14
|
+
require "timecop"
|
15
|
+
require "webmock/test_unit"
|
16
|
+
|
17
|
+
|
18
|
+
if $VERBOSE
|
19
|
+
$logger = Logger.new(STDOUT)
|
20
|
+
$logger.level = Logger::DEBUG
|
21
|
+
end
|
22
|
+
|
23
|
+
class Test::Unit::TestCase
|
24
|
+
include WebMock
|
25
|
+
|
26
|
+
def setup
|
27
|
+
FileUtils.mkpath "tmp/experiments/metrics"
|
28
|
+
new_playground
|
29
|
+
#WebMock.after_request do |request_signature, response|
|
30
|
+
# puts "Request #{request_signature} was made and #{response} was returned"
|
31
|
+
#end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Call this on teardown. It wipes put the playground and any state held in it
|
35
|
+
# (mostly experiments), resets vanity ID, and clears database of all experiments.
|
36
|
+
def nuke_playground
|
37
|
+
Vanity.playground.connection.flushdb
|
38
|
+
new_playground
|
39
|
+
end
|
40
|
+
|
41
|
+
# Call this if you need a new playground, e.g. to re-define the same experiment,
|
42
|
+
# or reload an experiment (saved by the previous playground).
|
43
|
+
def new_playground
|
44
|
+
adapter = ENV["ADAPTER"] || "redis"
|
45
|
+
# We go destructive on the database at the end of each run, so make sure we
|
46
|
+
# don't use databases you care about. For Redis, we pick database 15
|
47
|
+
# (default is 0).
|
48
|
+
spec = {
|
49
|
+
"redis"=>"redis://localhost/15",
|
50
|
+
"mongodb"=>"mongodb://localhost/vanity-test",
|
51
|
+
"mock"=>"mock:/"
|
52
|
+
}[adapter]
|
53
|
+
raise "No support yet for #{adapter}" unless spec
|
54
|
+
Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments")
|
55
|
+
Vanity.playground.establish_connection spec
|
56
|
+
end
|
57
|
+
|
58
|
+
# Defines the specified metrics (one or more names). Returns metric, or array
|
59
|
+
# of metric (if more than one argument).
|
60
|
+
def metric(*names)
|
61
|
+
metrics = names.map do |name|
|
62
|
+
id = name.to_s.downcase.gsub(/\W+/, '_').to_sym
|
63
|
+
Vanity.playground.metrics[id] ||= Vanity::Metric.new(Vanity.playground, name)
|
64
|
+
end
|
65
|
+
names.size == 1 ? metrics.first : metrics
|
66
|
+
end
|
67
|
+
|
68
|
+
# Defines an A/B experiment.
|
69
|
+
def new_ab_test(name, &block)
|
70
|
+
id = name.to_s.downcase.gsub(/\W/, "_").to_sym
|
71
|
+
experiment = Vanity::Experiment::AbTest.new(Vanity.playground, id, name)
|
72
|
+
experiment.instance_eval &block
|
73
|
+
experiment.save
|
74
|
+
Vanity.playground.experiments[id] = experiment
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns named experiment.
|
78
|
+
def experiment(name)
|
79
|
+
Vanity.playground.experiment(name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def today
|
83
|
+
@today ||= Date.today
|
84
|
+
end
|
85
|
+
|
86
|
+
def not_collecting!
|
87
|
+
Vanity.playground.collecting = false
|
88
|
+
Vanity.playground.stubs(:connection).returns(stub(:flushdb=>nil))
|
89
|
+
end
|
90
|
+
|
91
|
+
def teardown
|
92
|
+
Vanity.context = nil
|
93
|
+
FileUtils.rm_rf "tmp"
|
94
|
+
Vanity.playground.connection.flushdb if Vanity.playground.connected?
|
95
|
+
WebMock.reset_webmock
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
ActionController::Routing::Routes.draw do |map|
|
101
|
+
map.connect ':controller/:action/:id'
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
ActiveRecord::Base.logger = $logger
|
106
|
+
ActiveRecord::Base.establish_connection :adapter=>"sqlite3", :database=>File.expand_path("database.sqlite")
|
107
|
+
|
108
|
+
|
109
|
+
class Array
|
110
|
+
# Not in Ruby 1.8.6.
|
111
|
+
unless method_defined?(:shuffle)
|
112
|
+
def shuffle
|
113
|
+
copy = clone
|
114
|
+
Array.new(size) { copy.delete_at(Kernel.rand(copy.size)) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# Source: http://gist.github.com/25455
|
121
|
+
def context(*args, &block)
|
122
|
+
return super unless (name = args.first) && block
|
123
|
+
parent = Class === self ? self : (defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase)
|
124
|
+
klass = Class.new(parent) do
|
125
|
+
def self.test(name, &block)
|
126
|
+
define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
|
127
|
+
end
|
128
|
+
def self.xtest(*args) end
|
129
|
+
def self.setup(&block) define_method(:setup) { super() ; instance_eval &block } end
|
130
|
+
def self.teardown(&block) define_method(:teardown) { super() ; instance_eval &block } end
|
131
|
+
end
|
132
|
+
parent.const_set name.split(/\W+/).map(&:capitalize).join, klass
|
133
|
+
klass.class_eval &block
|
134
|
+
end
|
data/vanity.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + "/lib"
|
2
|
+
require "vanity/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "yacc-vanity"
|
6
|
+
spec.version = Vanity::VERSION
|
7
|
+
spec.author = "Yacin Bahi (forked from Assaf Arkin)"
|
8
|
+
spec.email = "assaf@labnotes.org"
|
9
|
+
spec.homepage = "http://vanity.labnotes.org"
|
10
|
+
spec.summary = "Experience Driven Development framework for Ruby"
|
11
|
+
spec.description = "Mirror, mirror on the wall ..."
|
12
|
+
spec.post_install_message = "To get started run vanity --help"
|
13
|
+
|
14
|
+
spec.files = Dir["{bin,lib,vendor,test}/**/*", "CHANGELOG", "MIT-LICENSE", "README.rdoc", "Rakefile", "Gemfile", "*.gemspec"]
|
15
|
+
spec.executable = "vanity"
|
16
|
+
|
17
|
+
spec.has_rdoc = true
|
18
|
+
spec.extra_rdoc_files = "README.rdoc", "CHANGELOG"
|
19
|
+
spec.rdoc_options = "--title", "Vanity #{spec.version}", "--main", "README.rdoc",
|
20
|
+
"--webcvs", "http://github.com/assaf/#{spec.name}"
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 1.8.7'
|
23
|
+
spec.add_dependency "redis", "~>2.0"
|
24
|
+
spec.add_dependency "redis-namespace", "~>0.7"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yacc-vanity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 5
|
9
|
+
- 1
|
10
|
+
version: 1.5.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Yacin Bahi (forked from Assaf Arkin)
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-03 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: redis
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
version: "2.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: redis-namespace
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 7
|
48
|
+
version: "0.7"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Mirror, mirror on the wall ...
|
52
|
+
email: assaf@labnotes.org
|
53
|
+
executables:
|
54
|
+
- vanity
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README.rdoc
|
59
|
+
- CHANGELOG
|
60
|
+
files:
|
61
|
+
- bin/vanity
|
62
|
+
- lib/vanity/commands/upgrade.rb
|
63
|
+
- lib/vanity/commands/list.rb
|
64
|
+
- lib/vanity/commands/report.rb
|
65
|
+
- lib/vanity/metric/google_analytics.rb
|
66
|
+
- lib/vanity/metric/active_record.rb
|
67
|
+
- lib/vanity/metric/remote.rb
|
68
|
+
- lib/vanity/metric/base.rb
|
69
|
+
- lib/vanity/adapters/mock_adapter.rb
|
70
|
+
- lib/vanity/adapters/redis_adapter.rb
|
71
|
+
- lib/vanity/adapters/active_record_adapter.rb
|
72
|
+
- lib/vanity/adapters/mongodb_adapter.rb
|
73
|
+
- lib/vanity/adapters/abstract_adapter.rb
|
74
|
+
- lib/vanity/templates/vanity.css
|
75
|
+
- lib/vanity/templates/_metric.erb
|
76
|
+
- lib/vanity/templates/_experiments.erb
|
77
|
+
- lib/vanity/templates/_experiment.erb
|
78
|
+
- lib/vanity/templates/_metrics.erb
|
79
|
+
- lib/vanity/templates/jquery.min.js
|
80
|
+
- lib/vanity/templates/_report.erb
|
81
|
+
- lib/vanity/templates/flot.min.js
|
82
|
+
- lib/vanity/templates/vanity.js
|
83
|
+
- lib/vanity/templates/_ab_test.erb
|
84
|
+
- lib/vanity/frameworks/rails.rb
|
85
|
+
- lib/vanity/helpers.rb
|
86
|
+
- lib/vanity/playground.rb
|
87
|
+
- lib/vanity/backport.rb
|
88
|
+
- lib/vanity/experiment/ab_test.rb
|
89
|
+
- lib/vanity/experiment/base.rb
|
90
|
+
- lib/vanity/version.rb
|
91
|
+
- lib/vanity.rb
|
92
|
+
- test/test_helper.rb
|
93
|
+
- test/passenger_test.rb
|
94
|
+
- test/experiments/metrics/cheers.rb
|
95
|
+
- test/experiments/metrics/signups.rb
|
96
|
+
- test/experiments/metrics/yawns.rb
|
97
|
+
- test/experiments/null_abc.rb
|
98
|
+
- test/experiments/age_and_zipcode.rb
|
99
|
+
- test/metric/base_test.rb
|
100
|
+
- test/metric/remote_test.rb
|
101
|
+
- test/metric/active_record_test.rb
|
102
|
+
- test/metric/google_analytics_test.rb
|
103
|
+
- test/rails_test.rb
|
104
|
+
- test/myapp/config/environments/production.rb
|
105
|
+
- test/myapp/config/routes.rb
|
106
|
+
- test/myapp/config/boot.rb
|
107
|
+
- test/myapp/config/environment.rb
|
108
|
+
- test/myapp/app/controllers/application_controller.rb
|
109
|
+
- test/myapp/app/controllers/main_controller.rb
|
110
|
+
- test/playground_test.rb
|
111
|
+
- test/experiment/base_test.rb
|
112
|
+
- test/experiment/ab_test.rb
|
113
|
+
- CHANGELOG
|
114
|
+
- MIT-LICENSE
|
115
|
+
- README.rdoc
|
116
|
+
- Rakefile
|
117
|
+
- Gemfile
|
118
|
+
- vanity.gemspec
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: http://vanity.labnotes.org
|
121
|
+
licenses: []
|
122
|
+
|
123
|
+
post_install_message: To get started run vanity --help
|
124
|
+
rdoc_options:
|
125
|
+
- --title
|
126
|
+
- Vanity 1.5.1
|
127
|
+
- --main
|
128
|
+
- README.rdoc
|
129
|
+
- --webcvs
|
130
|
+
- http://github.com/assaf/yacc-vanity
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 57
|
139
|
+
segments:
|
140
|
+
- 1
|
141
|
+
- 8
|
142
|
+
- 7
|
143
|
+
version: 1.8.7
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
requirements: []
|
154
|
+
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.3.7
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Experience Driven Development framework for Ruby
|
160
|
+
test_files: []
|
161
|
+
|