dao 5.5.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
 - data/README.md +258 -0
 - data/Rakefile +4 -5
 - data/coerce-0.0.8/README +28 -0
 - data/coerce-0.0.8/Rakefile +392 -0
 - data/coerce-0.0.8/coerce.gemspec +31 -0
 - data/coerce-0.0.8/lib/coerce.rb +210 -0
 - data/dao.gemspec +38 -25
 - data/lib/dao.rb +18 -81
 - data/lib/dao/_lib.rb +42 -0
 - data/lib/dao/active_record.rb +8 -8
 - data/lib/dao/api/call.rb +19 -4
 - data/lib/dao/api/dsl.rb +1 -1
 - data/lib/dao/coerce.rb +211 -0
 - data/lib/dao/conducer.rb +10 -14
 - data/lib/dao/conducer/controller_support.rb +5 -0
 - data/lib/dao/conducer/view_support.rb +0 -2
 - data/lib/dao/db.rb +0 -1
 - data/lib/dao/errors.rb +17 -11
 - data/lib/dao/errors2html.rb +128 -0
 - data/lib/dao/form.rb +13 -16
 - data/lib/dao/messages.rb +0 -4
 - data/lib/dao/path.rb +1 -1
 - data/lib/dao/route.rb +2 -2
 - data/lib/dao/status.rb +3 -4
 - data/lib/dao/support.rb +26 -19
 - data/lib/dao/upload.rb +0 -1
 - data/lib/dao/validations/common.rb +6 -6
 - data/lib/dao/validations/validator.rb +3 -3
 - data/lib/dao/wrap.rb +259 -0
 - data/tasks/default.rake +207 -0
 - data/tasks/this.rb +207 -0
 - data/test/active_model_conducer_lint_test.rb +3 -11
 - data/test/api_test.rb +24 -35
 - data/test/conducer_test.rb +37 -47
 - data/test/errors_test.rb +29 -13
 - data/test/form_test.rb +24 -34
 - data/test/rake_rerun_reporter.rb +74 -0
 - data/test/support_test.rb +9 -14
 - data/test/test_helper.rb +220 -0
 - data/test/{helper.rb → util.rb} +0 -0
 - data/test/validations_test.rb +14 -28
 - data/wrap-1.5.2/README +57 -0
 - data/wrap-1.5.2/Rakefile +394 -0
 - data/wrap-1.5.2/lib/wrap.rb +295 -0
 - data/{test → wrap-1.5.2/test}/testing.rb +0 -1
 - data/wrap-1.5.2/test/wrap_test.rb +397 -0
 - data/wrap-1.5.2/wrap.gemspec +38 -0
 - metadata +47 -103
 - data/Gemfile +0 -16
 - data/Gemfile.lock +0 -118
 - data/README +0 -256
 
    
        data/test/errors_test.rb
    CHANGED
    
    | 
         @@ -1,7 +1,22 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- encoding : utf-8 -*-
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
            class DaoErrorsTest < Dao::TestCase
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
      
 5 
     | 
    
         
            +
              test 'that errors have #to_html' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                e = Dao::Errors.new
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                e.add 'is fucked'
         
     | 
| 
      
 9 
     | 
    
         
            +
                e.add 'foo is fucked'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                actual = e.to_html
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                expected = <<-__
         
     | 
| 
      
 14 
     | 
    
         
            +
                __
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                assert compress(actual) == compress(expected)
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              test 'that conducer-less error objects scopes keys in a generic fashion' do
         
     | 
| 
       5 
20 
     | 
    
         
             
                e = Dao::Errors.new
         
     | 
| 
       6 
21 
     | 
    
         | 
| 
       7 
22 
     | 
    
         
             
                e.add 'is fucked'
         
     | 
| 
         @@ -19,7 +34,7 @@ Testing Dao::Errors do 
     | 
|
| 
       19 
34 
     | 
    
         
             
                assert compress(actual) == compress(expected)
         
     | 
| 
       20 
35 
     | 
    
         
             
              end
         
     | 
| 
       21 
36 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
               
     | 
| 
      
 37 
     | 
    
         
            +
              test 'that conducer-based error objects scope keys in a model_name based fashion' do
         
     | 
| 
       23 
38 
     | 
    
         
             
                c = new_foo_conducer
         
     | 
| 
       24 
39 
     | 
    
         | 
| 
       25 
40 
     | 
    
         
             
                e = c.errors 
         
     | 
| 
         @@ -29,7 +44,7 @@ Testing Dao::Errors do 
     | 
|
| 
       29 
44 
     | 
    
         
             
                e.add :first_name, 'is fucked'
         
     | 
| 
       30 
45 
     | 
    
         
             
                e.add :last_name, 'is fucked'
         
     | 
| 
       31 
46 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                actual = e.to_text 
     | 
| 
      
 47 
     | 
    
         
            +
                actual = e.to_text
         
     | 
| 
       33 
48 
     | 
    
         | 
| 
       34 
49 
     | 
    
         
             
                expected = <<-__
         
     | 
| 
       35 
50 
     | 
    
         
             
                  ---
         
     | 
