dao 5.6.1 → 7.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.
@@ -1,7 +1,22 @@
1
1
  # -*- encoding : utf-8 -*-
2
- Testing Dao::Errors do
2
+ require_relative 'test_helper'
3
+ class DaoErrorsTest < Dao::TestCase
3
4
 
4
- testing 'that conducer-less error objects scopes keys in a generic fashion' do
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
- testing 'that conducer-based error objects scope keys in a model_name based fashion' do
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
  ---
@@ -46,7 +61,7 @@ Testing Dao::Errors do
46
61
  end
47
62
 
48
63
  =begin
49
- testing 'that `nested` errors `nest`' do
64
+ test 'that `nested` errors `nest`' do
50
65
  e = Dao::Errors.new
51
66
 
52
67
  e.relay 'foo.bar' => 'is fucked'
@@ -80,12 +95,3 @@ protected
80
95
  end
81
96
  alias_method :new_conducer, :new_foo_conducer
82
97
  end
83
-
84
- BEGIN {
85
- testdir = File.dirname(File.expand_path(__FILE__))
86
- rootdir = File.dirname(testdir)
87
- libdir = File.join(rootdir, 'lib')
88
- require File.join(libdir, 'dao')
89
- require File.join(testdir, 'testing')
90
- require 'stringio'
91
- }
@@ -1,25 +1,26 @@
1
1
  # -*- encoding : utf-8 -*-
2
- Testing Dao::Form do
3
- testing '.new' do
2
+ require_relative 'test_helper'
3
+ class DaoFormTest < ::Dao::TestCase
4
+ test '.new' do
4
5
  form = new_form()
5
6
  form = new_named_form()
6
7
  end
7
8
 
8
- testing 'name_for' do
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
- testing 'scope_for' do
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="form_bar"/>'
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="form_foo-bar"/>'
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="form_bar"/>'
41
+ '<input type="text" name="dao[form][bar]" class="dao" id="form--bar"/>'
41
42
  )
42
43
  end
43
44
  end
44
45
 
45
- testing 'Form#select' do
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="form_key"> </select>'
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="form_key"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
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="form_key"><option value="1">A</option><option value="2">B</option><option value="3">C</option></select>'
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="form_key"><option></option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
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="form_key"><option></option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
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="form_key"><option value="">42</option><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
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="form_key"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select>'
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="form_key"><option value="a">a</option><option value="b" selected>b</option><option value="c">c</option></select>'
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="form_key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
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="form_key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
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="form_key"><option value="41">41</option><option value="42" selected>42</option><option value="43">43</option></select>'
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
+
@@ -1,20 +1,22 @@
1
1
  # -*- encoding : utf-8 -*-
2
- Testing Dao::Conducer do
3
- testing 'that dao has a root' do
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
- testing 'that dao can build a mock controller' do
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
- testing 'that dao can mark the current_controller' do
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
- testing 'that dao can pre-process parameters' do
19
+ test 'that dao can pre-process parameters' do
18
20
  params = Map.new(
19
21
  'dao' => {
20
22
  'foos' => {
@@ -45,12 +47,3 @@ Testing Dao::Conducer do
45
47
  assert{ params[:bars]['42'] == 'foobar' }
46
48
  end
47
49
  end
48
-
49
-
50
- BEGIN {
51
- testdir = File.dirname(File.expand_path(__FILE__))
52
- rootdir = File.dirname(testdir)
53
- libdir = File.join(rootdir, 'lib')
54
- require File.join(libdir, 'dao')
55
- require File.join(testdir, 'testing')
56
- }
@@ -1,45 +1,80 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require 'test/unit'
3
-
4
- testdir = File.expand_path(File.dirname(__FILE__))
5
- rootdir = File.dirname(testdir)
6
- libdir = File.join(rootdir, 'lib')
7
-
8
- STDOUT.sync = true
9
-
10
- $:.unshift(testdir) unless $:.include?(testdir)
11
- $:.unshift(libdir) unless $:.include?(libdir)
12
- $:.unshift(rootdir) unless $:.include?(rootdir)
13
-
14
- class Testing
15
- class Slug < ::String
16
- def Slug.for(*args)
17
- string = args.flatten.compact.join('-')
18
- words = string.to_s.scan(%r/\w+/)
19
- words.map!{|word| word.gsub %r/[^0-9a-zA-Z_-]/, ''}
20
- words.delete_if{|word| word.nil? or word.strip.empty?}
21
- new(words.join('-').downcase)
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
22
18
  end
23
19
  end
24
-
25
- class Context
26
- attr_accessor :name
27
20
 
28
- def initialize(name, *args)
29
- @name = name
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)
30
41
  end
31
42
 
32
- def to_s
33
- Slug.for(name)
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
34
54
  end
35
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
+
36
70
  end
37
71
 
72
+ __END__
38
73
  def Testing(*args, &block)
39
- Class.new(::Test::Unit::TestCase) do
74
+ Class.new(::MiniTest::Test) do
40
75
 
41
- ## class methods
42
- #
76
+ ## class methods
77
+ #
43
78
  class << self
44
79
  def contexts
45
80
  @contexts ||= []
@@ -104,8 +139,8 @@ def Testing(*args, &block)
104
139
  end
105
140
  end
106
141
 
107
- ## configure the subclass!
108
- #
142
+ ## configure the subclass!
143
+ #
109
144
  const_set(:Testno, '0')
110
145
  slug = slug_for(*args).gsub(%r/-/,'_')
111
146
  name = ['TESTING', '%03d' % const_get(:Testno), slug].delete_if{|part| part.empty?}.join('_')
@@ -113,8 +148,8 @@ def Testing(*args, &block)
113
148
  const_set(:Name, name)
114
149
  const_set(:Missing, Object.new.freeze)
115
150
 
116
- ## instance methods
117
- #
151
+ ## instance methods
152
+ #
118
153
  alias_method('__assert__', 'assert')
119
154
 
120
155
  def assert(*args, &block)
@@ -123,7 +158,7 @@ def Testing(*args, &block)
123
158
  expected = getopt(:expected, options){ missing }
124
159
  actual = getopt(:actual, options){ missing }
125
160
  if expected == missing and actual == missing
126
- actual, expected, *ignored = options.to_a.flatten
161
+ actual, expected, *_ = options.to_a.flatten
127
162
  end
128
163
  expected = expected.call() if expected.respond_to?(:call)
129
164
  actual = actual.call() if actual.respond_to?(:call)
@@ -133,7 +168,7 @@ def Testing(*args, &block)
133
168
  if block
134
169
  label = "assert(#{ args.join(' ') })"
135
170
  result = nil
136
- assert_nothing_raised{ result = block.call }
171
+ result = block.call
137
172
  __assert__(result, label)
138
173
  result
139
174
  else
@@ -168,8 +203,8 @@ def Testing(*args, &block)
168
203
  exception
169
204
  end
170
205
 
171
- ##
172
- #
206
+ ##
207
+ #
173
208
  module_eval(&block)
174
209
 
175
210
  self.setup()
@@ -183,14 +218,3 @@ def Testing(*args, &block)
183
218
  self
184
219
  end
185
220
  end
186
-
187
-
188
- if $0 == __FILE__
189
-
190
- Testing 'Testing' do
191
- testing('foo'){ assert true }
192
- test{ assert true }
193
- p instance_methods.grep(/test/)
194
- end
195
-
196
- end