Flowdock
method

assert_select_rjs

Importance_3
Ruby on Rails latest stable (v6.1.7.7) - 0 notes - Class: ActionDispatch::Assertions::SelectorAssertions
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0 (0)
  • 3.0.9 (-2)
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2
  • What's this?

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

assert_select_rjs(*args, &block) public

Selects content from the RJS response.

Narrowing down

With no arguments, asserts that one or more elements are updated or inserted by RJS statements.

Use the id argument to narrow down the assertion to only statements that update or insert an element with that identifier.

Use the first argument to narrow down assertions to only statements of that type. Possible values are :replace, :replace_html, :show, :hide, :toggle, :remove</tta>, <tt>:insert_html and :redirect.

Use the argument :insert followed by an insertion position to narrow down the assertion to only statements that insert elements in that position. Possible values are :top, :bottom, :before and :after.

Use the argument :redirect followed by a path to check that an statement which redirects to the specified path is generated.

Using the :remove statement, you will be able to pass a block, but it will be ignored as there is no HTML passed for this statement.

Using blocks

Without a block, assert_select_rjs merely asserts that the response contains one or more RJS statements that replace or update content.

With a block, assert_select_rjs also selects all elements used in these statements and passes them to the block. Nested assertions are supported.

Calling assert_select_rjs with no arguments and using nested asserts asserts that the HTML content is returned by one or more RJS statements. Using assert_select directly makes the same assertion on the content, but without distinguishing whether the content is returned in an HTML or JavaScript.

Examples

# Replacing the element foo.
# page.replace 'foo', ...
assert_select_rjs :replace, "foo"

# Replacing with the chained RJS proxy.
# page[:foo].replace ...
assert_select_rjs :chained_replace, 'foo'

# Inserting into the element bar, top position.
assert_select_rjs :insert, :top, "bar"

# Remove the element bar
assert_select_rjs :remove, "bar"

# Changing the element foo, with an image.
assert_select_rjs "foo" do
  assert_select "img[src=/images/logo.gif""
end

# RJS inserts or updates a list with four items.
assert_select_rjs do
  assert_select "ol>li", 4
end

# The same, but shorter.
assert_select "ol>li", 4

# Checking for a redirect.
assert_select_rjs :redirect, root_path
Show source
Register or log in to add new notes.