| 
         @@ -45,6 +60,16 @@ Testing Dao::Errors do 
     | 
|
| 
       45 
60 
     | 
    
         
             
                assert compress(actual) == compress(expected)
         
     | 
| 
       46 
61 
     | 
    
         
             
              end
         
     | 
| 
       47 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
            =begin
         
     | 
| 
      
 64 
     | 
    
         
            +
              test 'that `nested` errors `nest`' do
         
     | 
| 
      
 65 
     | 
    
         
            +
                e = Dao::Errors.new
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                e.relay 'foo.bar' => 'is fucked'
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            p e.to_hash
         
     | 
| 
      
 70 
     | 
    
         
            +
                assert e.to_hash == {'foo' => {'bar' => 'is fucked'}} 
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
            =end
         
     | 
| 
       48 
73 
     | 
    
         | 
| 
       49 
74 
     | 
    
         | 
| 
       50 
75 
     | 
    
         
             
            protected
         
     | 
| 
         @@ -70,12 +95,3 @@ protected 
     | 
|
| 
       70 
95 
     | 
    
         
             
              end
         
     | 
| 
       71 
96 
     | 
    
         
             
              alias_method :new_conducer, :new_foo_conducer
         
     | 
| 
       72 
97 
     | 
    
         
             
            end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
            BEGIN {
         
     | 
| 
       75 
     | 
    
         
            -
              testdir = File.dirname(File.expand_path(__FILE__))
         
     | 
| 
       76 
     | 
    
         
            -
              rootdir = File.dirname(testdir)
         
     | 
| 
       77 
     | 
    
         
            -
              libdir = File.join(rootdir, 'lib')
         
     | 
| 
       78 
     | 
    
         
            -
              require File.join(libdir, 'dao')
         
     | 
| 
       79 
     | 
    
         
            -
              require File.join(testdir, 'testing')
         
     | 
| 
       80 
     | 
    
         
            -
              require 'stringio'
         
     | 
| 
       81 
     | 
    
         
            -
            }
         
     | 
    
        data/test/form_test.rb
    CHANGED
    
    | 
         @@ -1,25 +1,26 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- encoding : utf-8 -*-
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
            class DaoFormTest < ::Dao::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              test '.new' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                _ = new_form() 
         
     | 
| 
      
 6 
     | 
    
         
            +
                _ = new_named_form() 
         
     | 
| 
       6 
7 
     | 
    
         
             
              end
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
      
 9 
     | 
    
         
            +
              test 'name_for' do
         
     | 
| 
       9 
10 
     | 
    
         
             
                assert{ Dao::Form.name_for(:foo, :a, :b) == 'dao[foo][a.b]' }
         
     | 
| 
       10 
11 
     | 
    
         
             
                assert{ new_form.name_for(:a, :b) == 'dao[form][a.b]' }
         
     | 
| 
       11 
12 
     | 
    
         
             
                assert{ new_named_form.name_for(:a, :b) == 'dao[name][a.b]' }
         
     | 
| 
       12 
13 
     | 
    
         
             
                assert{ new_named_form(:foo).name_for(:a, :b) == 'dao[foo][a.b]' }
         
     | 
| 
       13 
14 
     | 
    
         
             
              end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
               
     | 
| 
      
 16 
     | 
    
         
            +
              test 'scope_for' do
         
     | 
| 
       16 
17 
     | 
    
         
             
                form = new_form() 
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                assert do
         
     | 
| 
       19 
20 
     | 
    
         
             
                  html = form.input(:bar)
         
     | 
| 
       20 
21 
     | 
    
         
             
                  scmp(
         
     | 
| 
       21 
22 
     | 
    
         
             
                    html,
         
     | 
| 
       22 
     | 
    
         
            -
                    '<input type="text" name="dao[form][bar]" class="dao" id=" 
     | 
| 
      
 23 
     | 
    
         
            +
                    '<input type="text" name="dao[form][bar]" class="dao" id="form--bar"/>'
         
     | 
| 
       23 
24 
     | 
    
         
             
                  )
         
     | 
| 
       24 
25 
     | 
    
         
             
                end
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
         @@ -28,7 +29,7 @@ Testing Dao::Form do 
     | 
|
| 
       28 
29 
     | 
    
         
             
                    html = form.input(:bar)
         
     | 
| 
       29 
30 
     | 
    
         
             
                    scmp(
         
     | 
| 
       30 
31 
     | 
    
         
             
                      html,
         
     | 
| 
       31 
     | 
    
         
            -
                      '<input type="text" name="dao[form][foo.bar]" class="dao" id=" 
     | 
| 
      
 32 
     | 
    
         
            +
                      '<input type="text" name="dao[form][foo.bar]" class="dao" id="form--foo-bar"/>'
         
     | 
| 
       32 
33 
     | 
    
         
             
                    )
         
     | 
| 
       33 
34 
     | 
    
         
             
                  end
         
     | 
| 
       34 
35 
     | 
    
         
             
                end
         
     | 
| 
         @@ -37,12 +38,12 @@ Testing Dao::Form do 
     | 
