diff --git a/spec/oga/css/transformer/classes_spec.rb b/spec/oga/css/transformer/classes_spec.rb index ae4a5d4..d95df09 100644 --- a/spec/oga/css/transformer/classes_spec.rb +++ b/spec/oga/css/transformer/classes_spec.rb @@ -2,34 +2,12 @@ require 'spec_helper' describe Oga::CSS::Transformer do context 'classes' do - before do - @transformer = described_class.new - end - example 'convert a class node without a node test' do - @transformer.process(parse_css('.y')).should == s( - :axis, - 'child', - s( - :test, - nil, - '*', - s(:eq, s(:axis, 'attribute', s(:test, nil, 'class')), s(:string, 'y')) - ) - ) + transform_css('.y').should == parse_xpath('*[@class="y"]') end example 'convert a class node with a node test' do - @transformer.process(parse_css('x.y')).should == s( - :axis, - 'child', - s( - :test, - nil, - 'x', - s(:eq, s(:axis, 'attribute', s(:test, nil, 'class')), s(:string, 'y')) - ) - ) + transform_css('x.y').should == parse_xpath('x[@class="y"]') end end end diff --git a/spec/support/parsing.rb b/spec/support/parsing.rb index dfc9b3d..1015cb5 100644 --- a/spec/support/parsing.rb +++ b/spec/support/parsing.rb @@ -89,5 +89,17 @@ module Oga rescue Racc::ParseError => error return error.message end + + ## + # Parses and transforms a CSS AST into an XPath AST. + # + # @param [String] css + # @return [AST::Node] + # + def transform_css(css) + ast = parse_css(css) + + return Oga::CSS::Transformer.new.process(ast) + end end # ParsingHelpers end # Oga