2012-01-06 14:20:26 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'action_dispatch/testing/assertions/response'
|
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
module Assertions
|
|
|
|
class ResponseAssertionsTest < ActiveSupport::TestCase
|
|
|
|
include ResponseAssertions
|
|
|
|
|
|
|
|
FakeResponse = Struct.new(:response_code) do
|
|
|
|
[:success, :missing, :redirect, :error].each do |sym|
|
|
|
|
define_method("#{sym}?") do
|
|
|
|
sym == response_code
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_response_predicate_methods
|
|
|
|
[:success, :missing, :redirect, :error].each do |sym|
|
|
|
|
@response = FakeResponse.new sym
|
|
|
|
assert_response sym
|
|
|
|
|
2013-12-18 02:51:24 -05:00
|
|
|
assert_raises(Minitest::Assertion) {
|
2012-01-06 14:20:26 -05:00
|
|
|
assert_response :unauthorized
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_response_fixnum
|
|
|
|
@response = FakeResponse.new 400
|
|
|
|
assert_response 400
|
|
|
|
|
2013-12-18 02:51:24 -05:00
|
|
|
assert_raises(Minitest::Assertion) {
|
2012-01-06 14:20:26 -05:00
|
|
|
assert_response :unauthorized
|
|
|
|
}
|
|
|
|
|
2013-12-18 02:51:24 -05:00
|
|
|
assert_raises(Minitest::Assertion) {
|
2012-01-06 14:20:26 -05:00
|
|
|
assert_response 500
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_response_sym_status
|
|
|
|
@response = FakeResponse.new 401
|
|
|
|
assert_response :unauthorized
|
|
|
|
|
2013-12-18 02:51:24 -05:00
|
|
|
assert_raises(Minitest::Assertion) {
|
2012-01-06 14:20:26 -05:00
|
|
|
assert_response :ok
|
|
|
|
}
|
|
|
|
|
2013-12-18 02:51:24 -05:00
|
|
|
assert_raises(Minitest::Assertion) {
|
2012-01-06 14:20:26 -05:00
|
|
|
assert_response :success
|
|
|
|
}
|
|
|
|
end
|
2013-11-24 22:46:58 -05:00
|
|
|
|
|
|
|
def test_assert_response_sym_typo
|
|
|
|
@response = FakeResponse.new 200
|
|
|
|
|
|
|
|
assert_raises(ArgumentError) {
|
|
|
|
assert_response :succezz
|
|
|
|
}
|
|
|
|
end
|
2012-01-06 14:20:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|