Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit c05d7fcbe634588f8f0ea20e16f5497fdc5a7f04 0 parents
Dan Carper authored
6 .gitignore
@@ -0,0 +1,6 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+*.sw?
+.DS_STORE
6 Gemfile
@@ -0,0 +1,6 @@
+source "http://rubygems.org"
+
+gem 'nokogiri'
+
+# Specify your gem's dependencies in rspec-xml.gemspec
+gemspec
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
7 lib/rspec-xml.rb
@@ -0,0 +1,7 @@
+require "rspec-xml/version"
+
+module Rspec
+ module Xml
+ # Your code goes here...
+ end
+end
5 lib/rspec-xml/version.rb
@@ -0,0 +1,5 @@
+module Rspec
+ module Xml
+ VERSION = "0.0.1"
+ end
+end
6 lib/rspec.rb
@@ -0,0 +1,6 @@
+Bundler.require
+require 'rspec/xml_matchers'
+
+RSpec.configure do |config|
+ config.include XMLMatchers
+end
30 lib/rspec/xml_matchers.rb
@@ -0,0 +1,30 @@
+module XMLMatchers
+ class HaveXPath
+
+ def initialize(xpath)
+ @xpath = xpath
+ end
+
+ def with_text(text)
+ @text = text
+ self
+ end
+
+ def matches?(xml)
+ ::Nokogiri::XML(xml).xpath(@xpath).text == @text
+ end
+
+ def failure_message_for_should
+ "expected #{@xpath} to exist"
+ end
+
+ def failure_message_for_should_not
+ "expected #{@xpath} to not exist"
+ end
+ end
+
+ def have_xpath(xpath)
+ HaveXPath.new(xpath)
+ end
+end
+
26 rspec-xml.gemspec
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "rspec-xml/version"
+
+Gem::Specification.new do |s|
+ s.name = "rspec-xml"
+ s.version = Rspec::Xml::VERSION
+ s.authors = ["Dan Carper"]
+ s.email = ["dcarper@dreamagile.com"]
+ s.homepage = ""
+ s.summary = %q{Spec your XML}
+ s.description = %q{One simple matcher for now}
+
+ s.rubyforge_project = "rspec-xml"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ s.add_development_dependency 'rspec'
+ s.add_development_dependency 'bundler'
+
+ s.add_runtime_dependency 'rspec'
+ s.add_runtime_dependency 'nokogiri'
+end
1  spec/spec_helper.rb
@@ -0,0 +1 @@
+require File.expand_path('../../lib/rspec', __FILE__)
19 spec/xml_matchers_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe XMLMatchers do
+ describe '#have_xpath' do
+ it 'should pass if the xpath exists containing the supplied text' do
+ "<node>HAI</node>".should have_xpath('/node').with_text('HAI')
+ end
+
+ it "should fail if the xpath does not exist" do
+ lambda { "<node>HAI</node>".should have_xpath('/ne').with_text('HAI')}.
+ should raise_error(RSpec::Expectations::ExpectationNotMetError)
+ end
+
+ it 'should fail if the xpath does not contain the supplied text' do
+ lambda { "<node>HAI</node>".should have_xpath('/ne').with_text('HI')}.
+ should raise_error(RSpec::Expectations::ExpectationNotMetError)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.