Sha256: cad7701426e2dbc3ff7ac7043592078887487080d5ff6980305007cd1c4b2dc0

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

require 'test/unit'
module Mack
  
  module TestAssertions
    
    # Takes either a Symbol or a Fixnum and assert the response matches it.
    # The symbols it will match are :success, :redirect, :not_found, :error.
    # If a Fixnum is passed it will assert the response status equals that Fixnum
    def assert_response(status)
      if status.is_a?(Symbol)
        case status
        when :success
          assert(responses.first.successful?)
        when :redirect
          assert(responses.first.redirect?)
        when :not_found
          assert(responses.first.not_found?)
        when :error
          assert(responses.first.server_error?)
        else
          assert(false)
        end
      elsif status.is_a?(Fixnum)
        assert_equal(status, responses.first.status)
      end
    end
    
    # Asserts that the request has been redirected to the specified url.
    def assert_redirected_to(url)
      assert_equal(url, responses.first.location)
    end
    
    # Asserts that the specified cookie has been set to the specified value.
    def assert_cookie(name, value)
      assert cookies[name.to_s]
      assert_equal value, cookies[name.to_s]
    end
    
    # Asserts that there is no cookie set for the specified cookie
    def assert_no_cookie(name)
      assert !cookies[name.to_s]
    end
    
    def assert_difference(object, method = nil, difference = 1)
      start_count = object.send(method)
      yield
      object.reload if object.respond_to? :reload
      assert_equal start_count + difference, object.send(method)
    end
    
  end # TestAssertions
  
end # Mack

Test::Unit::TestCase.send(:include, Mack::TestAssertions)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mack-0.4.1 lib/test_extensions/test_assertions.rb
mack-0.4.2.1 lib/test_extensions/test_assertions.rb
mack-0.4.2 lib/test_extensions/test_assertions.rb
mack-0.4.5 lib/test_extensions/test_assertions.rb
mack-0.4.6 lib/test_extensions/test_assertions.rb
mack-0.4.7 lib/test_extensions/test_assertions.rb
mack-0.5.0 lib/test_extensions/test_assertions.rb
mack-0.5.5.1 lib/test_extensions/test_assertions.rb
mack-0.5.5.2 lib/test_extensions/test_assertions.rb
mack-0.5.5.4 lib/test_extensions/test_assertions.rb
mack-0.5.5.3 lib/test_extensions/test_assertions.rb
mack-0.5.5 lib/test_extensions/test_assertions.rb