spec/support/matchers.rb in ruby_speech-0.4.0 vs spec/support/matchers.rb in ruby_speech-0.5.0

- old
+ new

@@ -1,59 +1,20 @@ def be_a_valid_grxml_document - GRXMLMatcher.new + SpeechDocMatcher.new 'GRXML', GRXML_SCHEMA end def be_a_valid_ssml_document - SSMLMatcher.new + SpeechDocMatcher.new 'SSML', SSML_SCHEMA end -class SSMLMatcher - attr_reader :subject +class SpeechDocMatcher + attr_reader :subject, :type, :schema - def subject=(s) - if s.is_a? Nokogiri::XML::Document - @subject = s - else - doc = Nokogiri::XML::Document.new - doc << s - @subject = doc - end + def initialize(type, schema) + @type, @schema = type, schema end - def failure_message - " expected #{subject} to be a valid SSML document\n#{errors}" - end - - def negative_failure_message - " expected #{subject} not to be a valid SSML document" - end - - def description - "to be a valid SSML document" - end - - def matches?(s) - self.subject = s - SSML_SCHEMA.valid? subject - end - - def does_not_match?(s) - !matches? s - end - - private - - def errors - SSML_SCHEMA.validate(subject).map(&:message).join "\n" - end - -end - - -class GRXMLMatcher - attr_reader :subject - def subject=(s) if s.is_a? Nokogiri::XML::Document @subject = s else doc = Nokogiri::XML::Document.new @@ -61,32 +22,31 @@ @subject = doc end end def failure_message - " expected #{subject} to be a valid GRXML document\n#{errors}" + " expected #{subject} to be a valid #{type} document\n#{errors}" end def negative_failure_message - " expected #{subject} not to be a valid GRXML document" + " expected #{subject} not to be a valid #{type} document" end def description - "to be a valid GRXML document" + "to be a valid #{type} document" end def matches?(s) self.subject = s - GRXML_SCHEMA.valid? subject + schema.valid? subject end def does_not_match?(s) !matches? s end private - def errors - GRXML_SCHEMA.validate(subject).map(&:message).join "\n" - end - + def errors + schema.validate(subject).map(&:message).join "\n" + end end