|
| 
       37 
38 
     | 
    
         
             
                  html = form.input(:bar)
         
     | 
| 
       38 
39 
     | 
    
         
             
                  scmp(
         
     | 
| 
       39 
40 
     | 
    
         
             
                    html,
         
     | 
| 
       40 
     | 
    
         
            -
                    '<input type="text" name="dao[form][bar]" class="dao" id=" 
     | 
| 
      
 41 
     | 
    
         
            +
                    '<input type="text" name="dao[form][bar]" class="dao" id="form--bar"/>'
         
     | 
| 
       41 
42 
     | 
    
         
             
                  )
         
     | 
| 
       42 
43 
     | 
    
         
             
                end
         
     | 
| 
       43 
44 
     | 
    
         
             
              end
         
     | 
| 
       44 
45 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
               
     | 
| 
      
 46 
     | 
    
         
            +
              test 'Form#select' do
         
     | 
| 
       46 
47 
     | 
    
         
             
              #
         
     | 
| 
       47 
48 
     | 
    
         
             
                form = new_form() 
         
     | 
| 
       48 
49 
     | 
    
         
             
                form.attributes.set :key => 42 
         
     | 
| 
         @@ -52,7 +53,7 @@ Testing Dao::Form do 
     | 
|
| 
       52 
53 
     | 
    
         
             
                assert do
         
     | 
| 
       53 
54 
     | 
    
         
             
                  scmp(
         
     | 
| 
       54 
55 
     | 
    
         
             
                    html,
         
     | 
| 
       55 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 56 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"> </select>'
         
     | 
| 
       56 
57 
     | 
    
         
             
                  )
         
     | 
| 
       57 
58 
     | 
    
         
             
                end
         
     | 
| 
       58 
59 
     | 
    
         | 
| 
         @@ -61,7 +62,7 @@ Testing Dao::Form do 
     | 
|
| 
       61 
62 
     | 
    
         
             
                assert do
         
     | 
| 
       62 
63 
     | 
    
         
             
                  scmp(
         
     | 
| 
       63 
64 
     | 
    
         
             
                    html,
         
     | 
| 
       64 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 65 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
         
     | 
| 
       65 
66 
     | 
    
         
             
                  )
         
     | 
| 
       66 
67 
     | 
    
         
             
               end
         
     | 
| 
       67 
68 
     | 
    
         | 
| 
         @@ -70,7 +71,7 @@ Testing Dao::Form do 
     | 
|
| 
       70 
71 
     | 
    
         
             
                assert do
         
     | 
| 
       71 
72 
     | 
    
         
             
                  scmp(
         
     | 
| 
       72 
73 
     | 
    
         
             
                    html,
         
     | 
| 
       73 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 74 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="1">A</option><option value="2">B</option><option value="3">C</option></select>'
         
     | 
| 
       74 
75 
     | 
    
         
             
                  )
         
     | 
| 
       75 
76 
     | 
    
         
             
               end
         
     | 
| 
       76 
77 
     | 
    
         | 
| 
         @@ -79,7 +80,7 @@ Testing Dao::Form do 
     | 
|
| 
       79 
80 
     | 
    
         
             
                assert do
         
     | 
| 
       80 
81 
     | 
    
         
             
                  scmp(
         
     | 
| 
       81 
82 
     | 
    
         
             
                    html,
         
     | 
| 
       82 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 83 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option></option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
         
     | 
| 
       83 
84 
     | 
    
         
             
                  )
         
     | 
| 
       84 
85 
     | 
    
         
             
               end
         
     | 
| 
       85 
86 
     | 
    
         | 
| 
         @@ -88,7 +89,7 @@ Testing Dao::Form do 
     | 
|
| 
       88 
89 
     | 
    
         
             
                assert do
         
     | 
| 
       89 
90 
     | 
    
         
             
                  scmp(
         
     | 
| 
       90 
91 
     | 
    
         
             
                    html,
         
     | 
| 
       91 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 92 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option></option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
         
     | 
| 
       92 
93 
     | 
    
         
             
                  )
         
     | 
| 
       93 
94 
     | 
    
         
             
               end
         
     | 
| 
       94 
95 
     | 
    
         | 
| 
         @@ -97,7 +98,7 @@ Testing Dao::Form do 
     | 
|
| 
       97 
98 
     | 
    
         
             
                assert do
         
     | 
| 
       98 
99 
     | 
    
         
             
                  scmp(
         
     | 
| 
       99 
100 
     | 
    
         
             
                    html,
         
     | 
| 
       100 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 101 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="">42</option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
         
     | 
| 
       101 
102 
     | 
    
         
             
                  )
         
     | 
| 
       102 
103 
     | 
    
         
             
               end
         
     | 
| 
       103 
104 
     | 
    
         | 
| 
         @@ -106,7 +107,7 @@ Testing Dao::Form do 
     | 
|
| 
       106 
107 
     | 
    
         
             
                assert do
         
     | 
| 
       107 
