Report abuse

xpath.rb


			
# require 'ambition/adapters/xpath/select'

require 'xml/libxml'

module Ambition
  class XmlDocument
    include Ambition::API

    def initialize(xml)
      @doc = XML::Parser.string(xml).parse
    end
  end

  module Adapters
    module XPath
      class Base

      end

      class Select < Base

      end

      class Query

      end
    end
  end
end

Ambition::XmlDocument.extend Ambition::API
Ambition::XmlDocument.ambition_adapter = Ambition::Adapters::XPath

xpath_test.rb


			
require File.dirname(__FILE__) + '/../../helper'

require 'ambition/adapters/xpath'

context "An XPath adapter" do

  before do
    @xml = <<-EOX
      
        
          Adam Keys
          27
        
        
          Evan Phoenix
          27
        
      
    EOX
  end

  specify "performs a simple XPath query" do
    doc = Ambition::XmlDocument.new(@xml)
    node = doc.select { |n| n.id == '14' }
    node.find_first('name').should == 'Adam Keys'
  end
end