Sha256: 695ddf2377849b3a509df8fed8f2a1fe34a5e7081738a2aae3c722d3b01e9785

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

def be_a_valid_grxml_document
  GRXMLMatcher.new
end

def be_a_valid_ssml_document
  SSMLMatcher.new
end

class SSMLMatcher
  attr_reader :subject

  def subject=(s)
    if s.is_a? Nokogiri::XML::Document
      @subject = s
    else
      doc = Nokogiri::XML::Document.new
      doc << s
      @subject = doc
    end
  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
      doc << s
      @subject = doc
    end
  end

  def failure_message
    " expected #{subject} to be a valid GRXML document\n#{errors}"
  end

  def negative_failure_message
    " expected #{subject} not to be a valid GRXML document"
  end

  def description
    "to be a valid GRXML document"
  end

  def matches?(s)
    self.subject = s
    GRXML_SCHEMA.valid? subject
  end

  def does_not_match?(s)
    !matches? s
  end

  private

    def errors
      GRXML_SCHEMA.validate(subject).map(&:message).join "\n"
    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby_speech-0.4.0 spec/support/matchers.rb
ruby_speech-0.3.4 spec/support/matchers.rb
ruby_speech-0.3.3 spec/support/matchers.rb
ruby_speech-0.3.2 spec/support/matchers.rb
ruby_speech-0.3.1 spec/support/matchers.rb
ruby_speech-0.3.0 spec/support/matchers.rb