Class: TestableExamples::Matcher
- Inherits:
-
Object
- Object
- TestableExamples::Matcher
- Defined in:
- lib/testable_examples/matcher.rb
Instance Method Summary collapse
- #assert(*args) ⇒ Object
-
#initialize(val) ⇒ Matcher
constructor
A new instance of Matcher.
- #match(*args) ⇒ Object
- #match_exception? ⇒ Boolean
Constructor Details
#initialize(val) ⇒ Matcher
3 4 5 6 7 8 9 10 |
# File 'lib/testable_examples/matcher.rb', line 3 def initialize(val) @val = val @literal_val = begin eval(val) rescue Exception nil end end |
Instance Method Details
#assert(*args) ⇒ Object
29 30 31 |
# File 'lib/testable_examples/matcher.rb', line 29 def assert(*args) match(*args) or raise("Unable to match #{args.inspect} against #{@val.inspect}") end |
#match(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/testable_examples/matcher.rb', line 12 def match(*args) o = args.compact.first if @literal_val @literal_val === o elsif @val[/^[A-Z][a-z0-9_]*$/] Object.const_get(@val.to_sym) elsif @val[/^([A-Z][a-zA-Z0-9_]*?):(.*)$/] and o.is_a?(Exception) o.class.to_s === $1.strip && o. == $2.strip else raise "Unable to understand val type #{@val.inspect}" end end |
#match_exception? ⇒ Boolean
25 26 27 |
# File 'lib/testable_examples/matcher.rb', line 25 def match_exception? @val[/^[A-Z]/] end |