rails/actionview/test/fixtures
Sean Doyle 7badc42723
Introduce ActionView::TestCase.register_parser
Register a callable to decode rendered content for a given MIME type

Each registered decoder will also define a `#rendered.$MIME` helper
method, where `$MIME` corresponds to the value of the `mime` argument.

=== Arguments

`mime` - Symbol the MIME Type name for the rendered content
`callable` - Callable to decode the String. Accepts the String
                    value as its only argument
`block` - Block serves as the decoder when the
                 `callable` is omitted

By default, ActionView::TestCase defines a decoder for:

* :html - returns an instance of Nokogiri::XML::Node
* :json - returns an instance of ActiveSupport::HashWithIndifferentAccess

Each pre-registered decoder also defines a corresponding helper:

* :html - defines `rendered.html`
* :json - defines `rendered.json`

=== Examples

To parse the rendered content into RSS, register a call to `RSS::Parser.parse`:

```ruby
register_decoder :rss, -> rendered { RSS::Parser.parse(rendered) }

test "renders RSS" do
  article = Article.create!(title: "Hello, world")

  render formats: :rss, partial: article

  assert_equal "Hello, world", rendered.rss.items.last.title
end
```

To parse the rendered content into a Capybara::Simple::Node,
re-register an `:html` decoder with a call to
`Capybara.string`:

```ruby
register_decoder :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
```
2023-09-27 02:03:23 +00:00
..
actionpack Fix word case. html -> HTML 2022-09-18 04:21:22 +10:00
comments
customers
db_definitions
developers Introduce ActionView::TestCase.register_parser 2023-09-27 02:03:23 +00:00
digestor Replace dependency tracker with ripper based tracker 2021-07-12 10:33:09 -07:00
fun
games
good_customers
helpers
layout_tests/alt
layouts Replaces the "hash rocket" operator in favor of the newer Ruby syntax when rendering on render 2021-10-03 23:33:56 -03:00
mascots
override/test
override2/layouts/test
projects
public
replies
respond_to
test Add test for nested content_tags with data attributes outside of erb 2023-07-14 15:57:23 -06:00
topics
translations/templates Failing test for lazy translation in partial with block 2020-12-30 14:07:09 +01:00
_top_level_partial_only.erb
_top_level_partial.html.erb
companies.yml
company.rb
developer.rb
developers_projects.yml
developers.yml
mascot.rb
mascots.yml
plain_text_with_characters.raw
plain_text.raw
project.rb
projects.yml
replies.yml Make #to_fs the default replacement for #to_s(:format) 2022-02-07 12:41:21 +01:00
reply.rb
ruby_template.ruby
shared.html.erb
topic.rb
topics.yml Make #to_fs the default replacement for #to_s(:format) 2022-02-07 12:41:21 +01:00
with_format.json.erb Replaces the "hash rocket" operator in favor of the newer Ruby syntax when rendering on render 2021-10-03 23:33:56 -03:00