108 
     | 
    
         
             
                  scmp(
         
     | 
| 
       108 
109 
     | 
    
         
             
                    html,
         
     | 
| 
       109 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 110 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
         
     | 
| 
       110 
111 
     | 
    
         
             
                  )
         
     | 
| 
       111 
112 
     | 
    
         
             
               end
         
     | 
| 
       112 
113 
     | 
    
         | 
| 
         @@ -115,7 +116,7 @@ Testing Dao::Form do 
     | 
|
| 
       115 
116 
     | 
    
         
             
                assert do
         
     | 
| 
       116 
117 
     | 
    
         
             
                  scmp(
         
     | 
| 
       117 
118 
     | 
    
         
             
                    html,
         
     | 
| 
       118 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 119 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="a">a</option><option value="b" selected>b</option><option value="c">c</option></select>'
         
     | 
| 
       119 
120 
     | 
    
         
             
                  )
         
     | 
| 
       120 
121 
     | 
    
         
             
                end
         
     | 
| 
       121 
122 
     | 
    
         | 
| 
         @@ -130,7 +131,7 @@ Testing Dao::Form do 
     | 
|
| 
       130 
131 
     | 
    
         
             
                assert do
         
     | 
| 
       131 
132 
     | 
    
         
             
                  scmp(
         
     | 
| 
       132 
133 
     | 
    
         
             
                    html,
         
     | 
| 
       133 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 134 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
         
     | 
| 
       134 
135 
     | 
    
         
             
                  )
         
     | 
| 
       135 
136 
     | 
    
         
             
                end
         
     | 
| 
       136 
137 
     | 
    
         | 
| 
         @@ -145,7 +146,7 @@ Testing Dao::Form do 
     | 
|
| 
       145 
146 
     | 
    
         
             
                assert do
         
     | 
| 
       146 
147 
     | 
    
         
             
                  scmp(
         
     | 
| 
       147 
148 
     | 
    
         
             
                    html,
         
     | 
| 
       148 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 149 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
         
     | 
| 
       149 
150 
     | 
    
         
             
                  )
         
     | 
| 
       150 
151 
     | 
    
         
             
                end
         
     | 
| 
       151 
152 
     | 
    
         | 
| 
         @@ -160,14 +161,15 @@ Testing Dao::Form do 
     | 
|
| 
       160 
161 
     | 
    
         
             
                assert do
         
     | 
| 
       161 
162 
     | 
    
         
             
                  scmp(
         
     | 
| 
       162 
163 
     | 
    
         
             
                    html,
         
     | 
| 
       163 
     | 
    
         
            -
                    '<select name="dao[form][key]" class="dao" id=" 
     | 
| 
      
 164 
     | 
    
         
            +
                    '<select name="dao[form][key]" class="dao" id="form--key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
         
     | 
| 
       164 
165 
     | 
    
         
             
                  )
         
     | 
| 
       165 
166 
     | 
    
         
             
                end
         
     | 
| 
       166 
167 
     | 
    
         
             
              end
         
     | 
| 
       167 
168 
     | 
    
         | 
| 
       168 
169 
     | 
    
         
             
            protected
         
     | 
| 
       169 
170 
     | 
    
         
             
              def new_form
         
     | 
| 
       170 
     | 
    
         
            -
                assert{ Dao::Form.new }
         
     | 
| 
      
 171 
     | 
    
         
            +
                #assert{ Dao::Form.new }
         
     | 
| 
      
 172 
     | 
    
         
            +
                Dao::Form.new
         
     | 
| 
       171 
173 
     | 
    
         
             
              end
         
     | 
| 
       172 
174 
     | 
    
         | 
| 
       173 
175 
     | 
    
         
             
              def new_named_form(name = 'name')
         
     | 
| 
         @@ -182,15 +184,3 @@ protected 
     | 
|
| 
       182 
184 
     | 
    
         
             
                assert{ Dao::Form.new(object) }
         
     | 
| 
       183 
185 
     | 
    
         
             
              end
         
     | 
| 
       184 
186 
     | 
    
         
             
            end
         
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
            BEGIN {
         
     | 
| 
       189 
     | 
    
         
            -
              testdir = File.dirname(File.expand_path(__FILE__))
         
     | 
| 
       190 
     | 
    
         
            -
              rootdir = File.dirname(testdir)
         
     | 
| 
       191 
     | 
    
         
            -
              libdir = File.join(rootdir, 'lib')
         
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
              require File.join(libdir, 'dao')
         
     | 
| 
       194 
     | 
    
         
            -
              require File.join(testdir, 'testing')
         
     | 
| 
       195 
     | 
    
         
            -
              require File.join(testdir, 'helper')
         
     | 
| 
       196 
     | 
    
         
            -
            }
         
     | 
| 
         @@ -0,0 +1,74 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "minitest/reporters"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Minitest
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Reporters
         
     | 
| 
      
 5 
     | 
    
         
            +
                class RakeRerunReporter < Minitest::Reporters::DefaultReporter
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def initialize(options = {})
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @rerun_user_prefix=options.fetch(:rerun_prefix, "")
         
     | 
