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 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string" 2017-07-02 02:15:17 +09:30
customers Added tests to render helper that expect render partial: @foo to 2014-02-12 17:40:52 +00:00
db_definitions Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
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 Remove unneeded test fixtures in AV 2013-06-20 17:23:16 +02:00
games Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
good_customers Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
helpers Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
layout_tests/alt Remove unneeded test fixtures in AV 2013-06-20 17:23:16 +02:00
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 Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
override/test Move view_paths from AP to AV 2013-08-25 11:39:07 +02:00
override2/layouts/test Move view_paths from AP to AV 2013-08-25 11:39:07 +02:00
projects Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
public Clean up and consolidate .gitignores 2018-02-17 14:26:19 -08:00
replies Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
respond_to Remove unneeded test fixtures in AV 2013-06-20 17:23:16 +02:00
test Add test for nested content_tags with data attributes outside of erb 2023-07-14 15:57:23 -06:00
topics Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
translations/templates Failing test for lazy translation in partial with block 2020-12-30 14:07:09 +01:00
_top_level_partial_only.erb Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
_top_level_partial.html.erb Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
companies.yml Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
company.rb Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
developer.rb Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
developers_projects.yml Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
developers.yml Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
mascot.rb Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
mascots.yml Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
plain_text_with_characters.raw Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
plain_text.raw Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
project.rb Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
projects.yml Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
replies.yml Make #to_fs the default replacement for #to_s(:format) 2022-02-07 12:41:21 +01:00
reply.rb Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
ruby_template.ruby Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
shared.html.erb Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00
topic.rb Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
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