2014-09-10 03:43:27 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
module StringsSpec
|
|
|
|
module Parsing
|
|
|
|
|
2014-09-19 21:44:22 +00:00
|
|
|
# Cleans up the Registry and gives YARD some source code
|
|
|
|
# to generate documentation for
|
2014-09-10 03:43:27 +00:00
|
|
|
def parse(string, parser = :ruby)
|
2014-09-30 21:02:31 +00:00
|
|
|
YARD::Registry.clear
|
2014-09-10 03:43:27 +00:00
|
|
|
YARD::Parser::SourceParser.parse_string(string, parser)
|
|
|
|
end
|
|
|
|
|
2014-09-19 21:44:22 +00:00
|
|
|
# A custom matcher that allows us to compare aspects of a
|
|
|
|
# Code Objects to the specified values. This gives us a
|
|
|
|
# simplified way to ensure that the Code Object added to the
|
|
|
|
# Registry is what we expect when testing handlers
|
2014-09-10 03:43:27 +00:00
|
|
|
RSpec::Matchers.define :document_a do |arguments|
|
|
|
|
match do |actual|
|
|
|
|
compare_values(actual).empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
failure_message do |actual|
|
|
|
|
mismatches = compare_values(actual)
|
|
|
|
mismatches.collect do |key, value|
|
|
|
|
"Expected #{key} to be <#{value[1]}>, but got <#{value[0]}>."
|
|
|
|
end.join("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def compare_values(actual)
|
|
|
|
mismatched_arguments = {}
|
|
|
|
expected.each do |key, value|
|
|
|
|
actual_value = actual.send(key)
|
|
|
|
if actual_value != value
|
|
|
|
mismatched_arguments[key] = [actual_value, value]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
mismatched_arguments
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|