Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial commit

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

0 comments on commit c05d7fc

Please sign in to comment.
Something went wrong with that request. Please try again.