vanity 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_helper.rb CHANGED
@@ -5,11 +5,20 @@ require "test/unit"
5
5
  require "mocha"
6
6
  require "action_controller"
7
7
  require "action_controller/test_case"
8
+ require "active_record"
8
9
  require "initializer"
9
- require "lib/vanity/rails"
10
+ Rails.configuration = Rails::Configuration.new
11
+ require "lib/vanity"
10
12
  require "timecop"
11
13
 
12
14
 
15
+ if $VERBOSE
16
+ $logger = Logger.new(STDOUT)
17
+ $logger.level = Logger::DEBUG
18
+ else
19
+ $logger = Logger.new("/dev/null")
20
+ end
21
+
13
22
  class Test::Unit::TestCase
14
23
 
15
24
  def setup
@@ -27,8 +36,7 @@ class Test::Unit::TestCase
27
36
  # Call this if you need a new playground, e.g. to re-define the same experiment,
28
37
  # or reload an experiment (saved by the previous playground).
29
38
  def new_playground
30
- logger = Logger.new("/dev/null") unless $VERBOSE
31
- Vanity.playground = Vanity::Playground.new(:logger=>logger, :load_path=>"tmp/experiments", :db=>15)
39
+ Vanity.playground = Vanity::Playground.new(:logger=>$logger, :load_path=>"tmp/experiments", :db=>15)
32
40
  Vanity.playground.mock! unless ENV["REDIS"]
33
41
  end
34
42
 
@@ -41,6 +49,11 @@ class Test::Unit::TestCase
41
49
  end
42
50
  names.size == 1 ? metrics.first : metrics
43
51
  end
52
+
53
+ # Returns named experiment.
54
+ def experiment(name)
55
+ Vanity.playground.experiment(name)
56
+ end
44
57
 
45
58
  def teardown
46
59
  Vanity.context = nil
@@ -53,7 +66,37 @@ end
53
66
  ActionController::Routing::Routes.draw do |map|
54
67
  map.connect ':controller/:action/:id'
55
68
  end
56
- Rails.configuration = Rails::Configuration.new
69
+
70
+
71
+ ActiveRecord::Base.logger = $logger
72
+ ActiveRecord::Base.establish_connection :adapter=>"sqlite3", :database=>File.expand_path("database.sqlite")
73
+ # Call this to define aggregate functions not available in SQlite.
74
+ class ActiveRecord::Base
75
+ def self.aggregates
76
+ connection.raw_connection.create_aggregate("minimum", 1) do
77
+ step do |func, value|
78
+ func[:minimum] = value.to_i unless func[:minimum] && func[:minimum].to_i < value.to_i
79
+ end
80
+ finalize { |func| func.result = func[:minimum] }
81
+ end
82
+
83
+ connection.raw_connection.create_aggregate("maximum", 1) do
84
+ step do |func, value|
85
+ func[:maximum] = value.to_i unless func[:maximum] && func[:maximum].to_i > value.to_i
86
+ end
87
+ finalize { |func| func.result = func[:maximum] }
88
+ end
89
+
90
+ connection.raw_connection.create_aggregate("average", 1) do
91
+ step do |func, value|
92
+ func[:total] = func[:total].to_i + value.to_i
93
+ func[:count] = func[:count].to_i + 1
94
+ end
95
+ finalize { |func| func.result = func[:total].to_i / func[:count].to_i }
96
+ end
97
+ end
98
+ end
99
+
57
100
 
58
101
  class Array
59
102
  # Not in Ruby 1.8.6.
@@ -64,3 +107,20 @@ class Array
64
107
  end
65
108
  end
66
109
  end
110
+
111
+
112
+ # Source: http://gist.github.com/25455
113
+ def context(*args, &block)
114
+ return super unless (name = args.first) && block
115
+ parent = Class === self ? self : (defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase)
116
+ klass = Class.new(parent) do
117
+ def self.test(name, &block)
118
+ define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
119
+ end
120
+ def self.xtest(*args) end
121
+ def self.setup(&block) define_method(:setup) { super() ; block.call } end
122
+ def self.teardown(&block) define_method(:teardown) { super() ; block.call } end
123
+ end
124
+ parent.const_set name.split(/\W+/).map(&:capitalize).join, klass
125
+ klass.class_eval &block
126
+ end
data/vanity.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "vanity"
3
- spec.version = "1.1.1"
3
+ spec.version = "1.2.0"
4
4
  spec.author = "Assaf Arkin"
5
5
  spec.email = "assaf@labnotes.org"
6
6
  spec.homepage = "http://vanity.labnotes.org"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Assaf Arkin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-04 00:00:00 -08:00
12
+ date: 2009-12-14 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,7 @@ files:
29
29
  - lib/vanity/commands.rb
30
30
  - lib/vanity/experiment/ab_test.rb
31
31
  - lib/vanity/experiment/base.rb
32
+ - lib/vanity/helpers.rb
32
33
  - lib/vanity/metric.rb
33
34
  - lib/vanity/mock_redis.rb
34
35
  - lib/vanity/playground.rb
@@ -91,7 +92,7 @@ licenses: []
91
92
  post_install_message: To get started run vanity --help
92
93
  rdoc_options:
93
94
  - --title
94
- - Vanity 1.1.1
95
+ - Vanity 1.2.0
95
96
  - --main
96
97
  - README.rdoc
97
98
  - --webcvs