test/api_test.rb in dao-5.6.1 vs test/api_test.rb in dao-7.0.0

- old
+ new

@@ -1,21 +1,20 @@ # -*- encoding : utf-8 -*- +require_relative 'test_helper' - -Testing Dao do +class DaoTest < ::Dao::TestCase ## api # - testing 'that an api class for your application can be built using a simple dsl' do + test 'that an api class for your application can be built using a simple dsl' do assert{ - api_class = - Dao.api do - ### dsl - end + Dao.api do + ### dsl + end } end - testing 'that apis can have callable endpoints added to them which accept params and return results' do + test 'that apis can have callable endpoints added to them which accept params and return results' do captured = [] api_class = assert{ Dao.api do @@ -27,29 +26,29 @@ api = assert{ api_class.new } result = assert{ api.call(:foo, {}) } assert{ result.is_a?(Hash) } end - testing 'that endpoints are automatically called according to arity' do + test 'that endpoints are automatically called according to arity' do api = assert{ Class.new(Dao.api) } assert{ api.class_eval{ endpoint(:zero){|| result.update :args => [] } } } assert{ api.class_eval{ endpoint(:one){|a| result.update :args => [a]} } } assert{ api.class_eval{ endpoint(:two){|a,b| result.update :args => [a,b]} } } assert{ api.new.call(:zero).args.size == 0 } assert{ api.new.call(:one).args.size == 1 } assert{ api.new.call(:two).args.size == 2 } end - testing 'that endpoints have an auto-vivifying params/result' do + test 'that endpoints have an auto-vivifying params/result' do api = assert{ Class.new(Dao.api) } assert{ api.class_eval{ endpoint(:foo){ params; result; } } } result = assert{ api.new.call(:foo) } assert{ result.path.to_s =~ /foo/ } end - testing 'that an api can be called with different modes' do + test 'that an api can be called with different modes' do Dao::Mode.list.each do |mode| api_class = assert{ Dao.api do call(:foo) do @@ -61,11 +60,11 @@ assert{ api.mode(mode).call(:foo).data[:mode] == mode } end end - testing 'that read==get' do + test 'that read==get' do api_class = assert{ Dao.api do call(:foo) do read { data.update :answer => 42 } @@ -83,11 +82,11 @@ assert{ api.read.call(:bar).data.answer == 42.0 } assert{ api.get.call(:bar).data.answer == 42.0 } end - testing 'that write==post' do + test 'that write==post' do api_class = assert{ Dao.api do call(:foo) do write { data.update :answer => 42 } @@ -105,11 +104,11 @@ assert{ api.write.call(:bar).data.answer == 42.0 } assert{ api.post.call(:bar).data.answer == 42.0 } end - testing 'that aliases are re-defined in scope' do + test 'that aliases are re-defined in scope' do api_class = assert{ Dao.api do call(:foo) do data.update :a => mode @@ -147,11 +146,11 @@ end end ## context # - testing 'that calls have a shortcut to status' do + test 'that calls have a shortcut to status' do api_class = assert{ Dao.api do call(:foo){ status! 420 } end @@ -161,59 +160,59 @@ assert{ result.status =~ 420 } end ## results # - testing 'that results can be created' do + test 'that results can be created' do result = assert{ Dao::Result.new } assert{ result.path } assert{ result.status } assert{ result.errors } assert{ result.params } assert{ result.data } end - testing 'that results can be created with a path' do + test 'that results can be created with a path' do result = assert{ Dao::Result.new('/api/foo/bar') } assert{ result.path == '/api/foo/bar' } end ## paths # - testing 'that simple paths can be contstructed/compiled' do + test 'that simple paths can be contstructed/compiled' do path = assert{ Dao::Path.for('./api/../foo/bar') } assert{ path =~ %r|^/| } assert{ path !~ %r|[.]| } assert{ path.params.is_a?(Hash) } assert{ path.keys.is_a?(Array) } assert{ path.pattern.is_a?(Regexp) } end ## routes # - testing 'that an api has a list of routes' do + test 'that an api has a list of routes' do api_class = assert{ Dao.api do end } assert{ api_class.routes.is_a?(Array) } end - testing 'that routed endpoints call be declared' do + test 'that routed endpoints call be declared' do api_class = assert{ Dao.api do call('/users/:user_id/comments/:comment_id') do data.update(params) end end } - api = api_class.new + api_class.new end - testing 'that routed methods can be called with embedded params' do + test 'that routed methods can be called with embedded params' do api_class = assert{ Dao.api do call('/users/:user_id/comments/:comment_id') do data.update(params) @@ -234,11 +233,11 @@ end end ## doc # - testing 'that apis can be documented via the api' do + test 'that apis can be documented via the api' do api_class = assert { Dao.api { description 'foobar' doc 'signature' => {'read' => '...', 'write' => '...'} @@ -251,11 +250,11 @@ assert{ api_class_index==api_index } end # aliases # - testing 'that apis can alias methods' do + test 'that apis can alias methods' do api_class = assert { Dao.api { call('/barfoo'){ data.update(:k => :v) } call('/foobar', :alias => '/barfoo') @@ -272,19 +271,9 @@ array[a] == array[b] end def api(&block) api_class = assert{ Dao.api(&block) } - api = assert{ api_class.new } + assert{ api_class.new } end end - -BEGIN { - testdir = File.dirname(File.expand_path(__FILE__)) - rootdir = File.dirname(testdir) - libdir = File.join(rootdir, 'lib') - - require File.join(libdir, 'dao') - require File.join(testdir, 'testing') - require File.join(testdir, 'helper') -}