Module: Minitest::Rails::Expectations::ActionDispatch

Extended by:
ActiveSupport::Concern
Included in:
ActionDispatch::IntegrationTest
Defined in:
lib/minitest/rails/expectations/action_dispatch.rb

Overview

This exists as a module to allow easy mixing into classes other than ActionDispatch::IntegrationTest where you might want to do job testing.

Instance Method Summary collapse

Instance Method Details

#assert_dom_equalObject

Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values. Checks the numeric difference between the return value of an expression as a result of what is evaluated.

apple_link = '<a href="http://www.example.com">Apples</a>'
value(link_to("Apples", "http://www.example.com")).must_dom_equal apple_link

See also ActionView::TestCase#assert_dom_equal See also ActionDispatch::IntegrationTest#assert_dom_equal

:method: must_dom_equal :args: expected, message = nil



272
# File 'lib/minitest/rails/expectations/action_dispatch.rb', line 272

infect_an_assertion :assert_dom_equal, :must_dom_equal

#assert_generatesObject

Expects that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.

The defaults parameter is unused.

# Expects that the default action is generated for a route with no action
value({controller: "items", action: "index"}).must_route_from "/items"

# Tests that the list action is properly routed
value({controller: "items", action: "list"}).must_route_to "/items/list"

# Tests the generation of a route with a parameter
value({ controller: "items", action: "list", id: "1" }).must_route_from "/items/list/1"

# Expects that the generated route gives us our custom route
value({ controller: 'scm', action: 'show_diff', revision: "12" }).must_route_from "changesets/12"

See also ActionView::TestCase#assert_generates See also ActionDispatch::IntegrationTest#assert_generates

:method: must_route_from :call-seq: options.must_route_from(expected_path, defaults={}, extras = {}, message=nil)



34
# File 'lib/minitest/rails/expectations/action_dispatch.rb', line 34

infect_an_assertion :assert_generates, :must_route_to

#assert_recognizesObject

Expects that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.

Pass a hash in the second argument (path) to specify the request method. This is useful for routes requiring a specific HTTP method. The hash should contain a :path with the incoming request path and a :method containing the required HTTP verb.

# assert that POSTing to /items will call the create action on ItemsController
assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})

You can also pass in extras with a hash containing URL parameters that would normally be in the query string. This can be used to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the extras argument, appending the query string on the path directly will not work. For example:

# Expect that a path of '/items/list/1?view=print' returns the correct options
value('items/list/1').must_route_from({controller: 'items', action: 'list', id: '1', view: 'print'}, { view: "print" })

The message parameter allows you to pass in an error message that is displayed upon failure.

# Check the default route (i.e., the index action)
value('items').must_route_from({controller: 'items', action: 'index'})

# Test a specific action
value('items/list').must_route_from({controller: 'items', action: 'list'})

# Test an action with a parameter
value('items/destroy/1').must_route_from({controller: 'items', action: 'destroy', id: '1'})

# Test a custom route
value('view/item1').must_route_from({controller: 'items', action: 'show', id: '1'})

See also ActionView::TestCase#assert_recognizes See also ActionDispatch::IntegrationTest#assert_recognizes

:method: must_route_from :call-seq: path.must_route_from(expected_options, extras={}, msg=nil)



73
# File 'lib/minitest/rails/expectations/action_dispatch.rb', line 73

infect_an_assertion :assert_recognizes, :must_route_from

#assert_routingObject

Expects that path and options match both ways; in other words, it verifies that path generates options and then that options generates path. This essentially combines assert_recognizes and assert_generates into one step.

The extras hash allows you to specify options that would normally be provided as a query string to the action. The message parameter allows you to specify a custom error message to display upon failure.

# Expect a basic route: a controller with the default action (index)
value({ controller: 'home', action: 'index' }).must_route_for '/home'

# Test a route generated with a specific controller, action, and parameter (id)
value({ controller: 'entries', action: 'show', id: 23 }).must_route_for '/entries/show/23'

# Expect a basic route (controller + default action), with an error message if it fails
value({ controller: 'store', action: 'index' }).must_route_for '/store'

# Tests a route, providing a defaults hash
value({id: "9", item: "square"}).must_route_for 'controller/action/9', {controller: "controller", action: "action"}, {}, {item: "square"}

# Tests a route with a HTTP method
value({ controller: "product", action: "update", id: "321" }).must_route_for({ method: 'put', path: '/product/321' })

See also ActionView::TestCase#assert_routing See also ActionDispatch::IntegrationTest#assert_routing

:method: must_route_for :call-seq: options.must_route_for(path, defaults={}, extras={}, message=nil)



103
# File 'lib/minitest/rails/expectations/action_dispatch.rb', line 103

infect_an_assertion :assert_routing, :must_route_for

#refute_dom_equalObject

Checks that the numeric result of evaluating an expression is not changed before and after invoking.

orange_link = '<a href="http://www.example.com">Oranges</a>'
link_to("Apples", "http://www.example.com").wont_dom_equal orange_link

See also ActionView::TestCase#refute_dom_equal See also ActionDispatch::IntegrationTest#refute_dom_equal See also ActionView::TestCase#assert_dom_not_equal See also ActionDispatch::IntegrationTest#assert_dom_not_equal

:method: wont_dom_equal :args: expected, message = nil



287
# File 'lib/minitest/rails/expectations/action_dispatch.rb', line 287

infect_an_assertion :refute_dom_equal, :wont_dom_equal