vanity 2.0.0.beta4 → 2.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +4 -0
  3. data/Appraisals +14 -0
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +5 -3
  6. data/README.rdoc +5 -1
  7. data/config/locales/vanity.en.yml +39 -0
  8. data/config/locales/vanity.pt-BR.yml +41 -0
  9. data/doc/ab_testing.textile +1 -1
  10. data/doc/rails.textile +13 -0
  11. data/gemfiles/rails32.gemfile +2 -2
  12. data/gemfiles/rails32.gemfile.lock +4 -3
  13. data/gemfiles/rails4.gemfile +2 -2
  14. data/gemfiles/rails4.gemfile.lock +4 -3
  15. data/gemfiles/rails41.gemfile +29 -0
  16. data/gemfiles/rails41.gemfile.lock +196 -0
  17. data/gemfiles/rails42.gemfile +29 -0
  18. data/gemfiles/rails42.gemfile.lock +235 -0
  19. data/lib/generators/templates/vanity_migration.rb +1 -1
  20. data/lib/generators/vanity/views_generator.rb +16 -0
  21. data/lib/vanity.rb +1 -0
  22. data/lib/vanity/experiment/ab_test.rb +15 -15
  23. data/lib/vanity/experiment/alternative.rb +2 -2
  24. data/lib/vanity/frameworks/rails.rb +16 -3
  25. data/lib/vanity/metric/active_record.rb +1 -1
  26. data/lib/vanity/playground.rb +19 -25
  27. data/lib/vanity/templates.rb +29 -0
  28. data/lib/vanity/templates/_ab_test.erb +12 -12
  29. data/lib/vanity/templates/_experiment.erb +4 -2
  30. data/lib/vanity/templates/_participant.erb +2 -2
  31. data/lib/vanity/templates/_report.erb +6 -6
  32. data/lib/vanity/templates/_vanity.js.erb +13 -15
  33. data/lib/vanity/templates/vanity.css +4 -4
  34. data/lib/vanity/version.rb +1 -1
  35. data/test/frameworks/rails/action_controller_test.rb +1 -1
  36. data/test/frameworks/rails/rails_test.rb +118 -102
  37. data/test/playground_test.rb +13 -0
  38. data/test/templates_test.rb +28 -0
  39. data/test/test_helper.rb +15 -17
  40. data/test/web/rails/dashboard_test.rb +25 -4
  41. data/vanity.gemspec +2 -0
  42. metadata +36 -18
@@ -0,0 +1,29 @@
1
+ module Vanity
2
+ class Templates
3
+ def initialize
4
+ @template_directory = load_paths.find { |dir| File.exists?(dir) }
5
+ end
6
+
7
+ # Path to template.
8
+ def path(name)
9
+ File.join(@template_directory, name)
10
+ end
11
+
12
+ private
13
+
14
+ def load_paths
15
+ [Vanity.playground.custom_templates_path, gem_templates_path].compact
16
+ end
17
+
18
+ def gem_templates_path
19
+ File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def template(name)
25
+ @templates ||= Templates.new
26
+ @templates.path(name)
27
+ end
28
+ end
29
+ end
@@ -7,33 +7,33 @@
7
7
  <tr class="<%= "choice" if score.choice == alt %>">
8
8
  <td class="option"><%= alt.name.gsub(/^o/, "O") %>:</td>
9
9
  <td class="value"><code><%=vanity_h alt.value.to_s %></code></td>
10
- <td class="value"><%= alt.participants %> participants</td>
11
- <td class="value"><%= alt.converted %> converted</td>
10
+ <td class="value"><%= I18n.t 'vanity.participants', :count=>alt.participants %></td>
11
+ <td class="value"><%= I18n.t 'vanity.converted', :count=>alt.converted %></td>
12
12
  <td>
13
13
  <%= "%.1f%%" % [alt.conversion_rate * 100] %>
