Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2ff60e86
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,发现更多精彩内容 >>
提交
2ff60e86
编写于
7月 17, 2013
作者:
T
Timm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed tag.rb since it has been deprecated.
上级
8f5547f4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
0 addition
and
321 deletion
+0
-321
actionpack/lib/action_dispatch/testing/assertions.rb
actionpack/lib/action_dispatch/testing/assertions.rb
+0
-2
actionpack/lib/action_dispatch/testing/assertions/tag.rb
actionpack/lib/action_dispatch/testing/assertions/tag.rb
+0
-135
actionpack/test/controller/action_pack_assertions_test.rb
actionpack/test/controller/action_pack_assertions_test.rb
+0
-5
actionpack/test/controller/test_case_test.rb
actionpack/test/controller/test_case_test.rb
+0
-179
未找到文件。
actionpack/lib/action_dispatch/testing/assertions.rb
浏览文件 @
2ff60e86
...
@@ -4,7 +4,6 @@ module Assertions
...
@@ -4,7 +4,6 @@ module Assertions
autoload
:ResponseAssertions
,
'action_dispatch/testing/assertions/response'
autoload
:ResponseAssertions
,
'action_dispatch/testing/assertions/response'
autoload
:RoutingAssertions
,
'action_dispatch/testing/assertions/routing'
autoload
:RoutingAssertions
,
'action_dispatch/testing/assertions/routing'
autoload
:SelectorAssertions
,
'action_dispatch/testing/assertions/selector'
autoload
:SelectorAssertions
,
'action_dispatch/testing/assertions/selector'
autoload
:TagAssertions
,
'action_dispatch/testing/assertions/tag'
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
...
@@ -12,7 +11,6 @@ module Assertions
...
@@ -12,7 +11,6 @@ module Assertions
include
ResponseAssertions
include
ResponseAssertions
include
RoutingAssertions
include
RoutingAssertions
include
SelectorAssertions
include
SelectorAssertions
include
TagAssertions
end
end
end
end
actionpack/lib/action_dispatch/testing/assertions/tag.rb
已删除
100644 → 0
浏览文件 @
8f5547f4
require
'action_view/vendor/html-scanner'
module
ActionDispatch
module
Assertions
# Pair of assertions to testing elements in the HTML output of the response.
module
TagAssertions
# Asserts that there is a tag/node/element in the body of the response
# that meets all of the given conditions. The +conditions+ parameter must
# be a hash of any of the following keys (all are optional):
#
# * <tt>:tag</tt>: the node type must match the corresponding value
# * <tt>:attributes</tt>: a hash. The node's attributes must match the
# corresponding values in the hash.
# * <tt>:parent</tt>: a hash. The node's parent must match the
# corresponding hash.
# * <tt>:child</tt>: a hash. At least one of the node's immediate children
# must meet the criteria described by the hash.
# * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
# meet the criteria described by the hash.
# * <tt>:descendant</tt>: a hash. At least one of the node's descendants
# must meet the criteria described by the hash.
# * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
# meet the criteria described by the hash.
# * <tt>:after</tt>: a hash. The node must be after any sibling meeting
# the criteria described by the hash, and at least one sibling must match.
# * <tt>:before</tt>: a hash. The node must be before any sibling meeting
# the criteria described by the hash, and at least one sibling must match.
# * <tt>:children</tt>: a hash, for counting children of a node. Accepts
# the keys:
# * <tt>:count</tt>: either a number or a range which must equal (or
# include) the number of children that match.
# * <tt>:less_than</tt>: the number of matching children must be less
# than this number.
# * <tt>:greater_than</tt>: the number of matching children must be
# greater than this number.
# * <tt>:only</tt>: another hash consisting of the keys to use
# to match on the children, and only matching children will be
# counted.
# * <tt>:content</tt>: the textual content of the node must match the
# given value. This will not match HTML tags in the body of a
# tag--only text.
#
# Conditions are matched using the following algorithm:
#
# * if the condition is a string, it must be a substring of the value.
# * if the condition is a regexp, it must match the value.
# * if the condition is a number, the value must match number.to_s.
# * if the condition is +true+, the value must not be +nil+.
# * if the condition is +false+ or +nil+, the value must be +nil+.
#
# # Assert that there is a "span" tag
# assert_tag tag: "span"
#
# # Assert that there is a "span" tag with id="x"
# assert_tag tag: "span", attributes: { id: "x" }
#
# # Assert that there is a "span" tag using the short-hand
# assert_tag :span
#
# # Assert that there is a "span" tag with id="x" using the short-hand
# assert_tag :span, attributes: { id: "x" }
#
# # Assert that there is a "span" inside of a "div"
# assert_tag tag: "span", parent: { tag: "div" }
#
# # Assert that there is a "span" somewhere inside a table
# assert_tag tag: "span", ancestor: { tag: "table" }
#
# # Assert that there is a "span" with at least one "em" child
# assert_tag tag: "span", child: { tag: "em" }
#
# # Assert that there is a "span" containing a (possibly nested)
# # "strong" tag.
# assert_tag tag: "span", descendant: { tag: "strong" }
#
# # Assert that there is a "span" containing between 2 and 4 "em" tags
# # as immediate children
# assert_tag tag: "span",
# children: { count: 2..4, only: { tag: "em" } }
#
# # Get funky: assert that there is a "div", with an "ul" ancestor
# # and an "li" parent (with "class" = "enum"), and containing a
# # "span" descendant that contains text matching /hello world/
# assert_tag tag: "div",
# ancestor: { tag: "ul" },
# parent: { tag: "li",
# attributes: { class: "enum" } },
# descendant: { tag: "span",
# child: /hello world/ }
#
# <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
# with well-formed XHTML. They recognize a few tags as implicitly self-closing
# (like br and hr and such) but will not work correctly with tags
# that allow optional closing tags (p, li, td). <em>You must explicitly
# close all of your tags to use these assertions.</em>
def
assert_tag
(
*
opts
)
opts
=
opts
.
size
>
1
?
opts
.
last
.
merge
({
:tag
=>
opts
.
first
.
to_s
})
:
opts
.
first
tag
=
find_tag
(
opts
)
assert
tag
,
"expected tag, but no tag found matching
#{
opts
.
inspect
}
in:
\n
#{
@response
.
body
.
inspect
}
"
end
# Identical to +assert_tag+, but asserts that a matching tag does _not_
# exist. (See +assert_tag+ for a full discussion of the syntax.)
#
# # Assert that there is not a "div" containing a "p"
# assert_no_tag tag: "div", descendant: { tag: "p" }
#
# # Assert that an unordered list is empty
# assert_no_tag tag: "ul", descendant: { tag: "li" }
#
# # Assert that there is not a "p" tag with between 1 to 3 "img" tags
# # as immediate children
# assert_no_tag tag: "p",
# children: { count: 1..3, only: { tag: "img" } }
def
assert_no_tag
(
*
opts
)
opts
=
opts
.
size
>
1
?
opts
.
last
.
merge
({
:tag
=>
opts
.
first
.
to_s
})
:
opts
.
first
tag
=
find_tag
(
opts
)
assert
!
tag
,
"expected no tag, but found tag matching
#{
opts
.
inspect
}
in:
\n
#{
@response
.
body
.
inspect
}
"
end
def
find_tag
(
conditions
)
html_document
.
find
(
conditions
)
end
def
find_all_tag
(
conditions
)
html_document
.
find_all
(
conditions
)
end
def
html_document
xml
=
@response
.
content_type
=~
/xml$/
@html_document
||=
HTML
::
Document
.
new
(
@response
.
body
,
false
,
xml
)
end
end
end
end
actionpack/test/controller/action_pack_assertions_test.rb
浏览文件 @
2ff60e86
...
@@ -147,11 +147,6 @@ def redirect_to_top_level_named_route
...
@@ -147,11 +147,6 @@ def redirect_to_top_level_named_route
class
ActionPackAssertionsControllerTest
<
ActionController
::
TestCase
class
ActionPackAssertionsControllerTest
<
ActionController
::
TestCase
def
test_assert_tag_and_url_for
get
:render_url
assert_tag
:content
=>
"/action_pack_assertions/flash_me"
end
def
test_render_file_absolute_path
def
test_render_file_absolute_path
get
:render_file_absolute_path
get
:render_file_absolute_path
assert_match
(
/\A= Action Pack/
,
@response
.
body
)
assert_match
(
/\A= Action Pack/
,
@response
.
body
)
...
...
actionpack/test/controller/test_case_test.rb
浏览文件 @
2ff60e86
...
@@ -353,168 +353,6 @@ def test_view_assigns
...
@@ -353,168 +353,6 @@ def test_view_assigns
assert_equal
"bar"
,
assigns
[
:bar
]
assert_equal
"bar"
,
assigns
[
:bar
]
end
end
def
test_assert_tag_tag
process
:test_html_output
# there is a 'form' tag
assert_tag
:tag
=>
'form'
# there is not an 'hr' tag
assert_no_tag
:tag
=>
'hr'
end
def
test_assert_tag_attributes
process
:test_html_output
# there is a tag with an 'id' of 'bar'
assert_tag
:attributes
=>
{
:id
=>
"bar"
}
# there is no tag with a 'name' of 'baz'
assert_no_tag
:attributes
=>
{
:name
=>
"baz"
}
end
def
test_assert_tag_parent
process
:test_html_output
# there is a tag with a parent 'form' tag
assert_tag
:parent
=>
{
:tag
=>
"form"
}
# there is no tag with a parent of 'input'
assert_no_tag
:parent
=>
{
:tag
=>
"input"
}
end
def
test_assert_tag_child
process
:test_html_output
# there is a tag with a child 'input' tag
assert_tag
:child
=>
{
:tag
=>
"input"
}
# there is no tag with a child 'strong' tag
assert_no_tag
:child
=>
{
:tag
=>
"strong"
}
end
def
test_assert_tag_ancestor
process
:test_html_output
# there is a 'li' tag with an ancestor having an id of 'foo'
assert_tag
:ancestor
=>
{
:attributes
=>
{
:id
=>
"foo"
}
},
:tag
=>
"li"
# there is no tag of any kind with an ancestor having an href matching 'foo'
assert_no_tag
:ancestor
=>
{
:attributes
=>
{
:href
=>
/foo/
}
}
end
def
test_assert_tag_descendant
process
:test_html_output
# there is a tag with a descendant 'li' tag
assert_tag
:descendant
=>
{
:tag
=>
"li"
}
# there is no tag with a descendant 'html' tag
assert_no_tag
:descendant
=>
{
:tag
=>
"html"
}
end
def
test_assert_tag_sibling
process
:test_html_output
# there is a tag with a sibling of class 'item'
assert_tag
:sibling
=>
{
:attributes
=>
{
:class
=>
"item"
}
}
# there is no tag with a sibling 'ul' tag
assert_no_tag
:sibling
=>
{
:tag
=>
"ul"
}
end
def
test_assert_tag_after
process
:test_html_output
# there is a tag following a sibling 'div' tag
assert_tag
:after
=>
{
:tag
=>
"div"
}
# there is no tag following a sibling tag with id 'bar'
assert_no_tag
:after
=>
{
:attributes
=>
{
:id
=>
"bar"
}
}
end
def
test_assert_tag_before
process
:test_html_output
# there is a tag preceding a tag with id 'bar'
assert_tag
:before
=>
{
:attributes
=>
{
:id
=>
"bar"
}
}
# there is no tag preceding a 'form' tag
assert_no_tag
:before
=>
{
:tag
=>
"form"
}
end
def
test_assert_tag_children_count
process
:test_html_output
# there is a tag with 2 children
assert_tag
:children
=>
{
:count
=>
2
}
# in particular, there is a <ul> tag with two children (a nameless pair of <li>s)
assert_tag
:tag
=>
'ul'
,
:children
=>
{
:count
=>
2
}
# there is no tag with 4 children
assert_no_tag
:children
=>
{
:count
=>
4
}
end
def
test_assert_tag_children_less_than
process
:test_html_output
# there is a tag with less than 5 children
assert_tag
:children
=>
{
:less_than
=>
5
}
# there is no 'ul' tag with less than 2 children
assert_no_tag
:children
=>
{
:less_than
=>
2
},
:tag
=>
"ul"
end
def
test_assert_tag_children_greater_than
process
:test_html_output
# there is a 'body' tag with more than 1 children
assert_tag
:children
=>
{
:greater_than
=>
1
},
:tag
=>
"body"
# there is no tag with more than 10 children
assert_no_tag
:children
=>
{
:greater_than
=>
10
}
end
def
test_assert_tag_children_only
process
:test_html_output
# there is a tag containing only one child with an id of 'foo'
assert_tag
:children
=>
{
:count
=>
1
,
:only
=>
{
:attributes
=>
{
:id
=>
"foo"
}
}
}
# there is no tag containing only one 'li' child
assert_no_tag
:children
=>
{
:count
=>
1
,
:only
=>
{
:tag
=>
"li"
}
}
end
def
test_assert_tag_content
process
:test_html_output
# the output contains the string "Name"
assert_tag
:content
=>
/Name/
# the output does not contain the string "test"
assert_no_tag
:content
=>
/test/
end
def
test_assert_tag_multiple
process
:test_html_output
# there is a 'div', id='bar', with an immediate child whose 'action'
# attribute matches the regexp /somewhere/.
assert_tag
:tag
=>
"div"
,
:attributes
=>
{
:id
=>
"bar"
},
:child
=>
{
:attributes
=>
{
:action
=>
/somewhere/
}
}
# there is no 'div', id='foo', with a 'ul' child with more than
# 2 "li" children.
assert_no_tag
:tag
=>
"div"
,
:attributes
=>
{
:id
=>
"foo"
},
:child
=>
{
:tag
=>
"ul"
,
:children
=>
{
:greater_than
=>
2
,
:only
=>
{
:tag
=>
"li"
}
}
}
end
def
test_assert_tag_children_without_content
process
:test_html_output
# there is a form tag with an 'input' child which is a self closing tag
assert_tag
:tag
=>
"form"
,
:children
=>
{
:count
=>
1
,
:only
=>
{
:tag
=>
"input"
}
}
# the body tag has an 'a' child which in turn has an 'img' child
assert_tag
:tag
=>
"body"
,
:children
=>
{
:count
=>
1
,
:only
=>
{
:tag
=>
"a"
,
:children
=>
{
:count
=>
1
,
:only
=>
{
:tag
=>
"img"
}
}
}
}
end
def
test_should_not_impose_childless_html_tags_in_xml
def
test_should_not_impose_childless_html_tags_in_xml
process
:test_xml_output
process
:test_xml_output
...
@@ -529,23 +367,6 @@ def test_should_not_impose_childless_html_tags_in_xml
...
@@ -529,23 +367,6 @@ def test_should_not_impose_childless_html_tags_in_xml
assert
err
.
empty?
assert
err
.
empty?
end
end
def
test_assert_tag_attribute_matching
@response
.
body
=
'<input type="text" name="my_name">'
assert_tag
:tag
=>
'input'
,
:attributes
=>
{
:name
=>
/my/
,
:type
=>
'text'
}
assert_no_tag
:tag
=>
'input'
,
:attributes
=>
{
:name
=>
'my'
,
:type
=>
'text'
}
assert_no_tag
:tag
=>
'input'
,
:attributes
=>
{
:name
=>
/^my$/
,
:type
=>
'text'
}
end
def
test_assert_tag_content_matching
@response
.
body
=
"<p>hello world</p>"
assert_tag
:tag
=>
"p"
,
:content
=>
"hello world"
assert_tag
:tag
=>
"p"
,
:content
=>
/hello/
assert_no_tag
:tag
=>
"p"
,
:content
=>
"hello"
end
def
test_assert_generates
def
test_assert_generates
assert_generates
'controller/action/5'
,
:controller
=>
'controller'
,
:action
=>
'action'
,
:id
=>
'5'
assert_generates
'controller/action/5'
,
:controller
=>
'controller'
,
:action
=>
'action'
,
:id
=>
'5'
assert_generates
'controller/action/7'
,
{
:id
=>
"7"
},
{
:controller
=>
"controller"
,
:action
=>
"action"
}
assert_generates
'controller/action/7'
,
{
:id
=>
"7"
},
{
:controller
=>
"controller"
,
:action
=>
"action"
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录