assert 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -2
- data/lib/assert.rb +1 -8
- data/lib/assert/context.rb +18 -10
- data/lib/assert/runner.rb +9 -2
- data/lib/assert/setup.rb +1 -4
- data/lib/assert/setup/all.rb +5 -0
- data/lib/assert/setup/helpers.rb +13 -7
- data/lib/assert/setup/options.rb +6 -0
- data/lib/assert/setup/view.rb +23 -2
- data/lib/assert/version.rb +1 -1
- data/test/context/class_methods_test.rb +58 -4
- data/test/default_view_test.rb +44 -0
- data/test/runner_test.rb +1 -1
- metadata +8 -4
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
assert (0.
|
4
|
+
assert (0.5.0)
|
5
5
|
ansi (~> 1.3)
|
6
6
|
assert-view
|
7
7
|
|
@@ -9,8 +9,10 @@ GEM
|
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ansi (1.3.0)
|
12
|
-
assert-view (0.
|
12
|
+
assert-view (0.2.0)
|
13
|
+
undies (~> 1.1)
|
13
14
|
rake (0.9.2)
|
15
|
+
undies (1.1.0)
|
14
16
|
|
15
17
|
PLATFORMS
|
16
18
|
ruby
|
data/lib/assert.rb
CHANGED
data/lib/assert/context.rb
CHANGED
@@ -33,24 +33,32 @@ module Assert
|
|
33
33
|
alias_method :after_once, :teardown_once
|
34
34
|
|
35
35
|
# Add a setup block to run before each test or run the list of teardown blocks in given scope
|
36
|
-
def setup(
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def setup(scope_or_method_name = nil, &block)
|
37
|
+
is_method = scope_or_method_name.kind_of?(String) || scope_or_method_name.kind_of?(Symbol)
|
38
|
+
if block_given? || is_method
|
39
|
+
self.setups << (block || scope_or_method_name)
|
40
|
+
elsif !is_method
|
41
|
+
scope = scope_or_method_name
|
40
42
|
# setup parent before child
|
41
43
|
self.superclass.setup(scope) if self.superclass.respond_to?(:setup)
|
42
|
-
self.setups.each
|
44
|
+
self.setups.each do |setup|
|
45
|
+
setup.kind_of?(::Proc) ? scope.instance_eval(&setup) : scope.send(setup)
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
alias_method :before, :setup
|
46
50
|
|
47
51
|
# Add a teardown block to run after each test or run the list of teardown blocks in given scope
|
48
|
-
def teardown(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
def teardown(scope_or_method_name = nil, &block)
|
53
|
+
is_method = scope_or_method_name.kind_of?(String) || scope_or_method_name.kind_of?(Symbol)
|
54
|
+
if block_given? || is_method
|
55
|
+
self.teardowns << (block || scope_or_method_name)
|
56
|
+
elsif !is_method
|
57
|
+
scope = scope_or_method_name
|
52
58
|
# teardown child before parent
|
53
|
-
self.teardowns.each
|
59
|
+
self.teardowns.each do |teardown|
|
60
|
+
teardown.kind_of?(::Proc) ? scope.instance_eval(&teardown) : scope.send(teardown)
|
61
|
+
end
|
54
62
|
self.superclass.teardown(scope) if self.superclass.respond_to?(:teardown)
|
55
63
|
end
|
56
64
|
end
|
data/lib/assert/runner.rb
CHANGED
@@ -9,11 +9,18 @@ module Assert
|
|
9
9
|
@view = view
|
10
10
|
end
|
11
11
|
|
12
|
-
def run(
|
12
|
+
def run(render=true)
|
13
13
|
@suite.setup
|
14
|
-
|
14
|
+
|
15
|
+
if render
|
16
|
+
# render the view, passing it a callback block to run the test suite
|
17
|
+
@view.render do
|
18
|
+
benchmark { run_suite }
|
19
|
+
end
|
20
|
+
else
|
15
21
|
benchmark { run_suite }
|
16
22
|
end
|
23
|
+
|
17
24
|
@suite.teardown
|
18
25
|
count(:failed) + count(:errored)
|
19
26
|
end
|
data/lib/assert/setup.rb
CHANGED
data/lib/assert/setup/helpers.rb
CHANGED
@@ -10,12 +10,18 @@ module Assert
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
|
13
|
-
# assume the test dir path is ./test and look for helpers in ./test/helper.rb
|
14
|
-
PACKAGE_TEST_DIR = "test"
|
15
|
-
PACKAGE_HELPER_FILE = "helper"
|
16
|
-
TEST_REGEX = /^#{PACKAGE_TEST_DIR}$|^#{PACKAGE_TEST_DIR}\/|\/#{PACKAGE_TEST_DIR}\/|\/#{PACKAGE_TEST_DIR}$/
|
17
|
-
|
18
13
|
USER_TEST_HELPER = "~/.assert/options"
|
14
|
+
|
15
|
+
# assume the test dir path is ./test and look for helpers in ./test/helper.rb
|
16
|
+
def package_test_dir
|
17
|
+
"test"
|
18
|
+
end
|
19
|
+
def package_helper_name
|
20
|
+
"helper"
|
21
|
+
end
|
22
|
+
def package_test_helper_regex
|
23
|
+
/^#{package_test_dir}$|^#{package_test_dir}\/|\/#{package_test_dir}\/|\/#{package_test_dir}$/
|
24
|
+
end
|
19
25
|
|
20
26
|
def load(caller_info)
|
21
27
|
if (crp = caller_root_path(caller_info))
|
@@ -44,7 +50,7 @@ module Assert
|
|
44
50
|
end
|
45
51
|
|
46
52
|
def package_helper_file(root_path)
|
47
|
-
File.join(root_path,
|
53
|
+
File.join(root_path, package_test_dir, package_helper_name + '.rb')
|
48
54
|
end
|
49
55
|
|
50
56
|
# this method inspects the caller info and finds the caller's root path
|
@@ -52,7 +58,7 @@ module Assert
|
|
52
58
|
# parent dir of caller named TEST_DIR
|
53
59
|
def caller_root_path(caller_info)
|
54
60
|
caller_dirname = File.expand_path(File.dirname(caller_info[0]))
|
55
|
-
test_dir_pos = caller_dirname.index(
|
61
|
+
test_dir_pos = caller_dirname.index(package_test_helper_regex)
|
56
62
|
if test_dir_pos && (test_dir_pos > 0)
|
57
63
|
caller_dirname[0..(test_dir_pos-1)]
|
58
64
|
end
|
data/lib/assert/setup/view.rb
CHANGED
@@ -1,11 +1,32 @@
|
|
1
1
|
require 'assert/view/terminal'
|
2
|
+
require 'assert/view/helpers/ansi'
|
2
3
|
|
3
4
|
module Assert
|
4
|
-
|
5
|
+
|
6
|
+
# define an Assert::View:Terminal view that renders ansi output using the
|
7
|
+
# 'assert.ansi' template and setting up some styling defaults
|
8
|
+
class AnsiTerminal < View::Terminal
|
9
|
+
|
10
|
+
helper View::Helpers::AnsiStyles
|
11
|
+
options do
|
12
|
+
default_template 'assert.ansi'
|
13
|
+
default_styled false
|
14
|
+
default_passed_styles :green
|
15
|
+
default_failed_styles :red, :bold
|
16
|
+
default_errored_styles :yellow, :bold
|
17
|
+
default_skipped_styles :cyan
|
18
|
+
default_ignored_styles :magenta
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# Setup the above view, rendering on $stdout, as the default view for assert
|
24
|
+
# (override in user or package helpers)
|
5
25
|
options do
|
6
|
-
default_view
|
26
|
+
default_view AnsiTerminal.new($stdout)
|
7
27
|
end
|
8
28
|
|
29
|
+
# setup the global Assert.view method
|
9
30
|
class << self
|
10
31
|
def view; self.options.view; end
|
11
32
|
end
|
data/lib/assert/version.rb
CHANGED
@@ -85,10 +85,36 @@ class Assert::Context
|
|
85
85
|
|
86
86
|
|
87
87
|
|
88
|
+
class SetupWithMethodNameTest < ClassMethodsTest
|
89
|
+
desc "setup with method name"
|
90
|
+
setup do
|
91
|
+
method_name = @method_name = :setup_something_amazing
|
92
|
+
@context_class = Factory.context_class do
|
93
|
+
setup(method_name)
|
94
|
+
end
|
95
|
+
@setups = @context_class.send(:setups)
|
96
|
+
end
|
97
|
+
subject{ @setups }
|
98
|
+
|
99
|
+
should "add the method name to the context setups" do
|
100
|
+
assert_includes @method_name, subject
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
88
106
|
class MultipleSetupsTest < ClassMethodsTest
|
89
107
|
desc "a context class with multiple setups"
|
90
108
|
setup do
|
91
|
-
|
109
|
+
method_name = :setup_something_amazing
|
110
|
+
klass = Class.new do
|
111
|
+
attr_accessor :status
|
112
|
+
|
113
|
+
define_method(method_name) do
|
114
|
+
self.status += " with something amazing"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@object = klass.new
|
92
118
|
setup_block = @setup_block = ::Proc.new{ self.status = "the setup" }
|
93
119
|
@parent_class = Factory.context_class do
|
94
120
|
setup(&setup_block)
|
@@ -96,9 +122,10 @@ class Assert::Context
|
|
96
122
|
setup_block = @setup_block = ::Proc.new{ self.status += " has been run" }
|
97
123
|
@context_class = Factory.context_class(@parent_class) do
|
98
124
|
setup(&setup_block)
|
125
|
+
setup(method_name)
|
99
126
|
end
|
100
127
|
@context_class.setup(@object)
|
101
|
-
@expected = "the setup has been run"
|
128
|
+
@expected = "the setup has been run with something amazing"
|
102
129
|
end
|
103
130
|
subject{ @object }
|
104
131
|
|
@@ -129,20 +156,47 @@ class Assert::Context
|
|
129
156
|
|
130
157
|
|
131
158
|
|
159
|
+
class TeardownWithMethodNameTest < ClassMethodsTest
|
160
|
+
desc "teardown with method name"
|
161
|
+
setup do
|
162
|
+
method_name = @method_name = "teardown_something_amazing"
|
163
|
+
@context_class = Factory.context_class do
|
164
|
+
teardown(method_name)
|
165
|
+
end
|
166
|
+
@teardowns = @context_class.send(:teardowns)
|
167
|
+
end
|
168
|
+
subject{ @teardowns }
|
169
|
+
|
170
|
+
should "add the method name to the context teardowns" do
|
171
|
+
assert_includes @method_name, subject
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
132
177
|
class MultipleTeardownsTest < ClassMethodsTest
|
133
178
|
desc "a context class with multiple teardowns"
|
134
179
|
setup do
|
135
|
-
|
180
|
+
method_name = :teardown_something_amazing
|
181
|
+
klass = Class.new do
|
182
|
+
attr_accessor :status
|
183
|
+
|
184
|
+
define_method(method_name) do
|
185
|
+
self.status += " with something amazing"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
@object = klass.new
|
136
189
|
teardown_block = @teardown_block = ::Proc.new{ self.status += " has been run" }
|
137
190
|
@parent_class = Factory.context_class do
|
138
191
|
teardown(&teardown_block)
|
192
|
+
teardown(method_name)
|
139
193
|
end
|
140
194
|
teardown_block = @teardown_block = ::Proc.new{ self.status = "the teardown" }
|
141
195
|
@context_class = Factory.context_class(@parent_class) do
|
142
196
|
teardown(&teardown_block)
|
143
197
|
end
|
144
198
|
@context_class.teardown(@object)
|
145
|
-
@expected = "the teardown has been run"
|
199
|
+
@expected = "the teardown has been run with something amazing"
|
146
200
|
end
|
147
201
|
subject{ @object }
|
148
202
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'assert/setup/view'
|
3
|
+
|
4
|
+
module Assert
|
5
|
+
|
6
|
+
class DefaultViewTests < Assert::Context
|
7
|
+
desc "assert's default view"
|
8
|
+
subject { Assert.options.default_view }
|
9
|
+
|
10
|
+
should "be the AnsiTerminal" do
|
11
|
+
assert_kind_of AnsiTerminal, subject
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class OptionsTests < DefaultViewTests
|
17
|
+
desc "options"
|
18
|
+
subject do
|
19
|
+
Assert.options.default_view.options
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be an Options::Base object" do
|
23
|
+
assert_kind_of Assert::Options::Base, subject
|
24
|
+
end
|
25
|
+
|
26
|
+
should "default the template" do
|
27
|
+
assert_equal 'assert.ansi', subject.default_template
|
28
|
+
end
|
29
|
+
|
30
|
+
should "default the styled option" do
|
31
|
+
assert_equal false, subject.default_styled
|
32
|
+
end
|
33
|
+
|
34
|
+
should "default its result styles" do
|
35
|
+
assert_equal :green, subject.default_passed_styles
|
36
|
+
assert_equal [:red, :bold], subject.default_failed_styles
|
37
|
+
assert_equal :magenta, subject.default_ignored_styles
|
38
|
+
assert_equal :cyan, subject.default_skipped_styles
|
39
|
+
assert_equal [:yellow, :bold], subject.default_errored_styles
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/runner_test.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-08
|
19
|
+
date: 2011-09-08 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
type: :development
|
@@ -90,7 +90,9 @@ files:
|
|
90
90
|
- lib/assert/result_set.rb
|
91
91
|
- lib/assert/runner.rb
|
92
92
|
- lib/assert/setup.rb
|
93
|
+
- lib/assert/setup/all.rb
|
93
94
|
- lib/assert/setup/helpers.rb
|
95
|
+
- lib/assert/setup/options.rb
|
94
96
|
- lib/assert/setup/runner.rb
|
95
97
|
- lib/assert/setup/suite.rb
|
96
98
|
- lib/assert/setup/view.rb
|
@@ -123,6 +125,7 @@ files:
|
|
123
125
|
- test/assertions_test.rb
|
124
126
|
- test/context/class_methods_test.rb
|
125
127
|
- test/context_test.rb
|
128
|
+
- test/default_view_test.rb
|
126
129
|
- test/fixtures/inherited_stuff.rb
|
127
130
|
- test/fixtures/sample_context.rb
|
128
131
|
- test/helper.rb
|
@@ -195,6 +198,7 @@ test_files:
|
|
195
198
|
- test/assertions_test.rb
|
196
199
|
- test/context/class_methods_test.rb
|
197
200
|
- test/context_test.rb
|
201
|
+
- test/default_view_test.rb
|
198
202
|
- test/fixtures/inherited_stuff.rb
|
199
203
|
- test/fixtures/sample_context.rb
|
200
204
|
- test/helper.rb
|