14
- <%= "(%d%% this is best)" % [alt.probability] if score.method == :bayes_score %>
15
- <%= "(%d%% better than %s)" % [alt.difference, score.least.name] if alt.difference && alt.difference >= 1 %>
14
+ <%= I18n.t('vanity.best_alternative', :probabilty=>alt.probability.to_i) if score.method == :bayes_score %>
15
+ <%= I18n.t('vanity.better_alternative_than', :probability=>alt.difference.to_i, :alternative=>score.least.name) if alt.difference && alt.difference >= 1 %>
16
16
  </td>
17
17
  <% if experiment.active? && respond_to?(:url_for) %>
18
18
  <td class="action">
19
19
  <small>
20
20
  <% if experiment.showing?(alt) %>
21
- currently <br> shown
21
+ <%= I18n.t 'vanity.currently_shown' %>
22
22
  <% else %>
23
- <a class="button chooses" title="Show me this alternative from now on" href="#"
24
- data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:chooses, :e=>experiment.id, :a=>alt.id) %>">show me</a>
23
+ <a class="button chooses" title="<%= I18n.t 'vanity.choose_experiment' %>" href="#"
24
+ data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:chooses, :e=>experiment.id, :a=>alt.id) %>"><%= I18n.t 'vanity.show_me' %></a>
25
25
  <% end %>
26
26
  </small>
27
27
  </td>
28
28
  <td class="action">
29
29
  <small>
30
30
  <% if @to_confirm == alt.id %>
31
- Finish this experiment and assign all current and future participants to <%= alt.name %>?
32
- <a class="button chooses" title="Confirm experiment completion and assignment of all current and future participants to <%= alt.name %>" href="#"
33
- data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id, :confirmed=>alt.id) %>">confirm</a>
31
+ <%= I18n.t 'vanity.complete_and_confirm_experiment_label', :name=>alt.name %>
32
+ <a class="button chooses" title="<%= I18n.t 'vanity.complete_and_confirm_experiment', name: alt.name %>" href="#"
33
+ data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id, :confirmed=>alt.id) %>"><%= I18n.t 'vanity.confirm' %></a>
34
34
  <% else %>
35
- <a class="button chooses" title="Complete the experiment and assign all current and future participants to <%= alt.name %>" href="#"
36
- data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id) %>">make permanent</a>
35
+ <a class="button chooses" title="<%= I18n.t 'vanity.complete_experiment', :name=>alt.name %>" href="#"
36
+ data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:complete, :e=>experiment.id, :a=>alt.id) %>"><%= I18n.t 'vanity.make_permanent' %></a>
37
37
  <% end %>
38
38
  </small>
39
39
  </td>
@@ -1,5 +1,7 @@
1
1
  <h3><%=vanity_h experiment.name %> <span class="type">(<%= experiment.class.friendly_name %>)</span></h3>
2
2
  <%= experiment.description.to_s.split(/\n\s*\n/).map { |para| vanity_html_safe(%{<p class="description">#{vanity_h para}</p>}) }.join.html_safe %>
3
3
  <%= render :file => Vanity.template("_" + experiment.type), :locals => {:experiment => experiment} %>
4
- <p class="meta">Started <%= experiment.created_at.strftime("%a, %b %d") %>
5
- <%= " | Completed #{experiment.completed_at.strftime("%a, %b %d")}" unless experiment.active? %></p>
4
+ <p class="meta">
5
+ <%= I18n.t('vanity.started_at', :timestamp=>I18n.l(experiment.created_at, :format=>'%a, %b %d')) %>
6
+ <%= ' | '+I18n.t('vanity.completed_at', :timestamp=>I18n.l(experiment.completed_at, :format=>'%a, %b %d')) unless experiment.active? %>
7
+ </p>
@@ -1,4 +1,4 @@
1
- <p>Participant id <%= participant_id %> is taking part in the following experiments:
1
+ <p><%= I18n.t 'vanity.participant_taking_part_on', :participant_id=>participant_id %>
2
2
  <ul class="experiments">
3
3
  <% participant_info.each do |experiment, alt| %>
4
4
  <li class="experiment <%= experiment.type %>" id="experiment_<%=vanity_h experiment.id.to_s %>">
@@ -9,4 +9,4 @@
9
9
  </li>
10
10
  <% end %>
11
11
  </ul>
12
- </p>
12
+ </p>
@@ -1,6 +1,6 @@
1
1
  <html>
2
2
  <head>
3
- <title>Vanity Report: <%= Time.now.strftime("%b %d %Y, %I:%M:%P") %></title>
3
+ <title><%= I18n.t('vanity.report', :timestamp=>I18n.l(Time.now, :format=>'%b %d %Y, %I:%M:%P')) %></title>
4
4
  <style>
5
5
  .vanity { margin: 2em auto; width: 40em; font-family: "Helvetica Neue", "Helvetica", "Verdana", sans-serif }
6
6
  .vanity h1 { margin: 1em 0; border-bottom: 3px solid #ccc }
@@ -15,27 +15,27 @@
15
15
  <div class="vanity">
16
16
  <% unless Vanity.playground.collecting? %>
17
17
  <div class="alert collecting">
18
- Vanity is currently not collecting data or metrics. To turn on data collection, set <span style='font-family: courier'>Vanity.playground.collecting = true;</span> in <span style='font-family: courier'>config/environments/[environment].rb</span>.
18
+ <%= I18n.t('vanity.not_collecting_data', :setting=>"<span style='font-family: courier'>Vanity.playground.collecting = true;</span>", :file=>"<span style='font-family: courier'>config/environments/[environment].rb</span>").html_safe %>
19
19
  </div>
20
20
  <% end %>
21
21
 
22
22
  <% if experiments_persisted %>
23
23
  <% if experiments.present? %>
24
- <h2>Experiments</h2>
24
+ <h2><%= I18n.t 'vanity.experiments' %></h2>
25
25
  <%= render :file=>Vanity.template("_experiments"), :locals=>{:experiments=>experiments} %>
26
26
  <% end %>
27
27
 
28
28
  <% unless metrics.empty? %>
29
- <h2>Metrics</h2>
29
+ <h2><%= I18n.t 'vanity.metrics' %></h2>
30
30
  <%= render :file=>Vanity.template("_metrics"), :locals=>{:metrics=>metrics, :experiments=>experiments} %>
31
31
  <% end %>
32
32
  <% else %>
33
33
  <div class="alert persistance">
34
- Vanity's cached experiments are out of sync with those on the filesystem and/or those in the datastore. Please restart your server and/or turn on collecting.
34
+ <%= I18n.t 'vanity.experiments_out_of_sync' %>
35
35
  </div>
36
36
  <% end %>
37
37
 
38
- <p class="footer">Generated by <a href="http://vanity.labnotes.org">Vanity</a></p>
38
+ <p class="footer"><%= I18n.t('vanity.generated_by', :link=>'<a href="http://vanity.labnotes.org">Vanity</a>').html_safe %></p>
39
39
  </div>
40
40
  </body>
41
41
  </html>
@@ -1,16 +1,14 @@
1
1
  var httpRequest;
2
- <% @_vanity_experiments.each do |name, alternative| %>
3
- var params = "e=<%= name %>&a=<%= alternative.id %>&authenticity_token=<%= CGI.escape(form_authenticity_token) %>";
4
- if (window.XMLHttpRequest) { // Mozilla, Safari, ...
5
- httpRequest = new XMLHttpRequest();
6
- } else if (window.ActiveXObject) { // IE
7
- try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
8
- catch (e) { }
9
- }
10
- if (httpRequest) {
11
- httpRequest.open('POST', "<%= Vanity.playground.add_participant_path %>", true);
12
- httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
13
- httpRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest");
14
- httpRequest.send(params);
15
- }
16
- <% end %>
2
+ var params = "v=<%= @_vanity_experiments.map{|name, alternative| "#{name}=#{alternative.id}" }.join(',') %>&authenticity_token=<%= CGI.escape(form_authenticity_token) %>";
3
+ if (window.XMLHttpRequest) { // Mozilla, Safari, ...
4
+ httpRequest = new XMLHttpRequest();
5
+ } else if (window.ActiveXObject) { // IE
6
+ try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
7
+ catch (e) { }
8
+ }
9
+ if (httpRequest) {
10
+ httpRequest.open('POST', "<%= Vanity.playground.add_participant_path %>", true);
11
+ httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
12
+ httpRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest");
13
+ httpRequest.send(params);
14
+ }
@@ -9,12 +9,12 @@
9
9
  .vanity .experiment .type { margin-left: .3em; color: #bbb; font-size: .8em; font-weight: normal }
10
10
 
11
11
  .vanity .ab_test table { border-collapse: collapse; table-layout: fixed; width: 100%; border-bottom: 1px solid #ccc; margin: 1em 0 0 0 }
12
- .vanity .ab_test td { padding: .5em; border-top: 1px solid #ccc }
12
+ .vanity .ab_test td { padding: .5em; border-top: 1px solid #ccc; width: 2em; overflow: hidden }
13
13
  .vanity .ab_test .choice td { font-weight: bold; background: #f0f0f8 }
14
14
  .vanity .ab_test caption { caption-side: bottom; padding: .5em; background: transparent; text-align: left }
15
- .vanity .ab_test td.option { width: 5em; white-space: nowrap; overflow: hidden }
16
- .vanity .ab_test td.value { width: 8em; overflow: hidden }
17
- .vanity .ab_test td.action { width: 6em; overflow: hidden; text-align: right }
15
+ .vanity .ab_test td.option { width: 5em; white-space: nowrap; }
16
+ .vanity .ab_test td.value { width: 8em; }
17
+ .vanity .ab_test td.action { width: 6em; text-align: right }
18
18
 
19
19
  .vanity .metrics { list-style: none; margin: 0; padding: 0; border-bottom: 1px solid #ddd }
20
20
  .vanity .metric { margin: 2em 0 }
@@ -1,5 +1,5 @@
1
1
  module Vanity
2
- VERSION = "2.0.0.beta4"
2
+ VERSION = "2.0.0.beta5"
3
3
 
4
4
  module Version
5
5
  version = VERSION.to_s.split(".").map { |i| i.to_i }
@@ -34,7 +34,7 @@ class UseVanityControllerTest < ActionController::TestCase
34
34
  def test_render_js_for_tests
35
35
  Vanity.playground.use_js!
36
36
  get :js
37
- assert_match /script.*e=pie_or_cake.*script/m, @response.body
37
+ assert_match /script.*v=pie_or_cake=.*script/m, @response.body
38
38
  end
39
39
 
40
40
  def test_chooses_sets_alternatives_for_rails_tests
@@ -1,20 +1,20 @@
1
1
  require "test_helper"
2
2
 
3
- class LoadPathAndConnectionConfigurationTest < Test::Unit::TestCase
3
+ describe "Rails load path and connection configuration" do
4
4
 
5
- def test_load_path
5
+ it "load_path" do
6
6
  assert_equal File.expand_path("tmp/experiments"), load_rails("", <<-RB)
7
7
  $stdout << Vanity.playground.load_path
8
8
  RB
9
9
  end
10
10
 
11
- def test_settable_load_path
11
+ it "settable_load_path" do
12
12
  assert_equal File.expand_path("tmp/predictions"), load_rails(%Q{\nVanity.playground.load_path = "predictions"\n}, <<-RB)
13
13
  $stdout << Vanity.playground.load_path
14
14
  RB
15
15
  end
16
16
 
17
- def test_absolute_load_path
17
+ it "absolute_load_path" do
18
18
  Dir.mktmpdir do |dir|
19
19
  assert_equal dir, load_rails(%Q{\nVanity.playground.load_path = "#{dir}"\n}, <<-RB)
20
20
  $stdout << Vanity.playground.load_path
@@ -23,201 +23,217 @@ $stdout << Vanity.playground.load_path
23
23
  end
24
24
 
25
25
  if ENV['DB'] == 'redis'
26
- def test_default_connection
26
+ it "default_connection" do
27
27
  assert_equal "redis://127.0.0.1:6379/0", load_rails("", <<-RB)
28
28
  $stdout << Vanity.playground.connection
29
29
  RB
30
30
  end
31
31
 
32
- def test_connection_from_string
32
+ it "connection_from_string" do
33
33
  assert_equal "redis://192.168.1.1:6379/5", load_rails(%Q{\nVanity.playground.establish_connection "redis://192.168.1.1:6379/5"\n}, <<-RB)
34
34
  $stdout << Vanity.playground.connection
35
35
  RB
36
36
  end
37
37
 
38
- def test_connection_from_yaml
39
- FileUtils.mkpath "tmp/config"
40
- @original_env = ENV["RAILS_ENV"]
41
- ENV["RAILS_ENV"] = "production"
42
- File.open("tmp/config/vanity.yml", "w") do |io|
43
- io.write <<-YML
38
+ it "connection_from_yaml" do
39
+ begin
40
+ FileUtils.mkpath "tmp/config"
41
+ @original_env = ENV["RAILS_ENV"]
42
+ ENV["RAILS_ENV"] = "production"
43
+ File.open("tmp/config/vanity.yml", "w") do |io|
44
+ io.write <<-YML
44
45
  production:
45
46
  adapter: redis
46
47
  host: somehost
47
48
  database: 15
48
49
  YML
49
- end
50
- assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
50
+ end
51
+ assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
51
52
  $stdout << Vanity.playground.connection
52
- RB
53
- ensure
54
- ENV["RAILS_ENV"] = @original_env
55
- File.unlink "tmp/config/vanity.yml"
53
+ RB
54
+ ensure
55
+ ENV["RAILS_ENV"] = @original_env
56
+ File.unlink "tmp/config/vanity.yml"
57
+ end
56
58
  end
57
59
 
58
- def test_connection_from_yaml_url
59
- FileUtils.mkpath "tmp/config"
60
- @original_env = ENV["RAILS_ENV"]
61
- ENV["RAILS_ENV"] = "production"
62
- File.open("tmp/config/vanity.yml", "w") do |io|
63
- io.write <<-YML
60
+ it "connection_from_yaml_url" do
61
+ begin
62
+ FileUtils.mkpath "tmp/config"
63
+ @original_env = ENV["RAILS_ENV"]
64
+ ENV["RAILS_ENV"] = "production"
65
+ File.open("tmp/config/vanity.yml", "w") do |io|
66
+ io.write <<-YML
64
67
  production: redis://somehost/15
65
- YML
66
- end
67
- assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
68
+ YML
69
+ end
70
+ assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
68
71
  $stdout << Vanity.playground.connection
69
- RB
70
- ensure
71
- ENV["RAILS_ENV"] = @original_env
72
- File.unlink "tmp/config/vanity.yml"
72
+ RB
73
+ ensure
74
+ ENV["RAILS_ENV"] = @original_env
75
+ File.unlink "tmp/config/vanity.yml"
76
+ end
73
77
  end
74
78
 
75
- def test_connection_from_yaml_with_erb
76
- FileUtils.mkpath "tmp/config"
77
- @original_env = ENV["RAILS_ENV"]
78
- ENV["RAILS_ENV"] = "production"
79
- # Pass storage URL through environment like heroku does
80
- @original_redis_url = ENV["REDIS_URL"]
81
- ENV["REDIS_URL"] = "redis://somehost:6379/15"
82
- File.open("tmp/config/vanity.yml", "w") do |io|
83
- io.write <<-YML
79
+ it "connection_from_yaml_with_erb" do
80
+ begin
81
+ FileUtils.mkpath "tmp/config"
82
+ @original_env = ENV["RAILS_ENV"]
83
+ ENV["RAILS_ENV"] = "production"
84
+ # Pass storage URL through environment like heroku does
85
+ @original_redis_url = ENV["REDIS_URL"]
86
+ ENV["REDIS_URL"] = "redis://somehost:6379/15"
87
+ File.open("tmp/config/vanity.yml", "w") do |io|
88
+ io.write <<-YML
84
89
  production: <%= ENV['REDIS_URL'] %>
85
90
  YML
86
- end
87
- assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
91
+ end
92
+ assert_equal "redis://somehost:6379/15", load_rails("", <<-RB)
88
93
  $stdout << Vanity.playground.connection
89
- RB
90
- ensure
91
- ENV["RAILS_ENV"] = @original_env
92
- ENV["REDIS_URL"] = @original_redis_url
93
- File.unlink "tmp/config/vanity.yml"
94
+ RB
95
+ ensure
96
+ ENV["RAILS_ENV"] = @original_env
97
+ ENV["REDIS_URL"] = @original_redis_url
98
+ File.unlink "tmp/config/vanity.yml"
99
+ end
94
100
  end
95
101
 
96
- def test_connection_from_redis_yml
97
- FileUtils.mkpath "tmp/config"
98
- yml = File.open("tmp/config/redis.yml", "w")
99
- yml << "production: internal.local:6379\n"
100
- yml.flush
101
- assert_equal "redis://internal.local:6379/0", load_rails("", <<-RB)
102
+ it "connection_from_redis_yml" do
103
+ begin
104
+ FileUtils.mkpath "tmp/config"
105
+ yml = File.open("tmp/config/redis.yml", "w")
106
+ yml << "production: internal.local:6379\n"
107
+ yml.flush
108
+ assert_equal "redis://internal.local:6379/0", load_rails("", <<-RB)
102
109
  $stdout << Vanity.playground.connection
103
- RB
104
- ensure
105
- File.unlink yml.path
110
+ RB
111
+ ensure
112
+ File.unlink yml.path
113
+ end
106
114
  end
107
115
  end
108
116
 
109
117
  if ENV['DB'] == 'mongo'
110
- def test_mongo_connection_from_yaml
111
- FileUtils.mkpath "tmp/config"
112
- File.open("tmp/config/vanity.yml", "w") do |io|
113
- io.write <<-YML
118
+ it "mongo_connection_from_yaml" do
119
+ begin
120
+ FileUtils.mkpath "tmp/config"
121
+ File.open("tmp/config/vanity.yml", "w") do |io|
122
+ io.write <<-YML
114
123
  mongodb:
115
124
  adapter: mongodb
116
125
  host: localhost
117
126
  port: 27017
118
127
  database: vanity_test
119
- YML
120
- end
128
+ YML
129
+ end
121
130
 
122
- assert_equal "mongodb://localhost:27017/vanity_test", load_rails("", <<-RB, "mongodb")
131
+ assert_equal "mongodb://localhost:27017/vanity_test", load_rails("", <<-RB, "mongodb")
123
132
  $stdout << Vanity.playground.connection
124
- RB
125
- ensure
126
- File.unlink "tmp/config/vanity.yml"
133
+ RB
134
+ ensure
135
+ File.unlink "tmp/config/vanity.yml"
136
+ end
127
137
  end
128
138
 
129
139
  unless ENV['CI'] == 'true' #TODO this doesn't get tested on CI
130
- def test_mongodb_replica_set_connection
131
- FileUtils.mkpath "tmp/config"
132
- File.open("tmp/config/vanity.yml", "w") do |io|
133
- io.write <<-YML
140
+ it "mongodb_replica_set_connection" do
141
+ begin
142
+ FileUtils.mkpath "tmp/config"
143
+ File.open("tmp/config/vanity.yml", "w") do |io|
144
+ io.write <<-YML
134
145
  mongodb:
135
146
  adapter: mongodb
136
147
  hosts:
137
148
  - localhost
138
149
  port: 27017
139
150
  database: vanity_test
140
- YML
141
- end
151
+ YML
152
+ end
142
153
 
143
- assert_equal "mongodb://localhost:27017/vanity_test", load_rails("", <<-RB, "mongodb")
154
+ assert_equal "mongodb://localhost:27017/vanity_test", load_rails("", <<-RB, "mongodb")
144
155
  $stdout << Vanity.playground.connection
145
- RB
156
+ RB
146
157
 
147
- assert_equal "Mongo::ReplSetConnection", load_rails("", <<-RB, "mongodb")
158
+ assert_equal "Mongo::ReplSetConnection", load_rails("", <<-RB, "mongodb")
148
159
  $stdout << Vanity.playground.connection.mongo.class
149
- RB
150
- ensure
151
- File.unlink "tmp/config/vanity.yml"
160
+ RB
161
+ ensure
162
+ File.unlink "tmp/config/vanity.yml"
163
+ end
152
164
  end
153
165
  end
154
166
  end
155
167
 
156
- def test_connection_from_yaml_missing
157
- FileUtils.mkpath "tmp/config"
158
- File.open("tmp/config/vanity.yml", "w") do |io|
159
- io.write <<-YML
168
+ it "connection_from_yaml_missing" do
169
+ begin
170
+ FileUtils.mkpath "tmp/config"
171
+ File.open("tmp/config/vanity.yml", "w") do |io|
172
+ io.write <<-YML
160
173
  production:
161
174
  adapter: redis
162
175
  YML
163
- end
176
+ end
164
177
 
165
- assert_equal "No configuration for development", load_rails("\nbegin\n", <<-RB, "development")
178
+ assert_equal "No configuration for development", load_rails("\nbegin\n", <<-RB, "development")
166
179
  rescue RuntimeError => e
167
180
  $stdout << e.message
168
181
  end
169
182
  RB
170
- ensure
171
- File.unlink "tmp/config/vanity.yml"
183
+ ensure
184
+ File.unlink "tmp/config/vanity.yml"
185
+ end
172
186
  end
173
187
 
174
- def test_collection_from_vanity_yaml
175
- FileUtils.mkpath "tmp/config"
176
- File.open("tmp/config/vanity.yml", "w") do |io|
177
- io.write <<-YML
188
+ it "collection_from_vanity_yaml" do
189
+ begin
190
+ FileUtils.mkpath "tmp/config"
191
+ File.open("tmp/config/vanity.yml", "w") do |io|
192
+ io.write <<-YML
178
193
  production:
179
194
  collecting: false
180
195
  adapter: mock
181
- YML
182
- end
183
- assert_equal "false", load_rails("", <<-RB)
196
+ YML
197
+ end
198
+ assert_equal "false", load_rails("", <<-RB)
184
199
  $stdout << Vanity.playground.collecting?
185
- RB
186
- ensure
187
- File.unlink "tmp/config/vanity.yml"
200
+ RB
201
+ ensure
202
+ File.unlink "tmp/config/vanity.yml"
203
+ end
188
204
  end
189
205
 
190
- def test_collection_true_in_production_by_default
206
+ it "collection_true_in_production_by_default" do
191
207
  assert_equal "true", load_rails("", <<-RB)
192
208
  $stdout << Vanity.playground.collecting?
193
209
  RB
194
210
  end
195
211
 
196
- def test_collection_false_in_production_when_configured
212
+ it "collection_false_in_production_when_configured" do
197
213
  assert_equal "false", load_rails("\nVanity.playground.collecting = false\n", <<-RB)
198
214
  $stdout << Vanity.playground.collecting?
199
215
  RB
200
216
  end
201
217
 
202
- def test_collection_true_in_development_by_default
218
+ it "collection_true_in_development_by_default" do
203
219
  assert_equal "true", load_rails("", <<-RB, "development")
204
220
  $stdout << Vanity.playground.collecting?
205
221
  RB
206
222
  end
207
223
 
208
- def test_collection_true_in_development_when_configured
224
+ it "collection_true_in_development_when_configured" do
209
225
  assert_equal "true", load_rails("\nVanity.playground.collecting = true\n", <<-RB, "development")
210
226
  $stdout << Vanity.playground.collecting?
211
227
  RB
212
228
  end
213
229
 
214
- def test_playground_loads_if_connected
230
+ it "playground_loads_if_connected" do
215
231
  assert_equal "{}", load_rails("", <<-RB)
216
232
  $stdout << Vanity.playground.instance_variable_get(:@experiments).inspect
217
233
  RB
218
234
  end
219
235
 
220
- def test_playground_does_not_load_if_not_connected
236
+ it "playground_does_not_load_if_not_connected" do
221
237
  ENV['VANITY_DISABLED'] = '1'
222
238
  assert_equal "nil", load_rails("", <<-RB)
223
239
  $stdout << Vanity.playground.instance_variable_get(:@experiments).inspect