diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/configurable_test.rb | 22 | ||||
-rw-r--r-- | activesupport/test/core_ext/kernel_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 17 | ||||
-rw-r--r-- | activesupport/test/test_test.rb | 82 | ||||
-rw-r--r-- | activesupport/test/testing/performance_test.rb | 23 |
5 files changed, 93 insertions, 55 deletions
diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index 2e5ea2c360..da7729d066 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -5,7 +5,8 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase class Parent include ActiveSupport::Configurable config_accessor :foo - config_accessor :bar, :instance_reader => false, :instance_writer => false + config_accessor :bar, instance_reader: false, instance_writer: false + config_accessor :baz, instance_accessor: false end class Child < Parent @@ -19,13 +20,13 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase end test "adds a configuration hash" do - assert_equal({ :foo => :bar }, Parent.config) + assert_equal({ foo: :bar }, Parent.config) end test "adds a configuration hash to a module as well" do mixin = Module.new { include ActiveSupport::Configurable } mixin.config.foo = :bar - assert_equal({ :foo => :bar }, mixin.config) + assert_equal({ foo: :bar }, mixin.config) end test "configuration hash is inheritable" do @@ -39,8 +40,12 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase test "configuration accessors is not available on instance" do instance = Parent.new + assert !instance.respond_to?(:bar) assert !instance.respond_to?(:bar=) + + assert !instance.respond_to?(:baz) + assert !instance.respond_to?(:baz=) end test "configuration hash is available on instance" do @@ -71,6 +76,15 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase assert_method_defined child.new.config, :bar end + test "should raise name error if attribute name is invalid" do + assert_raises NameError do + Class.new do + include ActiveSupport::Configurable + config_accessor "invalid attribute name" + end + end + end + def assert_method_defined(object, method) methods = object.public_methods.map(&:to_s) assert methods.include?(method.to_s), "Expected #{methods.inspect} to include #{method.to_s.inspect}" @@ -80,4 +94,4 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase methods = object.public_methods.map(&:to_s) assert !methods.include?(method.to_s), "Expected #{methods.inspect} to not include #{method.to_s.inspect}" end -end +end
\ No newline at end of file diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index e90b9d454f..439bc87323 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -101,10 +101,10 @@ class KernelDebuggerTest < ActiveSupport::TestCase @logger ||= MockStdErr.new end end - Object.const_set("Rails", rails) + Object.const_set(:Rails, rails) debugger assert_match(/Debugger requested/, rails.logger.output.first) ensure - Object.send(:remove_const, "Rails") + Object.send(:remove_const, :Rails) end end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 081e6a16fd..69829bcda5 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -39,6 +39,19 @@ class DependenciesTest < ActiveSupport::TestCase with_loading 'autoloading_fixtures', &block end + def test_depend_on_path + skip "LoadError#path does not exist" if RUBY_VERSION < '2.0.0' + + expected = assert_raises(LoadError) do + Kernel.require 'omgwtfbbq' + end + + e = assert_raises(LoadError) do + ActiveSupport::Dependencies.depend_on 'omgwtfbbq' + end + assert_equal expected.path, e.path + end + def test_tracking_loaded_files require_dependency 'dependencies/service_one' require_dependency 'dependencies/service_two' @@ -60,10 +73,6 @@ class DependenciesTest < ActiveSupport::TestCase assert_raise(MissingSourceFile) { require_dependency("missing_service") } end - def test_missing_association_raises_nothing - assert_nothing_raised { require_association("missing_model") } - end - def test_dependency_which_raises_exception_isnt_added_to_loaded_set with_loading do filename = 'dependencies/raises_exception' diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 11506554a9..2473cec384 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -15,68 +15,64 @@ class AssertDifferenceTest < ActiveSupport::TestCase @object.num = 0 end - if lambda { }.respond_to?(:binding) - def test_assert_no_difference - assert_no_difference '@object.num' do - # ... - end + def test_assert_no_difference + assert_no_difference '@object.num' do + # ... end + end - def test_assert_difference - assert_difference '@object.num', +1 do - @object.increment - end + def test_assert_difference + assert_difference '@object.num', +1 do + @object.increment end + end - def test_assert_difference_with_implicit_difference - assert_difference '@object.num' do - @object.increment - end + def test_assert_difference_with_implicit_difference + assert_difference '@object.num' do + @object.increment end + end - def test_arbitrary_expression - assert_difference '@object.num + 1', +2 do - @object.increment - @object.increment - end + def test_arbitrary_expression + assert_difference '@object.num + 1', +2 do + @object.increment + @object.increment end + end - def test_negative_differences - assert_difference '@object.num', -1 do - @object.decrement - end + def test_negative_differences + assert_difference '@object.num', -1 do + @object.decrement end + end - def test_expression_is_evaluated_in_the_appropriate_scope - silence_warnings do - local_scope = local_scope = 'foo' - assert_difference('local_scope; @object.num') { @object.increment } - end + def test_expression_is_evaluated_in_the_appropriate_scope + silence_warnings do + local_scope = local_scope = 'foo' + assert_difference('local_scope; @object.num') { @object.increment } end + end - def test_array_of_expressions - assert_difference [ '@object.num', '@object.num + 1' ], +1 do - @object.increment - end + def test_array_of_expressions + assert_difference [ '@object.num', '@object.num + 1' ], +1 do + @object.increment end + end - def test_array_of_expressions_identify_failure - assert_raises(MiniTest::Assertion) do - assert_difference ['@object.num', '1 + 1'] do - @object.increment - end + def test_array_of_expressions_identify_failure + assert_raises(MiniTest::Assertion) do + assert_difference ['@object.num', '1 + 1'] do + @object.increment end end + end - def test_array_of_expressions_identify_failure_when_message_provided - assert_raises(MiniTest::Assertion) do - assert_difference ['@object.num', '1 + 1'], 1, 'something went wrong' do - @object.increment - end + def test_array_of_expressions_identify_failure_when_message_provided + assert_raises(MiniTest::Assertion) do + assert_difference ['@object.num', '1 + 1'], 1, 'something went wrong' do + @object.increment end end - else - def default_test; end end end diff --git a/activesupport/test/testing/performance_test.rb b/activesupport/test/testing/performance_test.rb index 74d7dae9e7..53073cb8db 100644 --- a/activesupport/test/testing/performance_test.rb +++ b/activesupport/test/testing/performance_test.rb @@ -11,7 +11,7 @@ module ActiveSupport assert_equal "1", amount_metric.format(1.23) assert_equal "40,000,000", amount_metric.format(40000000) end - + def test_time_format time_metric = ActiveSupport::Testing::Performance::Metrics[:time].new assert_equal "0 ms", time_metric.format(0) @@ -21,7 +21,7 @@ module ActiveSupport assert_equal "40000.00 sec", time_metric.format(40000) assert_equal "-5000 ms", time_metric.format(-5) end - + def test_space_format space_metric = ActiveSupport::Testing::Performance::Metrics[:digital_information_unit].new assert_equal "0 Bytes", space_metric.format(0) @@ -35,6 +35,25 @@ module ActiveSupport assert_equal "91 TB", space_metric.format(10**14) assert_equal "910000 TB", space_metric.format(10**18) end + + def test_environment_format_without_rails + metric = ActiveSupport::Testing::Performance::Metrics[:time].new + benchmarker = ActiveSupport::Testing::Performance::Benchmarker.new(self, metric) + assert_equal "#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL},#{RUBY_PLATFORM}", benchmarker.environment + end + + def test_environment_format_with_rails + rails, version = Module.new, Module.new + version.const_set :STRING, "4.0.0" + rails.const_set :VERSION, version + Object.const_set :Rails, rails + + metric = ActiveSupport::Testing::Performance::Metrics[:time].new + benchmarker = ActiveSupport::Testing::Performance::Benchmarker.new(self, metric) + assert_equal "rails-4.0.0,#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL},#{RUBY_PLATFORM}", benchmarker.environment + ensure + Object.send :remove_const, :Rails + end end end end
\ No newline at end of file |