Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
f8bdc10c
Commit
f8bdc10c
authored
Feb 21, 2013
by
Akira Yumiyama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add assert_{includes,instance_of,kind_of,raises} methods.
parent
59cf4bca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
test/assert.rb
test/assert.rb
+43
-0
No files found.
test/assert.rb
View file @
f8bdc10c
...
...
@@ -79,6 +79,49 @@ def assert_nil(obj, msg = nil)
assert_true
(
obj
.
nil?
,
msg
,
diff
)
end
def
assert_includes
(
collection
,
obj
,
msg
=
nil
)
msg
=
"Expected
#{
collection
.
inspect
}
to include
#{
obj
.
inspect
}
"
unless
msg
diff
=
" Collection:
#{
collection
.
inspect
}
\n
"
+
" Object:
#{
obj
.
inspect
}
"
assert_true
(
collection
.
include?
(
obj
),
msg
,
diff
)
end
def
assert_instance_of
(
klass
,
obj
,
msg
=
nil
)
msg
=
"Expected
#{
obj
.
inspect
}
to be an instance of
#{
klass
}
, not
#{
obj
.
class
}
"
unless
msg
assert_true
(
obj
.
instance_of?
(
klass
),
msg
)
end
def
assert_kind_of
(
klass
,
obj
,
msg
=
nil
)
msg
=
"Expected
#{
obj
.
inspect
}
to be an kind of
#{
klass
}
, not
#{
obj
.
class
}
"
unless
msg
assert_true
(
obj
.
kind_of?
(
klass
),
msg
)
end
def
assert_raises
(
*
exp
)
if
$mrbtest_assert
$mrbtest_assert_idx
+=
1
msg
=
exp
.
last
.
class
==
String
?
exp
.
pop
:
nil
msg
=
msg
.
to_s
+
" : "
if
msg
should_raise
=
false
begin
yield
should_raise
=
true
rescue
Exception
=>
e
msg
=
"
#{
msg
}#{
exp
.
inspect
}
exception expected, not"
diff
=
" Class: <
#{
e
.
class
}
>
\n
"
+
" Message:
#{
e
.
message
}
"
if
exp
.
any?
{
|
ex
|
ex
.
instance_of?
(
Module
)
?
e
.
kind_of?
(
ex
)
:
ex
==
e
.
class
}
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
diff
])
end
end
exp
=
exp
.
first
if
exp
.
first
if
should_raise
msg
=
"
#{
msg
}#{
exp
.
inspect
}
expected but nothing was raised."
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
nil
])
end
end
end
##
# Report the test result and print all assertions
# which were reported broken.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment