Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

r4487@asus: jeremy | 2006-04-29 12:21:39 -0700

 Check whether @flash is defined? for warnings-safety.
 r4488@asus:  jeremy | 2006-04-29 12:23:15 -0700
 Check whether @flash is defined? for warnings-safety. Obviates nil? check.
 r4489@asus:  jeremy | 2006-04-29 12:45:18 -0700
 Check whether @session is defined? for warnings-safety.
 r4490@asus:  jeremy | 2006-04-29 12:50:41 -0700
 Check whether @rendering_runtime is defined? for warnings-safety.
 r4491@asus:  jeremy | 2006-04-29 12:55:01 -0700
 Check whether @_cycles is defined? for warnings-safety.
 r4492@asus:  jeremy | 2006-04-29 12:59:19 -0700
 Check whether instance variables are defined? for warnings-safety.
 r4493@asus:  jeremy | 2006-04-29 13:14:09 -0700
 Add nil @template to PrototypeHelperTest to suppress unitialized instance variable warning.
 r4494@asus:  jeremy | 2006-04-29 13:31:34 -0700
 Check whether @auto_index defined? for warnings-safety.
 r4495@asus:  jeremy | 2006-04-29 13:32:24 -0700
 Wrap content_columns redefinitions with silence_warnings.
 r4496@asus:  jeremy | 2006-04-29 13:35:28 -0700
 Wrap more redefinitions with silence_warnings.
 r4829@asus:  jeremy | 2006-07-08 10:59:20 -0700
 abstract unit, fix warnings
 r4830@asus:  jeremy | 2006-07-08 11:06:12 -0700
 Use parens to silence warning.
 r4831@asus:  jeremy | 2006-07-08 11:06:48 -0700
 Use parens to silence warning.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4595 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 71234daef1517cf190adfc5978e56882d2a57ea6 1 parent a3f459e
@jeremy jeremy authored
Showing with 237 additions and 275 deletions.
  1. +1 −1  actionpack/lib/action_controller/benchmarking.rb
  2. +1 −1  actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
  3. +2 −2 actionpack/lib/action_controller/cgi_process.rb
  4. +3 −3 actionpack/lib/action_controller/components.rb
  5. +2 −2 actionpack/lib/action_controller/flash.rb
  6. +5 −3 actionpack/lib/action_controller/test_process.rb
  7. +2 −2 actionpack/lib/action_view/helpers/form_helper.rb
  8. +3 −4 actionpack/lib/action_view/helpers/text_helper.rb
  9. +2 −2 actionpack/test/controller/helper_test.rb
  10. +20 −9 actionpack/test/template/active_record_helper_test.rb
  11. +1 −0  actionpack/test/template/prototype_helper_test.rb
  12. +4 −0 activesupport/test/abstract_unit.rb
  13. +11 −14 activesupport/test/caching_tools_test.rb
  14. +1 −2  activesupport/test/class_inheritable_attributes_test.rb
  15. +1 −3 activesupport/test/clean_logger_test.rb
  16. +14 −15 activesupport/test/core_ext/array_ext_test.rb
  17. +1 −3 activesupport/test/core_ext/blank_test.rb
  18. +1 −2  activesupport/test/core_ext/cgi_ext_test.rb
  19. +1 −2  activesupport/test/core_ext/class_test.rb
  20. +4 −5 activesupport/test/core_ext/date_ext_test.rb
  21. +2 −4 activesupport/test/core_ext/enumerable_test.rb
  22. +9 −10 activesupport/test/core_ext/exception_test.rb
  23. +1 −2  activesupport/test/core_ext/hash_ext_test.rb
  24. +3 −4 activesupport/test/core_ext/integer_ext_test.rb
  25. +1 −2  activesupport/test/core_ext/kernel_test.rb
  26. +2 −3 activesupport/test/core_ext/load_error_tests.rb
  27. +10 −12 activesupport/test/core_ext/module_test.rb
  28. +1 −2  activesupport/test/core_ext/numeric_ext_test.rb
  29. +16 −18 activesupport/test/core_ext/object_and_class_ext_test.rb
  30. +1 −4 activesupport/test/core_ext/pathname_test.rb
  31. +2 −3 activesupport/test/core_ext/proc_test.rb
  32. +1 −4 activesupport/test/core_ext/range_ext_test.rb
  33. +15 −17 activesupport/test/core_ext/string_ext_test.rb
  34. +1 −2  activesupport/test/core_ext/symbol_test.rb
  35. +22 −24 activesupport/test/core_ext/time_ext_test.rb
  36. +10 −13 activesupport/test/dependencies_test.rb
  37. +18 −19 activesupport/test/inflector_test.rb
  38. +7 −9 activesupport/test/json.rb
  39. +7 −12 activesupport/test/option_merger_test.rb
  40. +12 −14 activesupport/test/ordered_options_test.rb
  41. +10 −13 activesupport/test/reloadable_test.rb
  42. +1 −2  activesupport/test/time_zone_test.rb
  43. +5 −7 activesupport/test/whiny_nil_test.rb
View
2  actionpack/lib/action_controller/benchmarking.rb
@@ -65,7 +65,7 @@ def perform_action_with_benchmark
else
runtime = [Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001].max
log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)"
- log_message << rendering_runtime(runtime) if @rendering_runtime
+ log_message << rendering_runtime(runtime) if defined?(@rendering_runtime)
log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
log_message << " | #{headers["Status"]}"
log_message << " [#{complete_request_uri rescue "unknown"}]"
View
2  actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
@@ -75,7 +75,7 @@ def read_body(content_length)
content = stdinput.read(content_length) || ''
# Fix for Safari Ajax postings that always append \000
content.chop! if content[-1] == 0
- content.gsub! /&_=$/, ''
+ content.gsub!(/&_=$/, '')
env_table['RAW_POST_DATA'] = content.freeze
end
View
4 actionpack/lib/action_controller/cgi_process.rb
@@ -101,7 +101,7 @@ def port
end
def session
- unless @session
+ unless defined?(@session)
if @session_options == false
@session = Hash.new
else
@@ -119,7 +119,7 @@ def session
end
def reset_session
- @session.delete if CGI::Session === @session
+ @session.delete if defined?(@session) && @session.is_a?(CGI::Session)
@session = new_session
end
View
6 actionpack/lib/action_controller/components.rb
@@ -111,9 +111,9 @@ def render_component_as_string(options) #:doc:
end
def flash_with_components(refresh = false) #:nodoc:
- if @flash.nil? || refresh
- @flash =
- if @parent_controller
+ if !defined?(@flash) || refresh
+ @flash =
+ if defined?(@parent_controller)
@parent_controller.flash
else
flash_without_components
View
4 actionpack/lib/action_controller/flash.rb
@@ -155,8 +155,8 @@ def reset_session_with_flash
# <tt>flash["notice"] = "hello"</tt> to put a new one.
# Note that if sessions are disabled only flash.now will work.
def flash(refresh = false) #:doc:
- if @flash.nil? || refresh
- @flash =
+ if !defined?(@flash) || refresh
+ @flash =
if @session.is_a?(Hash)
# @session is a Hash, if sessions are disabled
# we don't put the flash in the session in this case
View
8 actionpack/lib/action_controller/test_process.rb
@@ -337,7 +337,7 @@ def self.included(base)
%w( get post put delete head ).each do |method|
base.class_eval <<-EOV, __FILE__, __LINE__
def #{method}(action, parameters = nil, session = nil, flash = nil)
- @request.env['REQUEST_METHOD'] = "#{method.upcase}" if @request
+ @request.env['REQUEST_METHOD'] = "#{method.upcase}" if defined?(@request)
process(action, parameters, session, flash)
end
EOV
@@ -348,8 +348,10 @@ def #{method}(action, parameters = nil, session = nil, flash = nil)
def process(action, parameters = nil, session = nil, flash = nil)
# Sanity check for required instance variables so we can give an
# understandable error message.
- %w(controller request response).each do |iv_name|
- raise "@#{iv_name} is nil: make sure you set it in your test's setup method." if instance_variable_get("@#{iv_name}").nil?
+ %w(@controller @request @response).each do |iv_name|
+ if !instance_variables.include?(iv_name) || instance_variable_get(iv_name).nil?
+ raise "#{iv_name} is nil: make sure you set it in your test's setup method."
+ end
end
@request.recycle!
View
4 actionpack/lib/action_view/helpers/form_helper.rb
@@ -267,7 +267,7 @@ def to_radio_button_tag(tag_value, options = {})
end
options["checked"] = "checked" if checked
pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
- options["id"] = @auto_index ?
+ options["id"] = defined?(@auto_index) ?
"#{@object_name}_#{@auto_index}_#{@method_name}_#{pretty_tag_value}" :
"#{@object_name}_#{@method_name}_#{pretty_tag_value}"
add_default_name_and_id(options)
@@ -377,7 +377,7 @@ def add_default_name_and_id(options)
options["name"] ||= tag_name_with_index(options["index"])
options["id"] ||= tag_id_with_index(options["index"])
options.delete("index")
- elsif @auto_index
+ elsif defined?(@auto_index)
options["name"] ||= tag_name_with_index(@auto_index)
options["id"] ||= tag_id_with_index(@auto_index)
else
View
7 actionpack/lib/action_view/helpers/text_helper.rb
@@ -277,8 +277,7 @@ def cycle(first_value, *values)
# the next time it is used.
def reset_cycle(name = "default")
cycle = get_cycle(name)
- return if cycle.nil?
- cycle.reset
+ cycle.reset unless cycle.nil?
end
class Cycle #:nodoc:
@@ -305,12 +304,12 @@ def to_s
# guaranteed to be reset every time a page is rendered, so it
# uses an instance variable of ActionView::Base.
def get_cycle(name)
- @_cycles = Hash.new if @_cycles.nil?
+ @_cycles = Hash.new unless defined?(@_cycles)
return @_cycles[name]
end
def set_cycle(name, cycle_object)
- @_cycles = Hash.new if @_cycles.nil?
+ @_cycles = Hash.new unless defined?(@_cycles)
@_cycles[name] = cycle_object
end
View
4 actionpack/test/controller/helper_test.rb
@@ -77,8 +77,8 @@ def test_declare_missing_helper
def test_declare_missing_file_from_helper
require 'broken_helper'
- rescue LoadError => e
- assert_nil /\bbroken_helper\b/.match(e.to_s)[1]
+ rescue LoadError => e
+ assert_nil(/\bbroken_helper\b/.match(e.to_s)[1])
end
def test_helper_block
View
29 actionpack/test/template/active_record_helper_test.rb
@@ -49,7 +49,9 @@ def @post.column_for_attribute(attr_name)
Post.content_columns.select { |column| column.name == attr_name }.first
end
- def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
+ silence_warnings do
+ def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
+ end
@post.title = "Hello World"
@post.author_name = ""
@@ -76,7 +78,9 @@ def @user.column_for_attribute(attr_name)
User.content_columns.select { |column| column.name == attr_name }.first
end
- def User.content_columns() [ Column.new(:string, "email", "Email") ] end
+ silence_warnings do
+ def User.content_columns() [ Column.new(:string, "email", "Email") ] end
+ end
@user.email = ""
end
@@ -119,11 +123,14 @@ def test_form_with_string
form("post")
)
- class << @post
- def new_record?() false end
- def to_param() id end
- def id() 1 end
+ silence_warnings do
+ class << @post
+ def new_record?() false end
+ def to_param() id end
+ def id() 1 end
+ end
end
+
assert_dom_equal(
%(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
form("post")
@@ -131,16 +138,20 @@ def id() 1 end
end
def test_form_with_date
- def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
+ silence_warnings do
+ def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
+ end
assert_dom_equal(
%(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
form("post")
)
end
-
+
def test_form_with_datetime
- def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
+ silence_warnings do
+ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
+ end
@post.written_on = Time.gm(2004, 6, 15, 16, 30)
assert_dom_equal(
View
1  actionpack/test/template/prototype_helper_test.rb
@@ -13,6 +13,7 @@ module BaseTest
include ActionView::Helpers::CaptureHelper
def setup
+ @template = nil
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
if options.is_a?(String)
View
4 activesupport/test/abstract_unit.rb
@@ -0,0 +1,4 @@
+require 'test/unit'
+
+$:.unshift "#{File.dirname(__FILE__)}/../lib"
+require 'active_support'
View
25 activesupport/test/caching_tools_test.rb
@@ -1,11 +1,9 @@
-require 'test/unit'
-require File.dirname(__FILE__)+'/../lib/active_support/caching_tools'
+require File.dirname(__FILE__) + '/abstract_unit'
class HashCachingTests < Test::Unit::TestCase
-
def cached(&proc)
- return @cached if @cached
-
+ return @cached if defined?(@cached)
+
@cached_class = Class.new(&proc)
@cached_class.class_eval do
extend ActiveSupport::CachingTools::HashCaching
@@ -13,14 +11,14 @@ def cached(&proc)
end
@cached = @cached_class.new
end
-
+
def test_cache_access_should_call_method
cached do
def slow_method(a) raise "I should be here: #{a}"; end
end
assert_raises(RuntimeError) { cached.slow_method_cache[1] }
end
-
+
def test_cache_access_should_actually_cache
cached do
def slow_method(a)
@@ -37,7 +35,7 @@ def slow_method(a)
assert_equal 11, cached.slow_method_cache[10]
assert_equal 12, cached.slow_method_cache[11]
end
-
+
def test_cache_should_be_clearable
cached do
def slow_method(a)
@@ -48,18 +46,18 @@ def slow_method(a)
assert_equal 1, cached.slow_method_cache[:a]
assert_equal 2, cached.slow_method_cache[:b]
assert_equal 3, cached.slow_method_cache[:c]
-
+
assert_equal 1, cached.slow_method_cache[:a]
assert_equal 2, cached.slow_method_cache[:b]
assert_equal 3, cached.slow_method_cache[:c]
-
+
cached.slow_method_cache.clear
-
+
assert_equal 4, cached.slow_method_cache[:a]
assert_equal 5, cached.slow_method_cache[:b]
assert_equal 6, cached.slow_method_cache[:c]
end
-
+
def test_deep_caches_should_work_too
cached do
def slow_method(a, b, c)
@@ -70,12 +68,11 @@ def slow_method(a, b, c)
assert_equal 7, cached.slow_method_cache[1][2][4]
assert_equal 7, cached.slow_method_cache[1][2][4]
assert_equal 7, cached.slow_method_cache[4][2][1]
-
+
assert_equal({
1 => {1 => {1 => 3}, 2 => {4 => 7}},
4 => {2 => {1 => 7}}},
cached.slow_method_cache
)
end
-
end
View
3  activesupport/test/class_inheritable_attributes_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/active_support/core_ext/class/inheritable_attributes'
+require File.dirname(__FILE__) + '/abstract_unit'
class ClassInheritableAttributesTest < Test::Unit::TestCase
def setup
View
4 activesupport/test/clean_logger_test.rb
@@ -1,7 +1,5 @@
-require 'test/unit'
+require File.dirname(__FILE__) + '/abstract_unit'
require 'stringio'
-require File.dirname(__FILE__) + '/../lib/active_support/clean_logger'
-require File.dirname(__FILE__) + '/../lib/active_support/core_ext/kernel.rb' unless defined? silence_warnings
class CleanLoggerTest < Test::Unit::TestCase
def setup
View
29 activesupport/test/core_ext/array_ext_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support'
+require File.dirname(__FILE__) + '/../abstract_unit'
class ArrayExtToParamTests < Test::Unit::TestCase
def test_string_array
@@ -7,7 +6,7 @@ def test_string_array
assert_equal 'hello/world', %w(hello world).to_param
assert_equal 'hello/10', %w(hello 10).to_param
end
-
+
def test_number_array
assert_equal '10/20', [10, 20].to_param
end
@@ -19,13 +18,13 @@ def test_plain_array_to_sentence
assert_equal "one", ['one'].to_sentence
assert_equal "one and two", ['one', 'two'].to_sentence
assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence
-
+
end
-
+
def test_to_sentence_with_connector
assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:connector => 'and also')
end
-
+
def test_to_sentence_with_skip_last_comma
assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence(:skip_last_comma => false)
end
@@ -33,7 +32,7 @@ def test_to_sentence_with_skip_last_comma
def test_two_elements
assert_equal "one and two", ['one', 'two'].to_sentence
end
-
+
def test_one_element
assert_equal "one", ['one'].to_sentence
end
@@ -46,7 +45,7 @@ def test_to_s_db
Class.new { def id() 2 end }.new,
Class.new { def id() 3 end }.new
]
-
+
assert_equal "null", [].to_s(:db)
assert_equal "1,2,3", collection.to_s(:db)
end
@@ -87,16 +86,16 @@ class ArraySplitTests < Test::Unit::TestCase
def test_split_with_empty_array
assert_equal [[]], [].split(0)
end
-
+
def test_split_with_argument
assert_equal [[1, 2], [4, 5]], [1, 2, 3, 4, 5].split(3)
assert_equal [[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5].split(0)
end
-
+
def test_split_with_block
assert_equal [[1, 2], [4, 5], [7, 8], [10]], (1..10).to_a.split { |i| i % 3 == 0 }
end
-
+
def test_split_with_edge_values
assert_equal [[], [2, 3, 4, 5]], [1, 2, 3, 4, 5].split(1)
assert_equal [[1, 2, 3, 4], []], [1, 2, 3, 4, 5].split(5)
@@ -124,9 +123,9 @@ def test_to_xml_with_dedicated_name
assert_equal "<people><person>", xml.first(16)
end
-
+
def test_to_xml_with_options
- xml = [
+ xml = [
{ :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" }
].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0)
@@ -138,7 +137,7 @@ def test_to_xml_with_options
end
def test_to_xml_with_dasherize_false
- xml = [
+ xml = [
{ :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" }
].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0, :dasherize => false)
@@ -148,7 +147,7 @@ def test_to_xml_with_dasherize_false
end
def test_to_xml_with_dasherize_true
- xml = [
+ xml = [
{ :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" }
].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0, :dasherize => true)
View
4 activesupport/test/core_ext/blank_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/object'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/blank'
+require File.dirname(__FILE__) + '/../abstract_unit'
class BlankTest < Test::Unit::TestCase
BLANK = [nil, false, '', ' ', " \n\t \r ", [], {}]
View
3  activesupport/test/core_ext/cgi_ext_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/cgi'
+require File.dirname(__FILE__) + '/../abstract_unit'
class EscapeSkippingSlashesTest < Test::Unit::TestCase
def test_array
View
3  activesupport/test/core_ext/class_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class'
+require File.dirname(__FILE__) + '/../abstract_unit'
class A
end
View
9 activesupport/test/core_ext/date_ext_test.rb
@@ -1,17 +1,16 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/date'
+require File.dirname(__FILE__) + '/../abstract_unit'
class DateExtCalculationsTest < Test::Unit::TestCase
def test_to_s
assert_equal "21 Feb", Date.new(2005, 2, 21).to_s(:short)
assert_equal "February 21, 2005", Date.new(2005, 2, 21).to_s(:long)
end
-
+
def test_to_time
assert_equal Time.local(2005, 2, 21), Date.new(2005, 2, 21).to_time
end
-
+
def test_to_date
assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date
end
-end
+end
View
6 activesupport/test/core_ext/enumerable_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/enumerable'
+require File.dirname(__FILE__) + '/../abstract_unit'
Payment = Struct.new(:price)
class SummablePayment < Payment
@@ -12,7 +10,7 @@ def test_group_by
names = %w(marcel sam david jeremy)
klass = Class.new
klass.send(:attr_accessor, :name)
- objects = (1..50).inject([]) do |people,|
+ objects = (1..50).inject([]) do |people,|
p = klass.new
p.name = names.sort_by { rand }.first
people << p
View
19 activesupport/test/core_ext/exception_test.rb
@@ -1,33 +1,32 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/exception'
+require File.dirname(__FILE__) + '/../abstract_unit'
class ExceptionExtTests < Test::Unit::TestCase
-
+
def get_exception(cls = RuntimeError, msg = nil, trace = nil)
begin raise cls, msg, (trace || caller)
rescue Object => e
return e
end
end
-
+
def setup
Exception::TraceSubstitutions.clear
end
-
+
def test_clean_backtrace
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
e = get_exception RuntimeError, 'RAWR', ['bhal.rb', 'rawh hid den stuff is not here', 'almost all']
assert_kind_of Exception, e
assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace
end
-
+
def test_app_backtrace
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
e = get_exception RuntimeError, 'RAWR', ['bhal.rb', ' vendor/file.rb some stuff', 'almost all']
assert_kind_of Exception, e
assert_equal ['bhal.rb', 'almost all'], e.application_backtrace
end
-
+
def test_app_backtrace_with_before
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'bhal.rb', ' vendor/file.rb some stuff', 'almost all']
@@ -41,21 +40,21 @@ def test_framework_backtrace_with_before
assert_kind_of Exception, e
assert_equal ['vendor/file.rb some stuff', ' vendor/file.rb some stuff'], e.framework_backtrace
end
-
+
def test_backtrace_should_clean_paths
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
e = get_exception RuntimeError, 'RAWR', ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all']
assert_kind_of Exception, e
assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace
end
-
+
def test_clean_message_should_clean_paths
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
e = get_exception RuntimeError, "I dislike a/z/x/../../b/y/../c", ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all']
assert_kind_of Exception, e
assert_equal "I dislike a/b/c", e.clean_message
end
-
+
def test_app_trace_should_be_empty_when_no_app_frames
Exception::TraceSubstitutions << [/\s*hidden.*/, '']
e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'generated/bhal.rb', ' vendor/file.rb some stuff', 'generated/almost all']
View
3  activesupport/test/core_ext/hash_ext_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support'
+require File.dirname(__FILE__) + '/../abstract_unit'
class HashExtTest < Test::Unit::TestCase
def setup
View
7 activesupport/test/core_ext/integer_ext_test.rb
@@ -1,11 +1,10 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/integer'
+require File.dirname(__FILE__) + '/../abstract_unit'
class IntegerExtTest < Test::Unit::TestCase
def test_even
assert [ -2, 0, 2, 4 ].all? { |i| i.even? }
assert ![ -1, 1, 3 ].all? { |i| i.even? }
-
+
assert 22953686867719691230002707821868552601124472329079.odd?
assert !22953686867719691230002707821868552601124472329079.even?
assert 22953686867719691230002707821868552601124472329080.even?
@@ -17,7 +16,7 @@ def test_odd
assert [ -1, 1, 3 ].all? { |i| i.odd? }
assert 1000000000000000000000000000000000000000000000000000000001.odd?
end
-
+
def test_multiple_of
[ -7, 0, 7, 14 ].each { |i| assert i.multiple_of?(7) }
[ -7, 7, 14 ].each { |i| assert ! i.multiple_of?(6) }
View
3  activesupport/test/core_ext/kernel_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/kernel' unless defined? silence_warnings
+require File.dirname(__FILE__) + '/../abstract_unit'
class KernelTest < Test::Unit::TestCase
def test_silence_warnings
View
5 activesupport/test/core_ext/load_error_tests.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/load_error'
+require File.dirname(__FILE__) + '/../abstract_unit'
class TestMissingSourceFile < Test::Unit::TestCase
def test_with_require
@@ -14,4 +13,4 @@ def test_path
assert_equal 'nor/this/one.rb', e.path
end
end
-end
+end
View
22 activesupport/test/core_ext/module_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/module'
+require File.dirname(__FILE__) + '/../abstract_unit'
module One
end
@@ -67,33 +65,33 @@ def test_delegation_to_methods
assert_equal "Paulina", david.street
assert_equal "Chicago", david.city
end
-
+
def test_delegation_down_hierarchy
david = Someone.new("David", Somewhere.new("Paulina", "Chicago"))
assert_equal "CHICAGO", david.upcase
end
-
+
def test_delegation_to_instance_variable
david = Name.new("David", "Hansson")
assert_equal "DAVID HANSSON", david.upcase
end
-
+
def test_missing_delegation_target
assert_raises(ArgumentError) { eval($nowhere) }
assert_raises(ArgumentError) { eval($noplace) }
end
-
+
def test_parent
assert_equal Yz::Zy, Yz::Zy::Cd.parent
assert_equal Yz, Yz::Zy.parent
assert_equal Object, Yz.parent
end
-
+
def test_parents
assert_equal [Yz::Zy, Yz, Object], Yz::Zy::Cd.parents
assert_equal [Yz, Object], Yz::Zy.parents
end
-
+
def test_as_load_path
assert_equal 'yz/zy', Yz::Zy.as_load_path
assert_equal 'yz', Yz.as_load_path
@@ -156,7 +154,7 @@ def test_alias_method_chain_with_punctuation_method
FooClassWithBarMethod.send(:include, BarMethodAliaser)
FooClassWithBarMethod.alias_method_chain :quux!, :baz
assert @instance.respond_to?(:quux_with_baz!)
-
+
assert_equal 'quux_with_baz!', @instance.quux!
assert_equal 'quux', @instance.quux_without_baz!
end
@@ -166,11 +164,11 @@ def test_alias_method_chain_with_same_names_between_predicates_and_bang_methods
FooClassWithBarMethod.send(:define_method, 'quux?', Proc.new { true })
assert !@instance.respond_to?(:quux_with_baz!)
assert !@instance.respond_to?(:quux_with_baz?)
-
+
FooClassWithBarMethod.send(:include, BarMethodAliaser)
FooClassWithBarMethod.alias_method_chain :quux!, :baz
FooClassWithBarMethod.alias_method_chain :quux?, :baz
-
+
assert @instance.respond_to?(:quux_with_baz!)
assert @instance.respond_to?(:quux_with_baz?)
assert_equal 'quux_with_baz!', @instance.quux!
View
3  activesupport/test/core_ext/numeric_ext_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/numeric'
+require File.dirname(__FILE__) + '/../abstract_unit'
class NumericExtTimeTest < Test::Unit::TestCase
def setup
View
34 activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/object'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class'
+require File.dirname(__FILE__) + '/../abstract_unit'
class ClassA; end
class ClassB < ClassA; end
@@ -41,24 +39,24 @@ def test_methods
assert !defined?(ClassC)
assert !defined?(ClassD)
end
-
+
def test_subclasses_of
assert_equal [ClassJ], Object.subclasses_of(ClassI)
ClassI.remove_subclasses
assert_equal [], Object.subclasses_of(ClassI)
end
-
+
def test_subclasses_of_should_find_nested_classes
assert Object.subclasses_of(ClassK).include?(Nested::ClassL)
end
-
+
def test_subclasses_of_should_not_return_removed_classes
# First create the removed class
old_class = Nested.send :remove_const, :ClassL
new_class = Class.new(ClassK)
Nested.const_set :ClassL, new_class
assert_equal "Nested::ClassL", new_class.name # Sanity check
-
+
subclasses = Object.subclasses_of(ClassK)
assert subclasses.include?(new_class)
assert ! subclasses.include?(old_class)
@@ -75,23 +73,23 @@ def test_suppress_supresses
suppress(LoadError, ArgumentError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise ArgumentError }
end
-
+
def test_extended_by
foo = Foo.new
assert foo.extended_by.include?(Bar)
foo.extend(Baz)
assert ([Bar, Baz] - foo.extended_by).empty?, "Expected Bar, Baz in #{foo.extended_by.inspect}"
end
-
+
def test_extend_with_included_modules_from
foo, object = Foo.new, Object.new
assert !object.respond_to?(:bar)
assert !object.respond_to?(:baz)
-
+
object.extend_with_included_modules_from(foo)
assert object.respond_to?(:bar)
assert !object.respond_to?(:baz)
-
+
foo.extend(Baz)
object.extend_with_included_modules_from(foo)
assert object.respond_to?(:bar)
@@ -113,17 +111,17 @@ def test_copy_instance_variables_from_without_explicit_excludes
assert_equal %w(@bar @baz), @dest.instance_variables.sort
%w(@bar @baz).each do |name|
- assert_equal @source.instance_variable_get(name).object_id,
+ assert_equal @source.instance_variable_get(name).object_id,
@dest.instance_variable_get(name).object_id
end
end
-
+
def test_copy_instance_variables_from_with_explicit_excludes
@dest.copy_instance_variables_from(@source, ['@baz'])
assert !@dest.instance_variables.include?('@baz')
assert_equal 'bar', @dest.instance_variable_get('@bar')
end
-
+
def test_copy_instance_variables_automatically_excludes_protected_instance_variables
@source.instance_variable_set(:@quux, 'quux')
class << @source
@@ -131,23 +129,23 @@ def protected_instance_variables
['@bar', :@quux]
end
end
-
+
@dest.copy_instance_variables_from(@source)
assert !@dest.instance_variables.include?('@bar')
assert !@dest.instance_variables.include?('@quux')
assert_equal 'baz', @dest.instance_variable_get('@baz')
end
-
+
def test_instance_values
object = Object.new
object.instance_variable_set :@a, 1
object.instance_variable_set :@b, 2
assert_equal({'a' => 1, 'b' => 2}, object.instance_values)
end
-
+
def test_instance_exec_passes_arguments_to_block
block = Proc.new { |value| [self, value] }
assert_equal %w(hello goodbye), 'hello'.instance_exec('goodbye', &block)
end
-
+
end
View
5 activesupport/test/core_ext/pathname_test.rb
@@ -1,12 +1,9 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/pathname'
+require File.dirname(__FILE__) + '/../abstract_unit'
class TestPathname < Test::Unit::TestCase
-
def test_clean_within
assert_equal "Hi", Pathname.clean_within("Hi")
assert_equal "Hi", Pathname.clean_within("Hi/a/b/../..")
assert_equal "Hello\nWorld", Pathname.clean_within("Hello/a/b/../..\na/b/../../World/c/..")
end
-
end
View
5 activesupport/test/core_ext/proc_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/proc'
+require File.dirname(__FILE__) + '/../abstract_unit'
class ProcTests < Test::Unit::TestCase
def test_bind_returns_method_with_changed_self
@@ -9,4 +8,4 @@ def test_bind_returns_method_with_changed_self
assert_not_equal block, bound_block
assert_equal "hello", bound_block.call
end
-end
+end
View
5 activesupport/test/core_ext/range_ext_test.rb
@@ -1,7 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/date'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/time'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/range'
+require File.dirname(__FILE__) + '/../abstract_unit'
class RangeTest < Test::Unit::TestCase
def test_to_s_from_dates
View
32 activesupport/test/core_ext/string_ext_test.rb
@@ -1,7 +1,5 @@
-require 'test/unit'
require 'date'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/string'
-require File.dirname(__FILE__) + '/../inflector_test' unless defined? InflectorTest
+require File.dirname(__FILE__) + '/../abstract_unit'
class StringInflectionsTest < Test::Unit::TestCase
def test_pluralize
@@ -28,7 +26,7 @@ def test_underscore
InflectorTest::CamelToUnderscore.each do |camel, underscore|
assert_equal(underscore, camel.underscore)
end
-
+
assert_equal "html_tidy", "HTMLTidy".underscore
assert_equal "html_tidy_generator", "HTMLTidyGenerator".underscore
end
@@ -58,26 +56,26 @@ def test_classify
assert_equal(class_name, table_name.classify)
end
end
-
+
def test_string_to_time
assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time
assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:local)
assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date
end
-
+
def test_access
s = "hello"
assert_equal "h", s.at(0)
-
+
assert_equal "llo", s.from(2)
assert_equal "hel", s.to(2)
-
+
assert_equal "h", s.first
assert_equal "he", s.first(2)
assert_equal "o", s.last
assert_equal "llo", s.last(3)
-
+
assert_equal 'x', 'x'.first
assert_equal 'x', 'x'.first(4)
@@ -86,14 +84,14 @@ def test_access
end
def test_starts_ends_with
- s = "hello"
- assert s.starts_with?('h')
- assert s.starts_with?('hel')
- assert !s.starts_with?('el')
-
- assert s.ends_with?('o')
- assert s.ends_with?('lo')
- assert !s.ends_with?('el')
+ s = "hello"
+ assert s.starts_with?('h')
+ assert s.starts_with?('hel')
+ assert !s.starts_with?('el')
+
+ assert s.ends_with?('o')
+ assert s.ends_with?('lo')
+ assert !s.ends_with?('el')
end
def test_each_char_with_utf8_string_when_kcode_is_utf8
View
3  activesupport/test/core_ext/symbol_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol'
+require File.dirname(__FILE__) + '/../abstract_unit'
class SymbolTests < Test::Unit::TestCase
def test_to_proc
View
46 activesupport/test/core_ext/time_ext_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/numeric'
-require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/time'
+require File.dirname(__FILE__) + '/../abstract_unit'
class TimeExtCalculationsTest < Test::Unit::TestCase
def test_seconds_since_midnight
@@ -19,35 +17,35 @@ def test_begining_of_week
assert_equal Time.local(2005,11,28), Time.local(2005,12,01,0,0,0).beginning_of_week #thursday
assert_equal Time.local(2005,11,28), Time.local(2005,12,02,0,0,0).beginning_of_week #friday
assert_equal Time.local(2005,11,28), Time.local(2005,12,03,0,0,0).beginning_of_week #saturday
- assert_equal Time.local(2005,11,28), Time.local(2005,12,04,0,0,0).beginning_of_week #sunday
+ assert_equal Time.local(2005,11,28), Time.local(2005,12,04,0,0,0).beginning_of_week #sunday
end
-
+
def test_beginning_of_day
assert_equal Time.local(2005,2,4,0,0,0), Time.local(2005,2,4,10,10,10).beginning_of_day
end
-
+
def test_beginning_of_month
assert_equal Time.local(2005,2,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_month
end
-
+
def test_beginning_of_quarter
assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,15,10,10,10).beginning_of_quarter
assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,1,1,0,0,0).beginning_of_quarter
assert_equal Time.local(2005,10,1,0,0,0), Time.local(2005,12,31,10,10,10).beginning_of_quarter
assert_equal Time.local(2005,4,1,0,0,0), Time.local(2005,6,30,23,59,59).beginning_of_quarter
end
-
+
def test_end_of_month
assert_equal Time.local(2005,3,31,0,0,0), Time.local(2005,3,20,10,10,10).end_of_month
assert_equal Time.local(2005,2,28,0,0,0), Time.local(2005,2,20,10,10,10).end_of_month
assert_equal Time.local(2005,4,30,0,0,0), Time.local(2005,4,20,10,10,10).end_of_month
-
+
end
-
+
def test_beginning_of_year
assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_year
end
-
+
def test_months_ago
assert_equal Time.local(2005,5,5,10), Time.local(2005,6,5,10,0,0).months_ago(1)
assert_equal Time.local(2004,11,5,10), Time.local(2005,6,5,10,0,0).months_ago(7)
@@ -65,31 +63,31 @@ def test_months_since
assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).months_since(12)
assert_equal Time.local(2007,6,5,10), Time.local(2005,6,5,10,0,0).months_since(24)
end
-
+
def test_years_ago
assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).years_ago(1)
assert_equal Time.local(1998,6,5,10), Time.local(2005,6,5,10,0,0).years_ago(7)
end
-
+
def test_years_since
assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).years_since(1)
assert_equal Time.local(2012,6,5,10), Time.local(2005,6,5,10,0,0).years_since(7)
# Failure because of size limitations of numeric?
- # assert_equal Time.local(2182,6,5,10), Time.local(2005,6,5,10,0,0).years_since(177)
+ # assert_equal Time.local(2182,6,5,10), Time.local(2005,6,5,10,0,0).years_since(177)
end
def test_last_year
assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).last_year
end
-
+
def test_ago
assert_equal Time.local(2005,2,22,10,10,9), Time.local(2005,2,22,10,10,10).ago(1)
assert_equal Time.local(2005,2,22,9,10,10), Time.local(2005,2,22,10,10,10).ago(3600)
assert_equal Time.local(2005,2,20,10,10,10), Time.local(2005,2,22,10,10,10).ago(86400*2)
assert_equal Time.local(2005,2,20,9,9,45), Time.local(2005,2,22,10,10,10).ago(86400*2 + 3600 + 25)
- end
-
+ end
+
def test_since
assert_equal Time.local(2005,2,22,10,10,11), Time.local(2005,2,22,10,10,10).since(1)
assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600)
@@ -101,12 +99,12 @@ def test_yesterday
assert_equal Time.local(2005,2,21,10,10,10), Time.local(2005,2,22,10,10,10).yesterday
assert_equal Time.local(2005,2,28,10,10,10), Time.local(2005,3,2,10,10,10).yesterday.yesterday
end
-
+
def test_tomorrow
assert_equal Time.local(2005,2,23,10,10,10), Time.local(2005,2,22,10,10,10).tomorrow
assert_equal Time.local(2005,3,2,10,10,10), Time.local(2005,2,28,10,10,10).tomorrow.tomorrow
end
-
+
def test_change
assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2006)
assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:month => 6)
@@ -120,7 +118,7 @@ def test_change
assert_equal Time.local(2005,1,2,11,22, 7, 0), Time.local(2005,1,2,11,22,33,44).change(:sec => 7)
assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(:usec => 8)
end
-
+
def test_utc_change
assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:year => 2006)
assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:month => 6)
@@ -136,7 +134,7 @@ def test_plus
assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7)
assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5)
end
-
+
def test_utc_plus
assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1)
assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4)
@@ -159,11 +157,11 @@ def test_to_s
time = Time.utc(2005, 2, 21, 17, 44, 30)
assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822)
end
-
+
def test_to_date
assert_equal Date.new(2005, 2, 21), Time.local(2005, 2, 21, 17, 44, 30).to_date
end
-
+
def test_to_time
assert_equal Time.local(2005, 2, 21, 17, 44, 30), Time.local(2005, 2, 21, 17, 44, 30).to_time
end
@@ -202,7 +200,7 @@ def test_next_month_on_31st
def test_last_month_on_31st
assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).last_month
end
-
+
def test_xmlschema_is_available
assert_nothing_raised { Time.now.xmlschema }
end
View
23 activesupport/test/dependencies_test.rb
@@ -1,13 +1,11 @@
-require 'test/unit'
-$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/active_support/'
-require 'core_ext/string'
-require 'dependencies'
+require File.dirname(__FILE__) + '/abstract_unit'
+#require 'dependencies'
class DependenciesTest < Test::Unit::TestCase
def teardown
Dependencies.clear
end
-
+
def with_loading(from_dir = nil)
prior_path = $LOAD_PATH.clone
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/#{from_dir}" if from_dir
@@ -103,11 +101,11 @@ def test_mutual_dependencies_dont_infinite_loop
assert_equal 2, $mutual_dependencies_count
end
end
-
+
def test_as_load_path
assert_equal '', DependenciesTest.as_load_path
end
-
+
def test_module_loading
with_loading 'autoloading_fixtures' do
assert_kind_of Module, A
@@ -116,7 +114,7 @@ def test_module_loading
assert_kind_of Class, A::C::E::F
end
end
-
+
def test_non_existing_const_raises_name_error
with_loading 'autoloading_fixtures' do
assert_raises(NameError) { DoesNotExist }
@@ -125,21 +123,21 @@ def test_non_existing_const_raises_name_error
assert_raises(NameError) { A::B::DoesNotExist }
end
end
-
+
def test_directories_should_manifest_as_modules
with_loading 'autoloading_fixtures' do
assert_kind_of Module, ModuleFolder
Object.send :remove_const, :ModuleFolder
end
end
-
+
def test_nested_class_access
with_loading 'autoloading_fixtures' do
assert_kind_of Class, ModuleFolder::NestedClass
Object.send :remove_const, :ModuleFolder
end
end
-
+
def test_nested_class_can_access_sibling
with_loading 'autoloading_fixtures' do
sibling = ModuleFolder::NestedClass.class_eval "NestedSibling"
@@ -148,7 +146,7 @@ def test_nested_class_can_access_sibling
Object.send :remove_const, :ModuleFolder
end
end
-
+
def failing_test_access_thru_and_upwards_fails
with_loading 'autoloading_fixtures' do
assert ! defined?(ModuleFolder)
@@ -157,5 +155,4 @@ def failing_test_access_thru_and_upwards_fails
Object.send :remove_const, :ModuleFolder
end
end
-
end
View
37 activesupport/test/inflector_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/active_support/inflector' unless defined? Inflector
+require File.dirname(__FILE__) + '/abstract_unit'
module Ace
module Base
@@ -63,14 +62,14 @@ class InflectorTest < Test::Unit::TestCase
"old_news" => "old_news",
"news" => "news",
-
+
"series" => "series",
"species" => "species",
"quiz" => "quizzes",
"perspective" => "perspectives",
-
+
"ox" => "oxen",
"photo" => "photos",
"buffalo" => "buffaloes",
@@ -79,7 +78,7 @@ class InflectorTest < Test::Unit::TestCase
"elf" => "elves",
"information" => "information",
"equipment" => "equipment",
- "bus" => "buses",
+ "bus" => "buses",
"status" => "statuses",
"status_code" => "status_codes",
"mouse" => "mice",
@@ -90,17 +89,17 @@ class InflectorTest < Test::Unit::TestCase
"virus" => "viri",
"alias" => "aliases",
"portfolio" => "portfolios",
-
+
"vertex" => "vertices",
"matrix" => "matrices",
-
+
"axis" => "axes",
"testis" => "testes",
"crisis" => "crises",
-
+
"rice" => "rice",
"shoe" => "shoes",
-
+
"horse" => "horses",
"prize" => "prizes",
"edge" => "edges"
@@ -117,16 +116,16 @@ class InflectorTest < Test::Unit::TestCase
"product" => "product",
"special_guest" => "specialGuest",
"application_controller" => "applicationController",
- "area51_controller" => "area51Controller"
+ "area51_controller" => "area51Controller"
}
-
+
CamelToUnderscoreWithoutReverse = {
"HTMLTidy" => "html_tidy",
"HTMLTidyGenerator" => "html_tidy_generator",
"FreeBSD" => "free_bsd",
"HTML" => "html",
}
-
+
CamelWithModuleToUnderscoreWithSlash = {
"Admin::Product" => "admin/product",
"Users::Commission::Department" => "users/commission/department",
@@ -142,12 +141,12 @@ class InflectorTest < Test::Unit::TestCase
"Person" => "personid",
"MyApplication::Billing::Account" => "accountid"
}
-
+
ClassNameToTableName = {
"PrimarySpokesman" => "primary_spokesmen",
"NodeChild" => "node_children"
}
-
+
UnderscoreToHuman = {
"employee_salary" => "Employee salary",
"employee_id" => "Employee",
@@ -194,7 +193,7 @@ class InflectorTest < Test::Unit::TestCase
"1000" => "1000th",
"1001" => "1001st"
}
-
+
UnderscoresToDashes = {
"street" => "street",
"street_address" => "street-address",
@@ -246,7 +245,7 @@ def test_camelize_with_module
assert_equal(camel, Inflector.camelize(underscore))
end
end
-
+
def test_underscore_with_slashes
CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore|
assert_equal(underscore, Inflector.underscore(camel))
@@ -284,13 +283,13 @@ def test_classify_with_symbol
assert_equal 'FooBar', Inflector.classify(:foo_bar)
end
end
-
+
def test_humanize
UnderscoreToHuman.each do |underscore, human|
assert_equal(human, Inflector.humanize(underscore))
end
end
-
+
def test_constantize
assert_equal Ace::Base::Case, Inflector.constantize("Ace::Base::Case")
assert_equal Ace::Base::Case, Inflector.constantize("::Ace::Base::Case")
@@ -299,7 +298,7 @@ def test_constantize
assert_raises(NameError) { Inflector.constantize("UnknownClass") }
assert_raises(NameError) { Inflector.constantize("An invalid string") }
end
-
+
def test_constantize_doesnt_look_in_parent
assert_raises(NameError) { Inflector.constantize("Ace::Base::InflectorTest") }
end
View
16 activesupport/test/json.rb
@@ -1,6 +1,4 @@
-$:.unshift File.dirname(__FILE__) + '/../lib'
-require 'active_support'
-require 'test/unit'
+require File.dirname(__FILE__) + '/abstract_unit'
class Foo
def initialize(a, b)
@@ -14,15 +12,15 @@ class TestJSONEmitters < Test::Unit::TestCase
NilTests = [[ nil, %(null) ]]
NumericTests = [[ 1, %(1) ],
[ 2.5, %(2.5) ]]
-
+
StringTests = [[ 'this is the string', %("this is the string") ],
[ 'a "string" with quotes', %("a \\"string\\" with quotes") ]]
-
+
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ],
[ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]]
-
+
HashTests = [[ {:a => :b, :c => :d}, %({\"c\": \"d\", \"a\": \"b\"}) ]]
-
+
SymbolTests = [[ :a, %("a") ],
[ :this, %("this") ],
[ :"a b", %("a b") ]]
@@ -40,7 +38,7 @@ class TestJSONEmitters < Test::Unit::TestCase
end
end
end
-
+
def test_utf8_string_encoded_properly_when_kcode_is_utf8
old_kcode, $KCODE = $KCODE, 'UTF8'
assert_equal '"\\u20ac2.99"', '€2.99'.to_json
@@ -48,7 +46,7 @@ def test_utf8_string_encoded_properly_when_kcode_is_utf8
ensure
$KCODE = old_kcode
end
-
+
def test_exception_raised_when_encoding_circular_reference
a = [1]
a << a
View
19 activesupport/test/option_merger_test.rb
@@ -1,25 +1,20 @@
-require 'test/unit'
-
-unless defined? ActiveSupport::OptionMerger
- require File.dirname(__FILE__) + '/../lib/active_support/option_merger'
- require File.dirname(__FILE__) + '/../lib/active_support/core_ext/object'
-end
+require File.dirname(__FILE__) + '/abstract_unit'
class OptionMergerTest < Test::Unit::TestCase
def setup
@options = {:hello => 'world'}
end
-
+
def test_method_with_options_merges_options_when_options_are_present
local_options = {:cool => true}
-
+
with_options(@options) do |o|
assert_equal local_options, method_with_options(local_options)
- assert_equal @options.merge(local_options),
+ assert_equal @options.merge(local_options),
o.method_with_options(local_options)
end
end
-
+
def test_method_with_options_appends_options_when_options_are_missing
with_options(@options) do |o|
assert_equal Hash.new, method_with_options
@@ -30,10 +25,10 @@ def test_method_with_options_appends_options_when_options_are_missing
def test_method_with_options_allows_to_overwrite_options
local_options = {:hello => 'moon'}
assert_equal @options.keys, local_options.keys
-
+
with_options(@options) do |o|
assert_equal local_options, method_with_options(local_options)
- assert_equal @options.merge(local_options),
+ assert_equal @options.merge(local_options),
o.method_with_options(local_options)
assert_equal local_options, o.method_with_options(local_options)
end
View
26 activesupport/test/ordered_options_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-
-require File.dirname(__FILE__) + '/../lib/active_support/ordered_options'
+require File.dirname(__FILE__) + '/abstract_unit'
class OrderedHashTest < Test::Unit::TestCase
def setup
@@ -8,19 +6,19 @@ def setup
@values = %w( 000099 009900 aa0000 cc0066 cc6633 )
@ordered_hash = ActiveSupport::OrderedHash.new(@keys.zip(@values))
end
-
+
def test_order
assert_equal @keys, @ordered_hash.keys
assert_equal @values, @ordered_hash.values
end
-
+
def test_access
assert @keys.zip(@values).all? { |k, v| @ordered_hash[k] == v }
end
-
+
def test_assignment
key, value = 'purple', '5422a8'
-
+
@ordered_hash[key] = value
assert_equal @keys.length + 1, @ordered_hash.length
assert_equal key, @ordered_hash.keys.last
@@ -35,7 +33,7 @@ def test_usage
assert_nil a[:not_set]
- a[:allow_concurreny] = true
+ a[:allow_concurreny] = true
assert_equal 1, a.size
assert a[:allow_concurreny]
@@ -47,27 +45,27 @@ def test_usage
assert_equal 2, a.size
assert_equal 56, a[:else_where]
end
-
+
def test_looping
a = OrderedOptions.new
- a[:allow_concurreny] = true
+ a[:allow_concurreny] = true
a["else_where"] = 56
-
+
test = [[:allow_concurreny, true], [:else_where, 56]]
-
+
a.each_with_index do |(key, value), index|
assert_equal test[index].first, key
assert_equal test[index].last, value
end
end
-
+
def test_method_access
a = OrderedOptions.new
assert_nil a.not_set
- a.allow_concurreny = true
+ a.allow_concurreny = true
assert_equal 1, a.size
assert a.allow_concurreny
View
23 activesupport/test/reloadable_test.rb
@@ -1,10 +1,7 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/active_support/core_ext/class'
-require File.dirname(__FILE__) + '/../lib/active_support/core_ext/module'
-require File.dirname(__FILE__) + '/../lib/active_support/reloadable'
+require File.dirname(__FILE__) + '/abstract_unit'
module ReloadableTestSandbox
-
+
class AReloadableClass
include Reloadable
end
@@ -24,17 +21,17 @@ def self.reloadable?
end
include Reloadable
end
-
+
class SubclassesReloadable
include Reloadable::Subclasses
end
class ASubclassOfSubclassesReloadable < SubclassesReloadable
end
-
+
class AnOnlySubclassReloadableClassSubclassingAReloadableClass
include Reloadable::Subclasses
end
-
+
class ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass < AnOnlySubclassReloadableClassSubclassingAReloadableClass
end
end
@@ -49,17 +46,17 @@ def test_classes_inherit_reloadable
def test_reloadable_is_not_overwritten_if_present
assert_equal 10, ReloadableTestSandbox::AClassWhichDefinesItsOwnReloadable.reloadable?
end
-
+
def test_only_subclass_reloadable
assert ! ReloadableTestSandbox::SubclassesReloadable.reloadable?
assert ReloadableTestSandbox::ASubclassOfSubclassesReloadable.reloadable?
end
-
+
def test_inside_hierarchy_only_subclass_reloadable
assert ! ReloadableTestSandbox::AnOnlySubclassReloadableClassSubclassingAReloadableClass.reloadable?
assert ReloadableTestSandbox::ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass.reloadable?
end
-
+
def test_removable_classes
reloadables = %w(
AReloadableClass
@@ -72,7 +69,7 @@ def test_removable_classes
ANonReloadableSubclass
SubclassesReloadable
)
-
+
results = Reloadable.reloadable_classes
reloadables.each do |name|
assert results.include?(ReloadableTestSandbox.const_get(name)), "Expected #{name} to be reloadable"
@@ -81,4 +78,4 @@ def test_removable_classes
assert ! results.include?(ReloadableTestSandbox.const_get(name)), "Expected #{name} NOT to be reloadable"
end
end
-end
+end
View
3  activesupport/test/time_zone_test.rb
@@ -1,5 +1,4 @@
-require 'test/unit'
-require File.dirname(__FILE__)+'/../lib/active_support/values/time_zone'
+require File.dirname(__FILE__) + '/abstract_unit'
class TimeZoneTest < Test::Unit::TestCase
class MockTime
View
12 activesupport/test/whiny_nil_test.rb
@@ -1,6 +1,4 @@
-require 'test/unit'
-
-# mock to enable testing without activerecord
+# Stub to enable testing without Active Record
module ActiveRecord
class Base
def save!
@@ -8,8 +6,8 @@ def save!
end
end
-require File.dirname(__FILE__) + '/../lib/active_support/inflector'
-require File.dirname(__FILE__) + '/../lib/active_support/whiny_nil'
+require File.dirname(__FILE__) + '/abstract_unit'
+require 'active_support/whiny_nil'
class WhinyNilTest < Test::Unit::TestCase
def test_unchanged
@@ -17,14 +15,14 @@ def test_unchanged
rescue NoMethodError => nme
assert_match(/nil.method_thats_not_in_whiners/, nme.message)
end
-
+
def test_active_record
nil.save!
rescue NoMethodError => nme
assert(!(nme.message =~ /nil:NilClass/))
assert_match(/nil\.save!/, nme.message)
end
-
+
def test_array
nil.each
rescue NoMethodError => nme
Please sign in to comment.
Something went wrong with that request. Please try again.