Sha256: 728996576c79586cbec7ce223b8b5dad14e84808a64f203bb0a6b089ace4b28f

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

module Shoulda # :nodoc:
  module ActionView # :nodoc:
    # = 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_a_form
    #     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
    module Macros

      # Macro that creates a test asserting that the rendered view contains a <form> element.
      def should_render_a_form
        should "display a form" do
          assert_select "form", true, "The template doesn't contain a <form> element"
        end
      end

      # 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/
      def should_render_page_with_metadata(options)
        options.each do |key, value|
          should "have metatag #{key}" do
            if key.to_sym == :title
              assert_select "title", value
            else
              assert_select "meta[name=?][content#{"*" if value.is_a?(Regexp)}=?]", key, value
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 7 rubygems

Version Path
Flamefork-shoulda-2.10.1 lib/shoulda/action_view/macros.rb
Flamefork-shoulda-2.10.2 lib/shoulda/action_view/macros.rb
francois-shoulda-2.10.1 lib/shoulda/action_view/macros.rb
gnip-gnip-1.1.1 test/lib/shoulda/action_view/macros.rb
technicalpickles-shoulda-2.10.0 lib/shoulda/action_view/macros.rb
thoughtbot-shoulda-2.10.0 lib/shoulda/action_view/macros.rb
thoughtbot-shoulda-2.10.1 lib/shoulda/action_view/macros.rb
thoughtbot-shoulda-2.9.2 lib/shoulda/action_view/macros.rb
shoulda-2.9.2 lib/shoulda/action_view/macros.rb
shoulda-2.10.0 lib/shoulda/action_view/macros.rb
shoulda-2.10.1 lib/shoulda/action_view/macros.rb
gnip-1.0.0 test/lib/shoulda/action_view/macros.rb
gnip-1.1.1 test/lib/shoulda/action_view/macros.rb
gnip-0.4.2 test/lib/shoulda/action_view/macros.rb
gnip-1.1.2 test/lib/shoulda/action_view/macros.rb