Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Replace bespoke spec framework with minitest/spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
phillbaker committed May 1, 2014
1 parent 0f2f78f commit 5d360ba
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 143 deletions.
34 changes: 18 additions & 16 deletions test/autoconnect_test.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
require "test_helper"

context ".playground_should_autoconnect?" do
describe Vanity::Autoconnect do
describe ".playground_should_autoconnect?" do

test "returns true by default" do
autoconnect = Vanity::Autoconnect.playground_should_autoconnect?
assert autoconnect == true
end
it "returns true by default" do
autoconnect = Vanity::Autoconnect.playground_should_autoconnect?
assert autoconnect == true
end

test "returns false if environment flag is set" do
ENV['VANITY_DISABLED'] = '1'
autoconnect = Vanity::Autoconnect.playground_should_autoconnect?
assert autoconnect == false
ENV['VANITY_DISABLED'] = nil
end
it "returns false if environment flag is set" do
ENV['VANITY_DISABLED'] = '1'
autoconnect = Vanity::Autoconnect.playground_should_autoconnect?
assert autoconnect == false
ENV['VANITY_DISABLED'] = nil
end

test "returns false if in assets:precompile rake task" do
Rake.expects(:application).returns(stub(:top_level_tasks => ['assets:precompile']))
autoconnect = Vanity::Autoconnect.playground_should_autoconnect?
assert autoconnect == false
it "returns false if in assets:precompile rake task" do
Rake.expects(:application).returns(stub(:top_level_tasks => ['assets:precompile']))
autoconnect = Vanity::Autoconnect.playground_should_autoconnect?
assert autoconnect == false
end
end
end
end
21 changes: 12 additions & 9 deletions test/helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require "test_helper"

context "Object#track!" do
test "identity option sets identity" do
metric "Coolness"
new_ab_test :foobar do
alternatives "foo", "bar"
metrics :coolness
end
track! :coolness, :identity=>'quux', :values=>[2]
describe Object do
describe "#track!" do
it "identity option sets identity" do
metric "Coolness"
new_ab_test :foobar do
alternatives "foo", "bar"
metrics :coolness
end
track! :coolness, :identity=>'quux', :values=>[2]

assert_equal 2, experiment(:foobar).alternatives.sum(&:conversions)
# experiment(:foobar).alternatives.sum(&:conversions).must_equal 2
assert_equal 2, experiment(:foobar).alternatives.sum(&:conversions)
end
end
end
56 changes: 28 additions & 28 deletions test/metric/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ class Sky < ActiveRecord::Base

if ActiveRecord::Base.connected?

context "ActiveRecord Metric" do
describe "ActiveRecord Metric" do

test "record count" do
after do
Sky.delete_all
if rails3?
Sky.reset_callbacks(:create)
Sky.reset_callbacks(:save)
else
Sky.after_create.clear
Sky.after_save.clear
end
end

it "record count" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -34,7 +45,7 @@ class Sky < ActiveRecord::Base
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "record sum" do
it "record sum" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -48,7 +59,7 @@ class Sky < ActiveRecord::Base
assert_equal 6, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "record average" do
it "record average" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -62,7 +73,7 @@ class Sky < ActiveRecord::Base
assert_equal 5, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "record minimum" do
it "record minimum" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -76,7 +87,7 @@ class Sky < ActiveRecord::Base
assert_equal 2, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "record maximum" do
it "record maximum" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -90,7 +101,7 @@ class Sky < ActiveRecord::Base
assert_equal 4, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "with conditions" do
it "with conditions" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -111,7 +122,7 @@ class Sky < ActiveRecord::Base
assert_equal 11, high_skies
end

test "with scope" do
it "with scope" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -130,7 +141,7 @@ class Sky < ActiveRecord::Base
assert_equal 1, total
end

test "with timestamp" do
it "with timestamp" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -144,7 +155,7 @@ class Sky < ActiveRecord::Base
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "with timestamp and table" do
it "with timestamp and table" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -158,7 +169,7 @@ class Sky < ActiveRecord::Base
assert_equal 1, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "hooks" do
it "hooks" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -177,7 +188,7 @@ class Sky < ActiveRecord::Base
assert_equal 4, total
end

test "no hooks when metrics disabled" do
it "no hooks when metrics disabled" do
not_collecting!
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
Expand All @@ -195,7 +206,7 @@ class Sky < ActiveRecord::Base
assert_equal 0, total
end

test "after_create not after_save" do
it "after_create not after_save" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -213,7 +224,7 @@ class Sky < ActiveRecord::Base
Sky.last.update_attributes :height=>4
end

test "with after_save" do
it "with after_save" do
if rails3?
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
Expand Down Expand Up @@ -245,7 +256,7 @@ class Sky < ActiveRecord::Base
assert_equal 2, times
end

test "do it youself" do
it "do it youself" do
if rails3?
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
Expand All @@ -272,7 +283,7 @@ class Sky < ActiveRecord::Base
assert_equal 3, Vanity::Metric.data(metric(:sky_is_limit)).last.last
end

test "last update for new metric" do
it "last update for new metric" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -283,7 +294,7 @@ class Sky < ActiveRecord::Base
assert_nil metric(:sky_is_limit).last_update_at
end

test "last update with records" do
it "last update with records" do
File.open "tmp/experiments/metrics/sky_is_limit.rb", "w" do |f|
f.write <<-RUBY
metric "Sky is limit" do
Expand All @@ -297,17 +308,6 @@ class Sky < ActiveRecord::Base
end
assert_in_delta metric(:sky_is_limit).last_update_at.to_i, (Time.now + 1.day).to_i, 1
end

teardown do
Sky.delete_all
if rails3?
Sky.reset_callbacks(:create)
Sky.reset_callbacks(:save)
else
Sky.after_create.clear
Sky.after_save.clear
end
end
end

end
Loading

0 comments on commit 5d360ba

Please sign in to comment.