Module Shoulda::ActionView::Macros
In: lib/shoulda/action_view/macros.rb
ValidationMatcher ValidatePresenceOfMatcher ValidateAcceptanceOfMatcher EnsureLengthOfMatcher ValidateFormatOfMatcher EnsureInclusionOfMatcher ValidateUniquenessOfMatcher ValidateNumericalityOfMatcher Context SetSessionMatcher RespondWithContentTypeMatcher SetTheFlashMatcher RenderWithLayout RespondWithMatcher AssignToMatcher FilterParamMatcher RouteMatcher HaveNamedScopeMatcher HaveDbIndexMatcher HaveDbColumnMatcher AllowMassAssignmentOfMatcher AllowValueMatcher AssociationMatcher HaveReadonlyAttributeMatcher lib/shoulda/context.rb lib/shoulda/action_controller/matchers/set_session_matcher.rb lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb lib/shoulda/action_controller/matchers/respond_with_matcher.rb lib/shoulda/action_controller/matchers/assign_to_matcher.rb lib/shoulda/action_controller/matchers/filter_param_matcher.rb lib/shoulda/action_controller/matchers/route_matcher.rb Matchers Macros ActionController lib/shoulda/active_record/matchers/validation_matcher.rb lib/shoulda/active_record/matchers/have_named_scope_matcher.rb lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb lib/shoulda/active_record/matchers/have_db_index_matcher.rb lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb lib/shoulda/active_record/matchers/validate_format_of_matcher.rb lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb lib/shoulda/active_record/matchers/have_db_column_matcher.rb lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb lib/shoulda/active_record/matchers/allow_value_matcher.rb lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb lib/shoulda/active_record/matchers/association_matcher.rb lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb Matchers Helpers Assertions Macros ActiveRecord ClassMethods Macros ActionView Private Helpers Assertions ActionMailer InstanceMethods Assertions Macros Shoulda dot/m_47_0.png

Macro test helpers for your view

By using the macro helpers you can quickly and easily create concise and easy to read test suites.

This code segment:

  context "on GET to :new" do
    setup do
      get :new
    end

    should_render_page_with_metadata :title => /index/

    should "do something else really cool" do
      assert_select '#really_cool'
    end
  end

Would produce 3 tests for the show action

Methods

Public Instance methods

Macro that creates a test asserting that the rendered view contains a <form> element.

Deprecated.

[Source]

    # File lib/shoulda/action_view/macros.rb, line 27
27:       def should_render_a_form
28:         warn "[DEPRECATION] should_render_a_form is deprecated."
29:         should "display a form" do
30:           assert_select "form", true, "The template doesn't contain a <form> element"
31:         end
32:       end

Deprecated.

Macro that creates a test asserting that the rendered view contains the selected metatags. Values can be string or Regexps. Example:

  should_render_page_with_metadata :description => "Description of this page", :keywords => /post/

You can also use this method to test the rendered views title.

Example:

  should_render_page_with_metadata :title => /index/

[Source]

    # File lib/shoulda/action_view/macros.rb, line 46
46:       def should_render_page_with_metadata(options)
47:         warn "[DEPRECATION] should_render_page_with_metadata is deprecated."
48:         options.each do |key, value|
49:           should "have metatag #{key}" do
50:             if key.to_sym == :title
51:               assert_select "title", value
52:             else
53:               assert_select "meta[name=?][content#{"*" if value.is_a?(Regexp)}=?]", key, value
54:             end
55:           end
56:         end
57:       end

[Validate]