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
Hide 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)
...
@@ -143,52 +143,41 @@ def assert_not_include(collection, obj, msg = nil)
assert_false
(
collection
.
include?
(
obj
),
msg
,
diff
)
assert_false
(
collection
.
include?
(
obj
),
msg
,
diff
)
end
end
def
assert_raise
(
*
exp
)
def
assert_raise
(
exc
,
msg
=
nil
)
ret
=
true
return
true
unless
$mrbtest_assert
if
$mrbtest_assert
$mrbtest_assert_idx
+=
1
$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
}
"
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
begin
if
should_raise
yield
msg
=
"
#{
msg
}#{
exp
.
inspect
}
expected but nothing was raised."
msg
||=
"Expected to raise
#{
exc
}
but nothing was raised."
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
nil
])
diff
=
nil
ret
=
false
$mrbtest_assert
.
push
[
$mrbtest_assert_idx
,
msg
,
diff
]
end
false
rescue
exc
true
rescue
Exception
=>
e
msg
||=
"Expected to raise
#{
exc
}
, not"
diff
=
" Class: <
#{
e
.
class
}
>
\n
"
+
" Message:
#{
e
.
message
}
"
$mrbtest_assert
.
push
[
$mrbtest_assert_idx
,
msg
,
diff
]
false
end
end
ret
end
end
def
assert_nothing_raised
(
*
exp
)
def
assert_nothing_raised
(
msg
=
nil
)
ret
=
true
return
true
unless
$mrbtest_assert
if
$mrbtest_assert
$mrbtest_assert_idx
+=
1
$mrbtest_assert_idx
+=
1
msg
=
exp
.
last
.
class
==
String
?
exp
.
pop
:
""
begin
begin
yield
yield
true
rescue
Exception
=>
e
rescue
Exception
=>
e
msg
=
"
#{
msg
}
exception raised."
msg
||=
"Expected not to raise
#{
exc
.
join
(
', '
)
}
but it raised"
diff
=
" Class: <
#{
e
.
class
}
>
\n
"
+
diff
=
" Class: <
#{
e
.
class
}
>
\n
"
+
" Message:
#{
e
.
message
}
"
" Message:
#{
e
.
message
}
"
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
diff
])
$mrbtest_assert
.
push
[
$mrbtest_assert_idx
,
msg
,
diff
]
ret
=
false
false
end
end
end
ret
end
end
##
##
...
...
test/t/module.rb
View file @
79b4f61b
...
@@ -635,7 +635,7 @@ end
...
@@ -635,7 +635,7 @@ end
c
.
singleton_class
.
class_eval
do
c
.
singleton_class
.
class_eval
do
define_method
(
:method_removed
)
{
|
id
|
removed
=
id
}
define_method
(
:method_removed
)
{
|
id
|
removed
=
id
}
end
end
assert_nothing_raised
(
NoMethodError
,
NameError
,
'[Bug #7843]'
)
do
assert_nothing_raised
(
'[Bug #7843]'
)
do
c
.
class_eval
do
c
.
class_eval
do
remove_method
(
:foo
)
remove_method
(
:foo
)
end
end
...
@@ -724,7 +724,7 @@ end
...
@@ -724,7 +724,7 @@ end
end
end
a
=
c
.
new
a
=
c
.
new
assert_true
a
.
respond_to?
(
:foo
),
bug8005
assert_true
a
.
respond_to?
(
:foo
),
bug8005
assert_nothing_raised
(
NoMethodError
,
bug8005
)
{
a
.
send
:foo
}
assert_nothing_raised
(
bug8005
)
{
a
.
send
:foo
}
end
end
# mruby has no visibility control
# 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