module Rattler::Util::ParserSpecHelper
ParserSpecHelper
defines a fluent interface for writing RSpec examples for parsers.
@example
require 'my_awesome_language/my_awesome_parser' require 'rattler/util/parser_spec_helper' describe MyAwesomeLanguage::MyAwesomeParser do include Rattler::Util::ParserSpecHelper describe '#match(:var_name)' do it 'recognizes variable names' do matching(' fooBar ').as(:var_name).should result_in('fooBar').at(7) end it 'rejects non-variables' do matching(' 42 ').as(:var_name).should fail.with_message('variable name expected') end end end
Public Instance Methods
matching(source)
click to toggle source
Return a match result to be matched using result_in or fail
matching(source).as(rule_name) matching(source).as(rule_name).from(pos)
# File lib/rattler/util/parser_spec_helper.rb, line 42 def matching(source) Matching.new(parser(source)) end
parsing(source)
click to toggle source
Return a parse result to be matched using result_in or fail
parsing(source) parsing(source).from(pos)
# File lib/rattler/util/parser_spec_helper.rb, line 33 def parsing(source) Parsing.new(parser(source)) end
Private Instance Methods
parser(source)
click to toggle source
# File lib/rattler/util/parser_spec_helper.rb, line 48 def parser(source) (self.respond_to?(:parser_class) ? parser_class : described_class).new(source) end