Module: AssertValidContent::Assertions
- Included in:
- Test::Unit::TestCase
- Defined in:
- lib/assert_valid_content/assertions.rb
Overview
Test case assertions
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#assert_valid_content(type, *srcs) ⇒ Object
Asserts that the content (from one ore more
srcs) is valid for typetype. -
#method_missing(name, *args) ⇒ Object
Implements the
assert_valid_TYPE(*srcs) dynamic assertions, whereTYPEis a MIME type name (e.g.html,css, etc.) and each ofsrcsone ofString,Pathname, orIOobject. -
#orig_method_missing ⇒ Object
:nodoc:.
-
#test__assert_valid_static_content ⇒ Object
Executes class-level assertions (i.e. static content).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Implements the assert_valid_TYPE(*srcs) dynamic assertions, where TYPE is a MIME type name (e.g. html, css, etc.) and each of srcs one of String, Pathname, or IO object.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/assert_valid_content/assertions.rb', line 22 def method_missing( name, *args ) n = name.to_s return orig_method_missing( name, *args ) unless (n[0..12] == 'assert_valid_') and (type = Mime::Type.lookup_by_extension n[13..-1]) if args.empty? and self.respond_to?(:response) and self.response.respond_to(:body) args = [ self.response.body ] end assert_valid_content type, *args end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
51 52 53 |
# File 'lib/assert_valid_content/assertions.rb', line 51 def self.included( base ) #:nodoc: base.extend Assertions::ClassMethods end |
Instance Method Details
#assert_valid_content(type, *srcs) ⇒ Object
Asserts that the content (from one ore more srcs) is valid for type type. Each of srcs is one of String, Pathname, or IO object.
10 11 12 13 14 15 16 |
# File 'lib/assert_valid_content/assertions.rb', line 10 def assert_valid_content( type, *srcs ) msg = nil for src in srcs res = AssertValidContent.valid_content?(type, src) { |val| msg = val.to_s } assert_block( msg ) { res } end end |
#orig_method_missing ⇒ Object
:nodoc:
18 |
# File 'lib/assert_valid_content/assertions.rb', line 18 alias_method :orig_method_missing, :method_missing |
#test__assert_valid_static_content ⇒ Object
Executes class-level assertions (i.e. static content).
56 57 58 59 60 |
# File 'lib/assert_valid_content/assertions.rb', line 56 def test__assert_valid_static_content #:nodoc: for args in self.class.assert_valid_static_content assert_valid_content *args end end |