Sha256: b3af704885746733ec7cc656eea4e2f953b083088993d76123c05cd31c211fd3
Contents?: true
Size: 1.96 KB
Versions: 2
Compression:
Stored size: 1.96 KB
Contents
require 'test_helper' class ApplicationTest < Minitest::Test def test_defining_an_application Pico.define_application :Foo Pico.boot! refute_nil Pico.application assert_equal :Foo, Pico.application.name assert_equal Pathname(__FILE__).dirname, Pico.application.root end def test_autoload_paths Pico.define_application :Foo do self.autoload_paths = %w(lib app) end assert_equal %w(lib app), Pico.application.autoload_paths end def test_providing_objects Pico.define_application :Foo do provide as: 'foo' do :provided_foo; end provide :provided_bar, as: 'bar' provide 'MyClass', as: 'baz' end Pico.boot! my_class = Class.new do def message; :provided_baz; end ; end Object.const_set :MyClass, my_class consumer = Class.new do attr :foo, :bar, :baz, :ping def initialize(foo, bar, baz, ping:) @foo = foo ; @bar = bar ; @baz = baz; @ping = ping end end Foo.const_set :Consumer, consumer obj = Foo.build(:Consumer, ping: 'pong') assert_equal :provided_foo, obj.foo assert_equal :provided_bar, obj.bar assert_equal :provided_baz, obj.baz.message assert_equal 'pong', obj.ping ensure Object.send :remove_const, :MyClass end def test_wraps_ruse_errors Pico.define_application :Foo Pico.boot! consumer = Class.new do attr :unmet_dep def initialize(unmet_dep) @unmet_dep = unmet_dep end end Foo.const_set :Consumer, consumer exception = assert_raises Pico::Exception do Foo.build(:Consumer) end assert_equal "could not resolve dependency `unmet_dep'", exception.message end def test_cannot_provide_object_as_block_and_arg exception = assert_raises ArgumentError do Pico.define_application :Foo do provide :a_value, as: :foo do :another_value end end end assert_equal "cannot supply a block and a value", exception.message end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pico-0.1.0 | test/unit/application_test.rb |
pico-0.0.1 | test/unit/application_test.rb |