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
79b4f61b
Commit
79b4f61b
authored
Aug 30, 2017
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Aug 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3799 from christopheraue/assert_raise_refactoring
Refactored #assert_raise and #assert_nothing_raised
parents
8976f47e
4b0b8f7e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
43 deletions
+32
-43
test/assert.rb
test/assert.rb
+30
-41
test/t/module.rb
test/t/module.rb
+2
-2
No files found.
test/assert.rb
View file @
79b4f61b
...
...
@@ -143,52 +143,41 @@ def assert_not_include(collection, obj, msg = nil)
assert_false
(
collection
.
include?
(
obj
),
msg
,
diff
)
end
def
assert_raise
(
*
exp
)
ret
=
true
if
$mrbtest_assert
def
assert_raise
(
exc
,
msg
=
nil
)
return
true
unless
$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
msg
||=
"Expected to raise
#{
exc
}
but nothing was raised."
diff
=
nil
$mrbtest_assert
.
push
[
$mrbtest_assert_idx
,
msg
,
diff
]
false
rescue
exc
true
rescue
Exception
=>
e
msg
=
"
#{
msg
}#{
exp
.
inspect
}
exception expected
, not"
msg
||=
"Expected to raise
#{
exc
}
, not"
diff
=
" Class: <
#{
e
.
class
}
>
\n
"
+
" Message:
#{
e
.
message
}
"
unless
exp
.
any?
{
|
ex
|
ex
.
instance_of?
(
Module
)
?
e
.
kind_of?
(
ex
)
:
ex
==
e
.
class
}
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
diff
])
ret
=
false
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
])
ret
=
false
end
$mrbtest_assert
.
push
[
$mrbtest_assert_idx
,
msg
,
diff
]
false
end
ret
end
def
assert_nothing_raised
(
*
exp
)
ret
=
true
if
$mrbtest_assert
def
assert_nothing_raised
(
msg
=
nil
)
return
true
unless
$mrbtest_assert
$mrbtest_assert_idx
+=
1
msg
=
exp
.
last
.
class
==
String
?
exp
.
pop
:
""
begin
yield
true
rescue
Exception
=>
e
msg
=
"
#{
msg
}
exception raised.
"
msg
||=
"Expected not to raise
#{
exc
.
join
(
', '
)
}
but it raised
"
diff
=
" Class: <
#{
e
.
class
}
>
\n
"
+
" Message:
#{
e
.
message
}
"
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
diff
])
ret
=
false
end
$mrbtest_assert
.
push
[
$mrbtest_assert_idx
,
msg
,
diff
]
false
end
ret
end
##
...
...
test/t/module.rb
View file @
79b4f61b
...
...
@@ -635,7 +635,7 @@ end
c
.
singleton_class
.
class_eval
do
define_method
(
:method_removed
)
{
|
id
|
removed
=
id
}
end
assert_nothing_raised
(
NoMethodError
,
NameError
,
'[Bug #7843]'
)
do
assert_nothing_raised
(
'[Bug #7843]'
)
do
c
.
class_eval
do
remove_method
(
:foo
)
end
...
...
@@ -724,7 +724,7 @@ end
end
a
=
c
.
new
assert_true
a
.
respond_to?
(
:foo
),
bug8005
assert_nothing_raised
(
NoMethodError
,
bug8005
)
{
a
.
send
:foo
}
assert_nothing_raised
(
bug8005
)
{
a
.
send
:foo
}
end
# mruby has no visibility control
...
...
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