| 
      
 9 
     | 
    
         
            +
                    super
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def report
         
     | 
| 
      
 13 
     | 
    
         
            +
                    super
         
     | 
| 
      
 14 
     | 
    
         
            +
                  
         
     | 
| 
      
 15 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 16 
     | 
    
         
            +
                  
         
     | 
| 
      
 17 
     | 
    
         
            +
                    unless @fast_fail
         
     | 
| 
      
 18 
     | 
    
         
            +
                      #print rerun commands
         
     | 
| 
      
 19 
     | 
    
         
            +
                      failed_or_error_tests=(tests.select {|t| t.failure && !t.skipped? })
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                      unless failed_or_error_tests.empty?
         
     | 
| 
      
 22 
     | 
    
         
            +
                        puts red("You can rerun failed/error test by commands (you can add rerun prefix with 'rerun_prefix' option):")
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                        failed_or_error_tests.each do |test|
         
     | 
| 
      
 25 
     | 
    
         
            +
                          print_rerun_command(test)
         
     | 
| 
      
 26 
     | 
    
         
            +
                        end
         
     | 
| 
      
 27 
     | 
    
         
            +
                      end
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    
         
     | 
| 
      
 30 
     | 
    
         
            +
                    #summary for all suite again
         
     | 
| 
      
 31 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 32 
     | 
    
         
            +
                    print colored_for(suite_result, result_line)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 34 
     | 
    
         
            +
                    
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end  
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  private
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    def print_rerun_command(test)
         
     | 
| 
      
 40 
     | 
    
         
            +
                      message = rerun_message_for(test)
         
     | 
| 
      
 41 
     | 
    
         
            +
                      unless message.nil? || message.strip == ''
         
     | 
| 
      
 42 
     | 
    
         
            +
                        puts
         
     | 
| 
      
 43 
     | 
    
         
            +
                        puts colored_for(result(test), message)
         
     | 
| 
      
 44 
     | 
    
         
            +
                      end
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    def rerun_message_for(test)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      file_path=location(test.failure).gsub(/(\:\d*)\z/,"")
         
     | 
| 
      
 49 
     | 
    
         
            +
                      msg="#{@rerun_user_prefix} rake test TEST=#{file_path} TESTOPTS=\"--name=#{test.name} -v\""
         
     | 
| 
      
 50 
     | 
    
         
            +
                      if test.skipped?
         
     | 
| 
      
 51 
     | 
    
         
            +
                        "Skipped: \n#{msg}"
         
     | 
| 
      
 52 
     | 
    
         
            +
                      elsif test.error?
         
     | 
| 
      
 53 
     | 
    
         
            +
                        "Error:\n#{msg}"
         
     | 
| 
      
 54 
     | 
    
         
            +
                      else
         
     | 
| 
      
 55 
     | 
    
         
            +
                        "Failure:\n#{msg}"
         
     | 
| 
      
 56 
     | 
    
         
            +
                      end
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    
         
     | 
| 
      
 59 
     | 
    
         
            +
                    def location(exception)
         
     | 
| 
      
 60 
     | 
    
         
            +
                      last_before_assertion = ''
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                      exception.backtrace.reverse_each do |ss|
         
     | 
| 
      
 63 
     | 
    
         
            +
                        break if ss =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
         
     | 
| 
      
 64 
     | 
    
         
            +
                        last_before_assertion = ss
         
     | 
| 
      
 65 
     | 
    
         
            +
                        break if ss=~ /_test.rb\:/
         
     | 
| 
      
 66 
     | 
    
         
            +
                      end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                      last_before_assertion.sub(/:in .*$/, '')
         
     | 
| 
      
 69 
     | 
    
         
            +
                    end  
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
            end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
    
        data/test/support_test.rb
    CHANGED
    
    | 
         @@ -1,20 +1,22 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # -*- encoding : utf-8 -*-
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class Dao::ModuleTest < Dao::TestCase 
         
     | 
| 
      
 5 
     | 
    
         
            +
              test 'that dao has a root' do
         
     | 
| 
       4 
6 
     | 
    
         
             
                assert{ Dao.respond_to?(:root) }
         
     | 
| 
       5 
7 
     | 
    
         
             
                assert{ Dao.root }
         
     | 
| 
       6 
8 
     | 
    
         
             
              end
         
     | 
| 
       7 
9 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
      
 10 
     | 
    
         
            +
              test 'that dao can build a mock controller' do
         
     | 
| 
       9 
11 
     | 
    
         
             
                controller = assert{ Dao.mock_controller }
         
     | 
| 
       10 
12 
     | 
    
         
             
                assert{ controller.url_for '/' }
         
     | 
| 
       11 
13 
     | 
    
         
             
              end
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
               
     | 
| 
      
 15 
     | 
    
         
            +
              test 'that dao can mark the current_controller' do
         
     | 
| 
       14 
16 
     | 
    
         
             
                assert{ Dao.current_controller = Dao.mock_controller }
         
     | 
| 
       15 
17 
     | 
    
         
             
              end
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
               
     | 
| 
      
 19 
     | 
    
         
            +
              test 'that dao can pre-process parameters' do
         
     | 
| 
       18 
20 
     | 
    
         
             
                params = Map.new( 
         
     | 
| 
       19 
21 
     | 
    
         
             
                  'dao' => {
         
     | 
| 
       20 
22 
     | 
    
         
             
                    'foos' => {
         
     | 
| 
         @@ -33,6 +35,8 @@ Testing Dao::Conducer do 
     | 
|
| 
       33 
35 
     | 
    
         | 
| 
       34 
36 
     | 
    
         
             
                assert{ Dao.normalize_parameters(params) }
         
     | 
| 
       35 
37 
     | 
    
         | 
| 
      
 38 
     | 
    
         
            +
            #require 'pry'
         
     | 
| 
      
 39 
     | 
    
         
            +
            #binding.pry
         
     | 
| 
       36 
40 
     | 
    
         
             
                assert{ params[:foos].is_a?(Hash) }
         
     | 
| 
       37 
41 
     | 
    
         
             
                assert{ params[:foos][:k] == 'v' }
         
     | 
| 
       38 
42 
     | 
    
         
             
                assert{ params[:foos][:array] == %w( 0 1 ) }
         
     | 
| 
         @@ -43,12 +47,3 @@ Testing Dao::Conducer do 
     | 
|
| 
       43 
47 
     | 
    
         
             
                assert{ params[:bars]['42'] == 'foobar' }
         
     | 
| 
       44 
48 
     | 
    
         
             
              end
         
     | 
| 
       45 
49 
     | 
    
         
             
            end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
            BEGIN {
         
     | 
| 
       49 
     | 
    
         
            -
              testdir = File.dirname(File.expand_path(__FILE__))
         
     | 
| 
       50 
     | 
    
         
            -
              rootdir = File.dirname(testdir)
         
     | 
| 
       51 
     | 
    
         
            -
              libdir = File.join(rootdir, 'lib')
         
     | 
| 
       52 
     | 
    
         
            -
              require File.join(libdir, 'dao')
         
     | 
| 
       53 
     | 
    
         
            -
              require File.join(testdir, 'testing')
         
     | 
| 
       54 
     | 
    
         
            -
            }
         
     | 
    
        data/test/test_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,220 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- encoding : utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            gem "minitest"
         
     | 
| 
      
 3 
     | 
    
         
            +
            #require "minitest/autorun"
         
     | 
| 
      
 4 
     | 
    
         
            +
            #require "minitest/reporters"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            #require 'rake_rerun_reporter'
         
     | 
| 
      
 7 
     | 
    
         
            +
            #reporter_options = { color: true, slow_count: 5, verbose: false, rerun_prefix: "bundle exec" }
         
     | 
| 
      
 8 
     | 
    
         
            +
            #Minitest::Reporters.use! [Minitest::Reporters::RakeRerunReporter.new(reporter_options)]
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            require "dao"
         
     | 
| 
      
 11 
     | 
    
         
            +
            require_relative "util"
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            class Dao::TestCase < ActiveSupport::TestCase
         
     | 
| 
      
 14 
     | 
    
         
            +
              class << self
         
     | 
| 
      
 15 
     | 
    
         
            +
                def context(*args, &block)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  return contexts.last if(args.empty? and block.nil?)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  block.call
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              Missing = Object.new.freeze
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              alias_method('__assert__', 'assert')
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              def missing
         
     | 
| 
      
 27 
     | 
    
         
            +
                Dao::TestCase::Missing
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              def assert(*args, &block)
         
     | 
| 
      
 31 
     | 
    
         
            +
                if args.size == 1 and args.first.is_a?(Hash)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  options = args.first
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expected = getopt(:expected, options){ missing }
         
     | 
| 
      
 34 
     | 
    
         
            +
                  actual = getopt(:actual, options){ missing }
         
     | 
| 
      
 35 
     | 
    
         
            +
                  if expected == missing and actual == missing
         
     | 
| 
      
 36 
     | 
    
         
            +
                    actual, expected, *_ = options.to_a.flatten
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                  expected = expected.call() if expected.respond_to?(:call)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  actual = actual.call() if actual.respond_to?(:call)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  assert_equal(expected, actual)
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                if block
         
     | 
| 
      
 44 
     | 
    
         
            +
                  label = "assert(#{ args.join(' ') })"
         
     | 
| 
      
 45 
     | 
    
         
            +
                  result = nil
         
     | 
| 
      
 46 
     | 
    
         
            +
                  result = block.call
         
     | 
| 
      
 47 
     | 
    
         
            +
                  __assert__(result, label)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  result
         
     | 
| 
      
 49 
     | 
    
         
            +
                else
         
     | 
| 
      
 50 
     | 
    
         
            +
                  result = args.shift
         
     | 
| 
      
 51 
     | 
    
         
            +
                  label = "assert(#{ args.join(' ') })"
         
     | 
| 
      
 52 
     | 
    
         
            +
                  __assert__(result, label)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  result
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              def getopt(opt, hash, options = nil, &block)
         
     | 
| 
      
 58 
     | 
    
         
            +
                [opt.to_s, opt.to_s.to_sym].each do |key|
         
     | 
| 
      
 59 
     | 
    
         
            +
                  return hash[key] if hash.has_key?(key)
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
                default =
         
     | 
| 
      
 62 
     | 
    
         
            +
                  if block
         
     | 
| 
      
 63 
     | 
    
         
            +
                    block.call
         
     | 
| 
      
 64 
     | 
    
         
            +
                  else
         
     | 
| 
      
 65 
     | 
    
         
            +
                    options.is_a?(Hash) ? options[:default] : nil
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
                return default
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            __END__
         
     | 
| 
      
 73 
     | 
    
         
            +
            def Testing(*args, &block)
         
     | 
| 
      
 74 
     | 
    
         
            +
              Class.new(::MiniTest::Test) do
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                ## class methods
         
     | 
| 
      
 77 
     | 
    
         
            +
                #
         
     | 
| 
      
 78 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 79 
     | 
    
         
            +
                  def contexts
         
     | 
| 
      
 80 
     | 
    
         
            +
                    @contexts ||= []
         
     | 
| 
      
 81 
     | 
    
         
            +
                  end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                  def context(*args, &block)
         
     | 
| 
      
 84 
     | 
    
         
            +
                    return contexts.last if(args.empty? and block.nil?)
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                    context = Testing::Context.new(*args)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    contexts.push(context)
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 90 
     | 
    
         
            +
                      block.call(context)
         
     | 
| 
      
 91 
     | 
    
         
            +
                    ensure
         
     | 
| 
      
 92 
     | 
    
         
            +
                      contexts.pop
         
     | 
| 
      
 93 
     | 
    
         
            +
                    end
         
     | 
| 
      
 94 
     | 
    
         
            +
                  end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  def slug_for(*args)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    string = [context, args].flatten.compact.join('-')
         
     | 
| 
      
 98 
     | 
    
         
            +
                    words = string.to_s.scan(%r/\w+/)
         
     | 
| 
      
 99 
     | 
    
         
            +
                    words.map!{|word| word.gsub %r/[^0-9a-zA-Z_-]/, ''}
         
     | 
| 
      
 100 
     | 
    
         
            +
                    words.delete_if{|word| word.nil? or word.strip.empty?}
         
     | 
| 
      
 101 
     | 
    
         
            +
                    words.join('-').downcase.sub(/_$/, '')
         
     | 
| 
      
 102 
     | 
    
         
            +
                  end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  def name() const_get(:Name) end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                  def testno()
         
     | 
| 
      
 107 
     | 
    
         
            +
                    '%05d' % (@testno ||= 0)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 109 
     | 
    
         
            +
                    @testno += 1
         
     | 
| 
      
 110 
     | 
    
         
            +
                  end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                  def testing(*args, &block)
         
     | 
| 
      
 113 
     | 
    
         
            +
                    method = ["test", testno, slug_for(*args)].delete_if{|part| part.empty?}.join('_')
         
     | 
| 
      
 114 
     | 
    
         
            +
                    define_method(method, &block)
         
     | 
| 
      
 115 
     | 
    
         
            +
                  end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                  def test(*args, &block)
         
     | 
| 
      
 118 
     | 
    
         
            +
                    testing(*args, &block)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                  def setup(&block)
         
     | 
| 
      
 122 
     | 
    
         
            +
                    define_method(:setup, &block) if block
         
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                  def teardown(&block)
         
     | 
| 
      
 126 
     | 
    
         
            +
                    define_method(:teardown, &block) if block
         
     | 
| 
      
 127 
     | 
    
         
            +
                  end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                  def prepare(&block)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    @prepare ||= []
         
     | 
| 
      
 131 
     | 
    
         
            +
                    @prepare.push(block) if block
         
     | 
| 
      
 132 
     | 
    
         
            +
                    @prepare
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                  def cleanup(&block)
         
     | 
| 
      
 136 
     | 
    
         
            +
                    @cleanup ||= []
         
     | 
| 
      
 137 
     | 
    
         
            +
                    @cleanup.push(block) if block
         
     | 
| 
      
 138 
     | 
    
         
            +
                    @cleanup
         
     | 
| 
      
 139 
     | 
    
         
            +
                  end
         
     | 
| 
      
 140 
     | 
    
         
            +
                end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                ## configure the subclass!
         
     | 
| 
      
 143 
     | 
    
         
            +
                #
         
     | 
| 
      
 144 
     | 
    
         
            +
                const_set(:Testno, '0')
         
     | 
| 
      
 145 
     | 
    
         
            +
                slug = slug_for(*args).gsub(%r/-/,'_')
         
     | 
| 
      
 146 
     | 
    
         
            +
                name = ['TESTING', '%03d' % const_get(:Testno), slug].delete_if{|part| part.empty?}.join('_')
         
     | 
| 
      
 147 
     | 
    
         
            +
                name = name.upcase!
         
     | 
| 
      
 148 
     | 
    
         
            +
                const_set(:Name, name)
         
     | 
| 
      
 149 
     | 
    
         
            +
                const_set(:Missing, Object.new.freeze)
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                ## instance methods
         
     | 
| 
      
 152 
     | 
    
         
            +
                #
         
     | 
| 
      
 153 
     | 
    
         
            +
                alias_method('__assert__', 'assert')
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                def assert(*args, &block)
         
     | 
| 
      
 156 
     | 
    
         
            +
                  if args.size == 1 and args.first.is_a?(Hash)
         
     | 
| 
      
 157 
     | 
    
         
            +
                    options = args.first
         
     | 
| 
      
 158 
     | 
    
         
            +
                    expected = getopt(:expected, options){ missing }
         
     | 
| 
      
 159 
     | 
    
         
            +
                    actual = getopt(:actual, options){ missing }
         
     | 
| 
      
 160 
     | 
    
         
            +
                    if expected == missing and actual == missing
         
     | 
| 
      
 161 
     | 
    
         
            +
                      actual, expected, *_ = options.to_a.flatten
         
     | 
| 
      
 162 
     | 
    
         
            +
                    end
         
     | 
| 
      
 163 
     | 
    
         
            +
                    expected = expected.call() if expected.respond_to?(:call)
         
     | 
| 
      
 164 
     | 
    
         
            +
                    actual = actual.call() if actual.respond_to?(:call)
         
     | 
| 
      
 165 
     | 
    
         
            +
                    assert_equal(expected, actual)
         
     | 
| 
      
 166 
     | 
    
         
            +
                  end
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                  if block
         
     | 
| 
      
 169 
     | 
    
         
            +
                    label = "assert(#{ args.join(' ') })"
         
     | 
| 
      
 170 
     | 
    
         
            +
                    result = nil
         
     | 
| 
      
 171 
     | 
    
         
            +
                    result = block.call
         
     | 
| 
      
 172 
     | 
    
         
            +
                    __assert__(result, label)
         
     | 
| 
      
 173 
     | 
    
         
            +
                    result
         
     | 
| 
      
 174 
     | 
    
         
            +
                  else
         
     | 
| 
      
 175 
     | 
    
         
            +
                    result = args.shift
         
     | 
| 
      
 176 
     | 
    
         
            +
                    label = "assert(#{ args.join(' ') })"
         
     | 
| 
      
 177 
     | 
    
         
            +
                    __assert__(result, label)
         
     | 
| 
      
 178 
     | 
    
         
            +
                    result
         
     | 
| 
      
 179 
     | 
    
         
            +
                  end
         
     | 
| 
      
 180 
     | 
    
         
            +
                end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                def missing
         
     | 
| 
      
 183 
     | 
    
         
            +
                  self.class.const_get(:Missing)
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                def getopt(opt, hash, options = nil, &block)
         
     | 
| 
      
 187 
     | 
    
         
            +
                  [opt.to_s, opt.to_s.to_sym].each do |key|
         
     | 
| 
      
 188 
     | 
    
         
            +
                    return hash[key] if hash.has_key?(key)
         
     | 
| 
      
 189 
     | 
    
         
            +
                  end
         
     | 
| 
      
 190 
     | 
    
         
            +
                  default =
         
     | 
| 
      
 191 
     | 
    
         
            +
                    if block
         
     | 
| 
      
 192 
     | 
    
         
            +
                      block.call
         
     | 
| 
      
 193 
     | 
    
         
            +
                    else
         
     | 
| 
      
 194 
     | 
    
         
            +
                      options.is_a?(Hash) ? options[:default] : nil
         
     | 
| 
      
 195 
     | 
    
         
            +
                    end
         
     | 
| 
      
 196 
     | 
    
         
            +
                  return default
         
     | 
| 
      
 197 
     | 
    
         
            +
                end
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
                def subclass_of exception
         
     | 
| 
      
 200 
     | 
    
         
            +
                  class << exception
         
     | 
| 
      
 201 
     | 
    
         
            +
                    def ==(other) super or self > other end
         
     | 
| 
      
 202 
     | 
    
         
            +
                  end
         
     | 
| 
      
 203 
     | 
    
         
            +
                  exception
         
     | 
| 
      
 204 
     | 
    
         
            +
                end
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                ##
         
     | 
| 
      
 207 
     | 
    
         
            +
                #
         
     | 
| 
      
 208 
     | 
    
         
            +
                module_eval(&block)
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
                self.setup()
         
     | 
| 
      
 211 
     | 
    
         
            +
                self.prepare.each{|b| b.call()}
         
     | 
| 
      
 212 
     | 
    
         
            +
             
     | 
| 
      
 213 
     | 
    
         
            +
                at_exit{ 
         
     | 
| 
      
 214 
     | 
    
         
            +
                  self.teardown()
         
     | 
| 
      
 215 
     | 
    
         
            +
                  self.cleanup.each{|b| b.call()}
         
     | 
| 
      
 216 
     | 
    
         
            +
                }
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                self
         
     | 
| 
      
 219 
     | 
    
         
            +
              end
         
     | 
| 
      
 220 
     | 
    
         
            +
            end
         
     |