Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7ee60d4c
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7ee60d4c
编写于
8月 25, 2015
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21368 from rodzyn/remove_mocha
Get rid of mocha tests in actionpack - part 2
上级
c5a88e50
00234f56
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
209 addition
and
163 deletion
+209
-163
actionpack/test/abstract_unit.rb
actionpack/test/abstract_unit.rb
+7
-1
actionpack/test/controller/integration_test.rb
actionpack/test/controller/integration_test.rb
+153
-113
actionpack/test/controller/request_forgery_protection_test.rb
...onpack/test/controller/request_forgery_protection_test.rb
+24
-8
actionpack/test/dispatch/debug_exceptions_test.rb
actionpack/test/dispatch/debug_exceptions_test.rb
+25
-32
actionpack/test/dispatch/routing/inspector_test.rb
actionpack/test/dispatch/routing/inspector_test.rb
+0
-9
未找到文件。
actionpack/test/abstract_unit.rb
浏览文件 @
7ee60d4c
...
...
@@ -41,6 +41,8 @@ class << self
def
env
@_env
||=
ActiveSupport
::
StringInquirer
.
new
(
ENV
[
"RAILS_ENV"
]
||
ENV
[
"RACK_ENV"
]
||
"test"
)
end
def
root
;
end
;
end
end
...
...
@@ -407,7 +409,7 @@ def jruby_skip(message = '')
end
require
'mocha/setup'
# FIXME: stop using mocha
require
'
minitest/mock
'
require
'
active_support/testing/method_call_assertions
'
class
ForkingExecutor
class
Server
...
...
@@ -479,3 +481,7 @@ def translate_exceptions(result)
# Use N processes (N defaults to 4)
Minitest
.
parallel_executor
=
ForkingExecutor
.
new
(
PROCESS_COUNT
)
end
class
ActiveSupport::TestCase
include
ActiveSupport
::
Testing
::
MethodCallAssertions
end
actionpack/test/controller/integration_test.rb
浏览文件 @
7ee60d4c
此差异已折叠。
点击以展开。
actionpack/test/controller/request_forgery_protection_test.rb
浏览文件 @
7ee60d4c
...
...
@@ -131,9 +131,7 @@ def form_authenticity_param
# common test methods
module
RequestForgeryProtectionTests
def
setup
@token
=
"cf50faa3fe97702ca1ae"
@controller
.
stubs
(
:valid_authenticity_token?
).
with
{
|
_
,
t
|
t
==
@token
}.
returns
(
true
)
@controller
.
stubs
(
:valid_authenticity_token?
).
with
{
|
_
,
t
|
t
!=
@token
}.
returns
(
false
)
@token
=
Base64
.
strict_encode64
(
'railstestrailstestrailstestrails'
)
@old_request_forgery_protection_token
=
ActionController
::
Base
.
request_forgery_protection_token
ActionController
::
Base
.
request_forgery_protection_token
=
:custom_authenticity_token
end
...
...
@@ -255,37 +253,53 @@ def test_should_not_allow_xhr_post_without_token
end
def
test_should_allow_post_with_token
assert_not_blocked
{
post
:index
,
params:
{
custom_authenticity_token:
@token
}
}
session
[
:_csrf_token
]
=
@token
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
{
post
:index
,
params:
{
custom_authenticity_token:
@token
}
}
end
end
def
test_should_allow_patch_with_token
assert_not_blocked
{
patch
:index
,
params:
{
custom_authenticity_token:
@token
}
}
session
[
:_csrf_token
]
=
@token
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
{
patch
:index
,
params:
{
custom_authenticity_token:
@token
}
}
end
end
def
test_should_allow_put_with_token
assert_not_blocked
{
put
:index
,
params:
{
custom_authenticity_token:
@token
}
}
session
[
:_csrf_token
]
=
@token
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
{
put
:index
,
params:
{
custom_authenticity_token:
@token
}
}
end
end
def
test_should_allow_delete_with_token
assert_not_blocked
{
delete
:index
,
params:
{
custom_authenticity_token:
@token
}
}
session
[
:_csrf_token
]
=
@token
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
{
delete
:index
,
params:
{
custom_authenticity_token:
@token
}
}
end
end
def
test_should_allow_post_with_token_in_header
session
[
:_csrf_token
]
=
@token
@request
.
env
[
'HTTP_X_CSRF_TOKEN'
]
=
@token
assert_not_blocked
{
post
:index
}
end
def
test_should_allow_delete_with_token_in_header
session
[
:_csrf_token
]
=
@token
@request
.
env
[
'HTTP_X_CSRF_TOKEN'
]
=
@token
assert_not_blocked
{
delete
:index
}
end
def
test_should_allow_patch_with_token_in_header
session
[
:_csrf_token
]
=
@token
@request
.
env
[
'HTTP_X_CSRF_TOKEN'
]
=
@token
assert_not_blocked
{
patch
:index
}
end
def
test_should_allow_put_with_token_in_header
session
[
:_csrf_token
]
=
@token
@request
.
env
[
'HTTP_X_CSRF_TOKEN'
]
=
@token
assert_not_blocked
{
put
:index
}
end
...
...
@@ -339,6 +353,7 @@ def test_should_only_allow_same_origin_js_get_with_xhr_header
# Allow non-GET requests since GET is all a remote <script> tag can muster.
def
test_should_allow_non_get_js_without_xhr_header
session
[
:_csrf_token
]
=
@token
assert_cross_origin_not_blocked
{
post
:same_origin_js
,
params:
{
custom_authenticity_token:
@token
}
}
assert_cross_origin_not_blocked
{
post
:same_origin_js
,
params:
{
format:
'js'
,
custom_authenticity_token:
@token
}
}
assert_cross_origin_not_blocked
do
...
...
@@ -412,7 +427,8 @@ class RequestForgeryProtectionControllerUsingResetSessionTest < ActionController
get
:meta
assert_select
'meta[name=?][content=?]'
,
'csrf-param'
,
'custom_authenticity_token'
assert_select
'meta[name=?]'
,
'csrf-token'
assert_match
(
/cf50faa3fe97702ca1ae<=\?/
,
@response
.
body
)
regexp
=
"
#{
@token
}
<=
\?
"
assert_match
(
/
#{
regexp
}
/
,
@response
.
body
)
end
end
end
...
...
actionpack/test/dispatch/debug_exceptions_test.rb
浏览文件 @
7ee60d4c
...
...
@@ -71,14 +71,6 @@ def call(env)
end
end
def
setup
app
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
.
assets
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
.
assets
.
prefix
=
'/sprockets'
Rails
.
stubs
(
:application
).
returns
(
app
)
end
RoutesApp
=
Struct
.
new
(
:routes
).
new
(
SharedTestRoutes
)
ProductionApp
=
ActionDispatch
::
DebugExceptions
.
new
(
Boomer
.
new
(
false
),
RoutesApp
)
DevelopmentApp
=
ActionDispatch
::
DebugExceptions
.
new
(
Boomer
.
new
(
true
),
RoutesApp
)
...
...
@@ -338,36 +330,37 @@ def setup
test
'debug exceptions app shows user code that caused the error in source view'
do
@app
=
DevelopmentApp
Rails
.
stub
s
(
:root
).
returns
(
Pathname
.
new
(
'.'
))
cleaner
=
ActiveSupport
::
BacktraceCleaner
.
new
.
tap
do
|
bc
|
bc
.
add_silencer
{
|
line
|
line
=~
/method_that_raises/
}
bc
.
add_silencer
{
|
line
|
line
!~
%r{test/dispatch/debug_exceptions_test.rb}
}
end
Rails
.
stub
:root
,
Pathname
.
new
(
'.'
)
do
cleaner
=
ActiveSupport
::
BacktraceCleaner
.
new
.
tap
do
|
bc
|
bc
.
add_silencer
{
|
line
|
line
=~
/method_that_raises/
}
bc
.
add_silencer
{
|
line
|
line
!~
%r{test/dispatch/debug_exceptions_test.rb}
}
end
get
'/framework_raises'
,
headers:
{
'action_dispatch.backtrace_cleaner'
=>
cleaner
}
get
'/framework_raises'
,
headers:
{
'action_dispatch.backtrace_cleaner'
=>
cleaner
}
# Assert correct error
assert_response
500
assert_select
'h2'
,
/error in framework/
# Assert correct error
assert_response
500
assert_select
'h2'
,
/error in framework/
# assert source view line is the call to method_that_raises
assert_select
'div.source:not(.hidden)'
do
assert_select
'pre .line.active'
,
/method_that_raises/
end
# assert source view line is the call to method_that_raises
assert_select
'div.source:not(.hidden)'
do
assert_select
'pre .line.active'
,
/method_that_raises/
end
# assert first source view (hidden) that throws the error
assert_select
'div.source:first'
do
assert_select
'pre .line.active'
,
/raise StandardError\.new/
end
# assert first source view (hidden) that throws the error
assert_select
'div.source:first'
do
assert_select
'pre .line.active'
,
/raise StandardError\.new/
end
# assert application trace refers to line that calls method_that_raises is first
assert_select
'#Application-Trace'
do
assert_select
'pre code a:first'
,
%r{test/dispatch/debug_exceptions_test
\.
rb:
\d
+:in `call}
end
# assert application trace refers to line that calls method_that_raises is first
assert_select
'#Application-Trace'
do
assert_select
'pre code a:first'
,
%r{test/dispatch/debug_exceptions_test
\.
rb:
\d
+:in `call}
end
# assert framework trace that that threw the error is first
assert_select
'#Framework-Trace'
do
assert_select
'pre code a:first'
,
/method_that_raises/
# assert framework trace that that threw the error is first
assert_select
'#Framework-Trace'
do
assert_select
'pre code a:first'
,
/method_that_raises/
end
end
end
end
actionpack/test/dispatch/routing/inspector_test.rb
浏览文件 @
7ee60d4c
...
...
@@ -12,12 +12,6 @@ module Routing
class
RoutesInspectorTest
<
ActiveSupport
::
TestCase
def
setup
@set
=
ActionDispatch
::
Routing
::
RouteSet
.
new
app
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
.
assets
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
.
assets
.
prefix
=
'/sprockets'
Rails
.
stubs
(
:application
).
returns
(
app
)
Rails
.
stubs
(
:env
).
returns
(
"development"
)
end
def
draw
(
options
=
{},
&
block
)
...
...
@@ -316,9 +310,6 @@ def test_regression_route_with_controller_regexp
def
test_inspect_routes_shows_resources_route_when_assets_disabled
@set
=
ActionDispatch
::
Routing
::
RouteSet
.
new
app
=
ActiveSupport
::
OrderedOptions
.
new
Rails
.
stubs
(
:application
).
returns
(
app
)
output
=
draw
do
get
'/cart'
,
to:
'cart#show'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录