mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add test coverage to module setup extensions
This commit is contained in:
parent
bfc1609a50
commit
783deae99a
1 changed files with 74 additions and 0 deletions
74
activesupport/test/core_ext/module/setup_test.rb
Normal file
74
activesupport/test/core_ext/module/setup_test.rb
Normal file
|
@ -0,0 +1,74 @@
|
|||
require 'abstract_unit'
|
||||
require 'active_support/core/time'
|
||||
require 'active_support/core_ext/module/setup'
|
||||
|
||||
class SetupTest < Test::Unit::TestCase
|
||||
module Baz
|
||||
module ClassMethods
|
||||
def baz
|
||||
"baz"
|
||||
end
|
||||
|
||||
def setup=(value)
|
||||
@@setup = value
|
||||
end
|
||||
|
||||
def setup
|
||||
@@setup
|
||||
end
|
||||
end
|
||||
|
||||
setup do
|
||||
self.setup = true
|
||||
end
|
||||
|
||||
def baz
|
||||
"baz"
|
||||
end
|
||||
end
|
||||
|
||||
module Bar
|
||||
depends_on Baz
|
||||
|
||||
def bar
|
||||
"bar"
|
||||
end
|
||||
|
||||
def baz
|
||||
"bar+" + super
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
@klass = Class.new
|
||||
end
|
||||
|
||||
def test_module_is_included_normally
|
||||
@klass.use(Baz)
|
||||
assert_equal "baz", @klass.new.baz
|
||||
assert_equal SetupTest::Baz, @klass.included_modules[0]
|
||||
|
||||
@klass.use(Baz)
|
||||
assert_equal "baz", @klass.new.baz
|
||||
assert_equal SetupTest::Baz, @klass.included_modules[0]
|
||||
end
|
||||
|
||||
def test_class_methods_are_extended
|
||||
@klass.use(Baz)
|
||||
assert_equal "baz", @klass.baz
|
||||
assert_equal SetupTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0]
|
||||
end
|
||||
|
||||
def test_setup_block_is_ran
|
||||
@klass.use(Baz)
|
||||
assert_equal true, @klass.setup
|
||||
end
|
||||
|
||||
def test_modules_dependencies_are_met
|
||||
@klass.use(Bar)
|
||||
assert_equal "bar", @klass.new.bar
|
||||
assert_equal "bar+baz", @klass.new.baz
|
||||
assert_equal "baz", @klass.baz
|
||||
assert_equal [SetupTest::Bar, SetupTest::Baz], @klass.included_modules[0..1]
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue