Module: Mack::Testing::TestCaseAssertions
- Defined in:
- lib/mack/testing/test_assertions.rb
Instance Method Summary collapse
-
#assert_cookie(name, value) ⇒ Object
Asserts that the specified cookie has been set to the specified value.
- #assert_difference(object, method = nil, difference = 1) ⇒ Object
-
#assert_no_cookie(name) ⇒ Object
Asserts that there is no cookie set for the specified cookie.
-
#assert_redirected_to(url) ⇒ Object
Asserts that the request has been redirected to the specified url.
-
#assert_response(status) ⇒ Object
Takes either a Symbol or a Fixnum and assert the response matches it.
Instance Method Details
#assert_cookie(name, value) ⇒ Object
Asserts that the specified cookie has been set to the specified value.
33 34 35 36 |
# File 'lib/mack/testing/test_assertions.rb', line 33 def (name, value) assert [name.to_s] assert_equal value, [name.to_s] end |
#assert_difference(object, method = nil, difference = 1) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/mack/testing/test_assertions.rb', line 43 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 |
#assert_no_cookie(name) ⇒ Object
Asserts that there is no cookie set for the specified cookie
39 40 41 |
# File 'lib/mack/testing/test_assertions.rb', line 39 def (name) assert ![name.to_s] end |
#assert_redirected_to(url) ⇒ Object
Asserts that the request has been redirected to the specified url.
28 29 30 |
# File 'lib/mack/testing/test_assertions.rb', line 28 def assert_redirected_to(url) assert response.redirected_to?(url) end |
#assert_response(status) ⇒ Object
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
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mack/testing/test_assertions.rb', line 8 def assert_response(status) if status.is_a?(Symbol) case status when :success assert(response.successful?) when :redirect assert(response.redirect?) when :not_found assert(response.not_found?) when :error assert(response.server_error?) else assert(false) end elsif status.is_a?(Fixnum) assert_equal(status, response.status) end end |