Skip to content

Commit

Permalink
fixed loadpaths and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Adkisson committed May 3, 2010
1 parent 99342d8 commit 832df37
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 41 deletions.
3 changes: 2 additions & 1 deletion lib/modesty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ module Modesty
require 'modesty/metric.rb'
require 'modesty/experiment.rb'
require 'modesty/load.rb'
$:.shift

if defined? Rails
require 'modesty/frameworks/rails'
end

$:.shift
2 changes: 1 addition & 1 deletion lib/modesty/frameworks/rails.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Modesty.root = File.join(Rails.root, 'modesty')
Modesty.config_path = File.join(Rails.root, 'config/modesty.yml')
Modesty.config_path = File.join(Rails.root, 'config', 'modesty.yml')
Modesty.environment = Rails.env

Rails.configuration.after_initialize do
Expand Down
33 changes: 17 additions & 16 deletions spec/experiment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'modesty'

describe Modesty::Experiment, "creating an experiment" do
before :all do
Modesty.metrics = {}
before :each do
Modesty.metrics.clear
Modesty.experiments.clear
Modesty.new_metric :foo do |m|
m.description "Foo"
m.submetric :bar do |m|
Expand All @@ -13,31 +14,31 @@
Modesty.new_metric :baz do |m|
m.description "Baz"
end
end

it "can create an experiment with a block" do
e = Modesty.new_experiment(:creation_page) do |m|
@e = Modesty.new_experiment(:creation_page) do |m|
m.description "Three versions of the creation page"
m.alternatives :heavyweight, :lightweight
m.metrics :foo/:bar, :baz
end

@f = Modesty.new_experiment :ab_test do |e|
e.description "only two groups"
e.metrics :baz
end
end

it "can create an experiment with a block" do
Modesty.experiments.should include :creation_page
Modesty.experiments[:creation_page].should == e
Modesty.experiments[:creation_page].should == @e

e.metrics.should include Modesty.metrics[:foo/:bar]
e.metrics.should include Modesty.metrics[:baz]
e.alternatives.should == [:control, :heavyweight, :lightweight]
e.description.should == "Three versions of the creation page"
@e.metrics.should include Modesty.metrics[:foo/:bar]
@e.metrics.should include Modesty.metrics[:baz]
@e.alternatives.should == [:control, :heavyweight, :lightweight]
@e.description.should == "Three versions of the creation page"
end

it "uses [:control, :experiment] as the default experiment groups" do
e = Modesty.new_experiment :ab_test do |e|
e.description "only two groups"
e.metrics :baz
end

e.alternatives.should == [:control, :experiment]
@f.alternatives.should == [:control, :experiment]
end

it "auto-creates metrics" do
Expand Down
16 changes: 6 additions & 10 deletions spec/load_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
before :all do
Modesty.root = File.join(
Modesty::TEST,
'myapp'
'myapp',
'modesty'
)
Modesty.environment = 'test'
Modesty.load_config!
Expand All @@ -15,7 +16,7 @@
File.expand_path(
File.join(
File.dirname(__FILE__),
"../test/myapp/experiments/metrics"
"../test/myapp/modesty/metrics"
)
)
end
Expand All @@ -33,7 +34,7 @@
)

Modesty.environment = 'test'
Modesty.metrics = {}
Modesty.metrics.clear
end

it "can load metrics" do
Expand Down Expand Up @@ -63,15 +64,15 @@

after :all do
Modesty.root = nil
Modesty.metrics = {}
end
end

describe "Loading experiments" do
before :all do
Modesty.environment = 'test'
Modesty.metrics.clear
Modesty.experiments.clear
Modesty.load_all_metrics!
Modesty.experiments = {}
end

it "can load experiments" do
Expand All @@ -83,9 +84,4 @@
it "actually loads experiments" do
Modesty.experiments.should include :cookbook
end

after :all do
Modesty.metrics = {}
Modesty.experiments = {}
end
end
16 changes: 4 additions & 12 deletions spec/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
require 'modesty'

describe "bootstrap" do
before :all do
Modesty.root = File.join(
Modesty::TEST,
'myapp'
)
Modesty.metrics = {}
Modesty.experiments = {}
Modesty.load!
Modesty.data.flushdb
Modesty.metrics.clear
Modesty.experiments.clear

unless defined? Rails
class Rails
Expand All @@ -32,10 +26,8 @@ def self.after_initialize
end
end
end
end

it "can bootstrap" do
lambda { require 'modesty/frameworks/rails.rb' }.should_not raise_error
require 'modesty/frameworks/rails'
end

it "bootstraps Redis" do
Expand Down
2 changes: 1 addition & 1 deletion test/myapp/config/modesty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ test:

paths:
experiments: experiments
metrics: experiments/metrics
metrics: metrics
File renamed without changes.

0 comments on commit 832df37

Please sign in to comment.