Permalink
Browse files

All tests green on Ruby 1.8.6

  • Loading branch information...
1 parent 0731d3b commit 3a5e8529bc08dbb09e28e27c66b2e6668139df2e @assaf assaf committed Nov 25, 2009
Showing with 21 additions and 7 deletions.
  1. +3 −0 CHANGELOG
  2. +3 −3 lib/vanity/experiment/ab_test.rb
  3. +1 −1 test/ab_test_test.rb
  4. +2 −2 test/metric_test.rb
  5. +1 −1 test/playground_test.rb
  6. +11 −0 test/test_helper.rb
View
@@ -1,5 +1,8 @@
== 1.1.0
+This release introduces metrics. Metrics are the gateway drug to better software.
+* Added: Metrics.
+* Changed: All tests are green on Ruby 1.8.6, 1.8.7 and 1.9.1.
* Deprecated: Please call experiment method with experiment identifier (a symbol) and not experiment name.
== 1.0.0 (2009-11-19)
@@ -370,7 +370,7 @@ def complete!
# -- Store/validate --
def destroy
- @alternatives.count.times do |i|
+ @alternatives.size.times do |i|
redis.del key("alts:#{i}:participants")
redis.del key("alts:#{i}:converted")
redis.del key("alts:#{i}:conversions")
@@ -380,7 +380,7 @@ def destroy
end
def save
- fail "Experiment #{name} needs at least two alternatives" unless alternatives.count >= 2
+ fail "Experiment #{name} needs at least two alternatives" unless alternatives.size >= 2
super
end
@@ -391,7 +391,7 @@ def save
# identity, and randomly distributed alternatives for each identity (in the
# same experiment).
def alternative_for(identity)
- Digest::MD5.hexdigest("#{name}/#{identity}").to_i(17) % @alternatives.count
+ Digest::MD5.hexdigest("#{name}/#{identity}").to_i(17) % @alternatives.size
end
# Used for testing Vanity.
View
@@ -82,7 +82,7 @@ def test_returns_different_alternatives_for_each_participant
end
alts = Array.new(1000) { experiment(:foobar).choose }
assert_equal %w{bar foo}, alts.uniq.sort
- assert_in_delta alts.select { |a| a == "foo" }.count, 500, 100 # this may fail, such is propability
+ assert_in_delta alts.select { |a| a == "foo" }.size, 500, 100 # this may fail, such is propability
end
def test_records_all_participants_in_each_alternative
View
@@ -70,10 +70,10 @@ def test_metric_name_must_match_file_name
def test_reloading_metrics
Vanity.playground.metric(:yawns_sec)
Vanity.playground.metric(:cheers_sec)
- assert 2, Vanity.playground.metrics.count
+ assert 2, Vanity.playground.metrics.size
metrics = Vanity.playground.metrics.values
Vanity.playground.reload!
- assert 2, Vanity.playground.metrics.count
+ assert 2, Vanity.playground.metrics.size
assert_not_equal metrics, Vanity.playground.metrics.values
end
View
@@ -50,7 +50,7 @@ def test_complains_if_not_defined_where_expected
def test_reloading_experiments
Vanity.playground.define(:ab, :ab_test) {}
Vanity.playground.define(:cd, :ab_test) {}
- assert 2, Vanity.playground.experiments.count
+ assert 2, Vanity.playground.experiments.size
Vanity.playground.reload!
assert Vanity.playground.experiments.empty?
end
View
@@ -53,3 +53,14 @@ def teardown
# around permission issues in some places.
ENV["TMPDIR"] = File.expand_path("tmp")
Vanity::Playground::DEFAULTS[:load_path] = "tmp/experiments"
+
+
+class Array
+ # Not in Ruby 1.8.6.
+ unless method_defined?(:shuffle)
+ def shuffle
+ copy = clone
+ Array.new(size) { copy.delete_at(Kernel.rand(copy.size)) }
+ end
+ end
+end

0 comments on commit 3a5e852

Please sign in to comment.