lib/aktion_test/matchers/base.rb in aktion_test-0.1.2 vs lib/aktion_test/matchers/base.rb in aktion_test-0.2.0
- old
+ new
@@ -1,13 +1,45 @@
module AktionTest
module Matchers
class Base
+ def initialize
+ @matches = nil
+ end
+
+ def matches?(subject)
+ return @matches unless @matches.nil?
+ @subject = subject
+ @matches = !!perform_match!
+ end
+
def failure_message
- "Expected #{expectation}\n#{problem}"
+ raise "Called failure message before determining a match from #{caller[0]}" if @matches.nil?
+ raise "Called failure message while the match was positive from #{caller[0]}" if @matches
+ "Expected #{expectation}\n#{problems_for_should}\n"
end
def negative_failure_message
- "Did not expect #{expectation}"
+ raise "Called negative failure message before determining a match from #{caller[0]}" if @matches.nil?
+ raise "Called negative failure message while the match was unsucessful from #{caller[0]}" unless @matches
+ "Did not expect #{expectation}\n#{problems_for_should_not}\n"
+ end
+
+ protected
+
+ def expectation
+ "Override expectation to provide expectation details"
+ end
+
+ def problems_for_should
+ "Override problem_for_should to set problems in the failure message output."
+ end
+
+ def problems_for_should_not
+ "Override problem_for_should_not to set problems in the failure message output."
+ end
+
+ def perform_match!
+ raise "Override perform_match! with your custom matching logic. The subject is available through @subject"
end
end
end
end