0
+ # A custom RSpec example group which assists with the testing of the
0
+ # behaviors of the single rules rather than the default root.
0
+ # Using it as the default example group:
0
+ # require 'treetop/parser_example_group'
0
+ # Spec::Example::ExampleGroupFactory.default(Treetop::ParserExampleGroup)
0
+ # Using it for a subset of specs:
0
+ # require 'treetop/parser_example_group'
0
+ # Spec::Example::ExampleGroupFactory.register(:my_parser, Treetop::ParserExampleGroup)
0
+ class ParserExampleGroup < Spec::Example::ExampleGroup
0
+ attr_reader :default_klass, :default_root
0
+ def parse_from(klass, root = nil)
0
+ @default_klass, @default_root = klass, root
0
+ def parse(input, options = {})
0
+ @parser = (options[:klass] || self.class.default_klass).new
0
+ if root = (options[:root] || self.class.default_root)
0
+ unless options[:consume_all_input].nil?
0
+ parser.consume_all_input = options.delete(:consume_all_input)
0
+ result = parser.parse(input, options)
0
+ yield result if block_given?
0
+ def initialize(parser, value)
0
+ @parser, @value = parser, value
0
+ parsed? && correct_value?
0
+ @result.value == @value
0
+ "expected input to be parsed\nfailure_reason: #{@parser.failure_reason}"
0
+ "expected: #{@value.inspect},\n got: #{@result.value.inspect}"
0
+ def negative_failure_message
0
+ "expected input not to be parsed"
0
+ def be_parsed_and_eql(value)
0
+ BeParsedAndEql.new(parser, value)
0
+ class HaveFailedParsingBecause
0
+ def initialize(parser, failure_reason)
0
+ @parser, @failure_reason = parser, failure_reason
0
+ not_parsed? && correct_reason?
0
+ @parser.failure_reason == @failure_reason
0
+ "expected input not to be parsed because #{@failure_reason}"
0
+ "failure message was incorrect\nexpected: #{@failure_reason},\n got: #{@parser.failure_reason}"
0
+ def negative_failure_message
0
+ raise RspecCommandError, "Cannot use this like so"
0
+ def have_failed_parsing_because(failure_message)
0
+ HaveFailedParsingBecause.new(parser, failure_message)
Comments
No one has commented yet.