LanguagesRuby / RailsTesting Views and Integration in Ruby on Rails

Testing Views and Integration in Ruby on Rails

To test views in a Rails application, you use assertions to send requests and then check for the response to those requests. In the example Saurabh Bhatia uses in his article “Testing Views and Integration in Ruby on Rails,” you make the assertions on the presence of HTML elements on your application views. The Rails method you use to do this is assert_select.

The assert_select method has two types:

  1. assert_selector(selector,[equality],[message]): The selector type specifies the HTML elements that you need to equate. These elements can be an element of CSS, or an expression with substitution values. The whole test tag asserts whether or not the value mentioned in the selector element is equal to the response and displays an appropriate message.
  2. assert_select(element, selector, [equality], [message]): This type uses the condition of equality and validates it over each of the selected elements using the selector. It starts from the element that is an instance of HTML::Node and its subnodes.

Integration Testing in Rails

At some point during the development of any application, you contend with workflow and data flow. In Rails—as we all know—this flow is largely defined by Controllers. The workflow of an application is composed of multiple controllers and the interaction among their actions. Integration testing tests such workflows and verifies how it takes place between different controllers.

Rails does not automatically create integration tests with models, controllers, or scaffolds. However, you can create skeleton tests using the Rails generators.

Read the entire article at Web Developer’s Virtual Library to learn all about testing views and integration in Ruby on Rails.

Please enter your content here.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories