Sha256: 437c560d7e7e52150814b5bc6d274ae6989512d87245ab345daa9f7f268f807e

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8
require 'action_controller/test_case'
 
# Assertion helpers extracted from Devise by José Valim.
#
module Cells
  module AssertionsHelper
    def setup
      @controller = ::CellsTestController.new
      @request    = ::ActionController::TestRequest.new
      @response   = ::ActionController::TestResponse.new
      @controller.request = @request
      @controller.response = @response
      @controller.params = {}
    end

    def assert_selekt(content, *args)
      assert_select(HTML::Document.new(content).root, *args)
    end

    def assert_not(assertion)
      assert !assertion
    end

    def assert_blank(assertion)
      assert assertion.blank?
    end

    def assert_not_blank(assertion)
      assert !assertion.blank?
    end
    alias :assert_present :assert_not_blank

    # Execute the block setting the given values and restoring old values after
    # the block is executed.
    #
    # == Usage/Example:
    #
    #   I18n.locale   # => :en
    #
    #   swap(I18n :locale => :se) do
    #     I18n.locale   # => :se
    #   end
    #
    #   I18n.locale   # => :en
    #
    def swap(object, new_values)
      old_values = {}
      new_values.each do |key, value|
        old_values[key] = object.send key
        object.send :"#{key}=", value
      end
      yield
    ensure
      old_values.each do |key, value|
        object.send :"#{key}=", value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cells-3.3.0 test/support/assertions_helper.rb