Module: ChunkMatch
- Included in:
- CategoryTest, NoWikiTest, URITest, WikiTest
- Defined in:
- app/models/chunks/match.rb
Overview
This module is to be included in unit tests that involve matching chunks. It provides a easy way to test whether a chunk matches a particular string and any the values of any fields that should be set after a match.
Instance Method Summary collapse
-
#match(type, test_text, expected) ⇒ Object
Asserts a number of tests for the given type and text.
Instance Method Details
#match(type, test_text, expected) ⇒ Object
Asserts a number of tests for the given type and text.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/chunks/match.rb', line 7 def match(type, test_text, expected) pattern = type.pattern assert_match(pattern, test_text) pattern =~ test_text # Previous assertion guarantees match chunk = type.new($~, nil) # Test if requested parts are correct. for method_sym, value in expected do assert_respond_to(chunk, method_sym) assert_equal(value, chunk.method(method_sym).call, "Checking value of '#{method_sym}'") end end |