命名空间
- 模块 ActionView::TestCase::Behavior::ClassMethods
- 模块 ActionView::TestCase::Behavior::Locals
- 类 ActionView::TestCase::Behavior::RenderedViewsCollection
方法
- #
- C
- P
- R
- S
包含的模块
- Rails::Dom::Testing::Assertions
- ActionView::Context
- ActionDispatch::Routing::PolymorphicRoutes
- AbstractController::Helpers
- ActionView::Helpers
- ActionView::RecordIdentifier
- ActionView::RoutingUrlFor
- ActiveSupport::Testing::ConstantLookup
常量
INTERNAL_IVARS | = | [ :@NAME, :@failures, :@assertions, :@__io__, :@_assertion_wrapped, :@_assertions, :@_result, :@_routes, :@controller, :@_controller, :@_request, :@_config, :@_default_form_builder, :@_layouts, :@_files, :@_rendered_views, :@method_name, :@output_buffer, :@_partials, :@passed, :@rendered, :@request, :@routes, :@tagged_logger, :@_templates, :@options, :@test_passed, :@view, :@view_context_class, :@view_flow, :@_subscribers, :@html_document, ] |
属性
[RW] | controller | |
[RW] | output_buffer | |
[RW] | rendered | |
[RW] | request |
实例公共方法
_routes() 链接
:method: rendered
返回由最后一个 render
调用渲染的内容。
返回的对象的行为类似于字符串,但也公开了一些方法,这些方法允许您使用 .register_parser
注册的格式解析内容字符串。
默认情况下包含以下解析器
.html
将 rendered
内容 String
解析为 HTML。默认情况下,这意味着 Nokogiri::XML::Node
。
test "renders HTML" do
article = Article.create!(title: "Hello, world")
render partial: "articles/article", locals: { article: article }
assert_pattern { rendered.html.at("main h1") => { content: "Hello, world" } }
end
要将渲染的内容解析为 Capybara::Simple::Node
,请使用 Capybara.string
调用重新注册 :html
解析器。
register_parser :html, -> rendered { Capybara.string(rendered) }
test "renders HTML" do
article = Article.create!(title: "Hello, world")
render partial: article
rendered.html.assert_css "h1", text: "Hello, world"
end
.json
将 rendered
内容 String
解析为 JSON。默认情况下,这意味着 ActiveSupport::HashWithIndifferentAccess
。
test "renders JSON" do
article = Article.create!(title: "Hello, world")
render formats: :json, partial: "articles/article", locals: { article: article }
assert_pattern { rendered.json => { title: "Hello, world" } }
end
_test_case() 链接
config() 链接
protect_against_forgery?() 链接
render(options = {}, local_assigns = {}, &block) 链接
rendered_views() 链接
setup_with_controller() 链接
# File actionview/lib/action_view/test_case.rb, line 220 def setup_with_controller controller_class = Class.new(ActionView::TestCase::TestController) @controller = controller_class.new @request = @controller.request @view_flow = ActionView::OutputFlow.new @output_buffer = ActionView::OutputBuffer.new @rendered = self.class.content_class.new(+"") test_case_instance = self controller_class.define_method(:_test_case) { test_case_instance } end