Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information
1 parent
162be9f
commit 7badc42
Showing
8 changed files
with
364 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ name: developer.name }.to_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.