Permalink
Browse files

fixed rspec.

  • Loading branch information...
1 parent e0bf1d8 commit 079752698824fc21b3c07b03028e75d9fd5f3611 @apotonick apotonick committed Apr 4, 2011
@@ -1,6 +1,2 @@
require 'test_xml'
require 'test_xml/spec/matchers.rb'
-
-# class Spec::Example::ExampleGroup
-# include TestXml::Spec
-# end
@@ -1,4 +1,5 @@
-require 'test_xml/spec/matchers/match_xml'
-require 'test_xml/spec/matchers/match_xml_structure'
-require 'test_xml/spec/matchers/exactly_match_xml_structure'
-require 'test_xml/spec/matchers/exactly_match_xml'
+require 'test_xml/matcher_methods'
+require 'test_xml/spec/matchers/contain_xml'
+require 'test_xml/spec/matchers/contain_xml_structure'
+require 'test_xml/spec/matchers/equal_xml_structure'
+require 'test_xml/spec/matchers/equal_xml'
@@ -1,13 +1,6 @@
-require 'rspec/matchers'
-
-RSpec::Matchers.define :match_xml do |expected|
+RSpec::Matchers.define :contain_xml do |expected|
match do |actual|
- subject = Nokogiri::XML::Document.parse(actual)
- pattern = Nokogiri::XML::Document.parse(expected)
-
- compare_values = true
-
- subject.match?(pattern, compare_values)
+ TestXml::MatcherMethods.xml_contain(actual, expected)
end
failure_message_for_should do |actual|
@@ -1,9 +1,6 @@
-RSpec::Matchers.define :match_xml_structure do |expected|
+RSpec::Matchers.define :contain_xml_structure do |expected|
match do |actual|
- subject = Nokogiri::XML::Document.parse(actual)
- pattern = Nokogiri::XML::Document.parse(expected)
-
- subject.match?(pattern)
+ TestXml::MatcherMethods.xml_structure_contain(actual, expected)
end
failure_message_for_should do |actual|
@@ -1,11 +1,6 @@
-RSpec::Matchers.define :exactly_match_xml do |expected|
+RSpec::Matchers.define :equal_xml do |expected|
match do |actual|
- subject = Nokogiri::XML::Document.parse(actual)
- pattern = Nokogiri::XML::Document.parse(expected)
-
- compare_values = true
-
- subject.match?(pattern, compare_values) && pattern.match?(subject, compare_values)
+ TestXml::MatcherMethods.xml_equal(actual, expected)
end
failure_message_for_should do |actual|
@@ -1,8 +1,6 @@
-RSpec::Matchers.define :exactly_match_xml_structure do |expected|
+RSpec::Matchers.define :equal_xml_structure do |expected|
match do |actual|
- subject = Nokogiri::XML::Document.parse(actual)
- pattern = Nokogiri::XML::Document.parse(expected)
- subject.match?(pattern) && pattern.match?(subject)
+ TestXml::MatcherMethods.xml_structure_equal(actual, expected)
end
failure_message_for_should do |actual|
@@ -1,54 +1,42 @@
+require 'test_xml/matcher_methods'
+
module TestXml
module TestUnit
module Assertions
-
- def parse_xml(subject, pattern)
- [Nokogiri::XML.parse(subject), Nokogiri::XML.parse(pattern)]
- end
-
-
def self.assertions_for(name, options)
define_method("assert_#{name}") do |subject, pattern|
- actual, expected = parse_xml(subject, pattern)
-
full_message = options[:message_for_should].gsub(/\<pattern\>/, pattern).gsub(/\<subject\>/, subject)
assert_block(full_message) do
- options[:matcher].call(actual, expected)
+ MatcherMethods.send(name, subject, pattern)
end
end
define_method("assert_not_#{name}") do |subject, pattern|
- actual, expected = parse_xml(subject, pattern)
-
full_message = options[:message_for_should_not].gsub(/\<pattern\>/, pattern).gsub(/\<subject\>/, subject)
assert_block(full_message) do
- !options[:matcher].call(actual, expected)
+ not MatcherMethods.send(name, subject, pattern)
end
end
end
-
+
assertions_for :xml_contain,
:message_for_should => "the xml:\n<subject>\nshould contain xml:\n<pattern>",
- :message_for_should_not => "the xml:\n<subject>\nshould not contain xml:\n<pattern> but it does",
- :matcher => Proc.new {|actual, expected| actual.match?(expected, true) }
+ :message_for_should_not => "the xml:\n<subject>\nshould not contain xml:\n<pattern> but it does"
assertions_for :xml_equal,
:message_for_should => "the xml:\n<subject>\nshould exactly match xml:\n<pattern>",
- :message_for_should_not => "the xml:\n<subject>\nshould not exactly match xml:\n<pattern> but it does",
- :matcher => Proc.new {|actual, expected| actual.match?(expected, true) && expected.match?(actual, true) }
+ :message_for_should_not => "the xml:\n<subject>\nshould not exactly match xml:\n<pattern> but it does"
assertions_for :xml_structure_contain,
:message_for_should => "the xml:\n<subject>\nshould match xml structure:\n<pattern>",
- :message_for_should_not => "the xml:\n<subject>\nshould not match xml structure:\n<pattern> but it does",
- :matcher => Proc.new {|actual, expected| actual.match?(expected)}
+ :message_for_should_not => "the xml:\n<subject>\nshould not match xml structure:\n<pattern> but it does"
assertions_for :xml_structure_equal,
:message_for_should => "the xml:\n<subject>\nshould exactly match xml structure:\n<pattern>",
- :message_for_should_not => "the xml:\n<subject>\nshould not exactly match xml structure:\n<pattern> but it does",
- :matcher => Proc.new {|actual, expected| actual.match?(expected) && expected.match?(actual) }
+ :message_for_should_not => "the xml:\n<subject>\nshould not exactly match xml structure:\n<pattern> but it does"
end
end
end
@@ -12,7 +12,7 @@
context "when xml is equal" do
it "should pass" do
- should match_xml(<<-XML)
+ should contain_xml(<<-XML)
<xml>
<one>1</one>
<two>2</two>
@@ -23,7 +23,7 @@
context "when xml has less elements" do
it "should pass" do
- should match_xml(<<-XML)
+ should contain_xml(<<-XML)
<xml>
<one>1</one>
</xml>
@@ -33,7 +33,7 @@
context "when xml structure is equal but elements have different content" do
it "should fail" do
- should_not match_xml(<<-XML)
+ should_not contain_xml(<<-XML)
<xml>
<one>4</one>
<two>5</two>
@@ -44,7 +44,7 @@
context "when xml has more elements" do
it "should fail" do
- should_not match_xml(<<-XML)
+ should_not contain_xml(<<-XML)
<xml>
<one>1</one>
<two>2</two>
@@ -67,7 +67,7 @@
}
it "should pass" do
- should match_xml(<<-XML)
+ should contain_xml(<<-XML)
<xml>
<errors>
<error>one</error>
@@ -12,7 +12,7 @@
context "when xml is equal" do
it "should pass" do
- should match_xml_structure(<<-XML)
+ should contain_xml_structure(<<-XML)
<xml>
<one>1</one>
<two>2</two>
@@ -23,7 +23,7 @@
context "when xml structure is equal but elements have different content" do
it "should pass" do
- should match_xml_structure(<<-XML)
+ should contain_xml_structure(<<-XML)
<xml>
<one>4</one>
<two>5</two>
@@ -34,7 +34,7 @@
context "when xml has less elements" do
it "should pass" do
- should match_xml_structure(<<-XML)
+ should contain_xml_structure(<<-XML)
<xml>
<one>1</one>
</xml>
@@ -44,7 +44,7 @@
context "when xml has more elements" do
it "should fail" do
- should_not match_xml_structure(<<-XML)
+ should_not contain_xml_structure(<<-XML)
<xml>
<one>1</one>
<two>2</two>
@@ -1,5 +1,7 @@
require 'spec_helper'
+# TODO: attributes are not matched.
+
describe "exactly_match_xml(xml)" do
subject {
<<-XML
@@ -12,7 +14,7 @@
context "when xml is equal with subject" do
it "should pass" do
- should exactly_match_xml(<<-XML)
+ should equal_xml(<<-XML)
<xml>
<one>1</one>
<two>2</two>
@@ -23,7 +25,7 @@
context "when xml structure is equal with subject but elements have different content" do
it "should fail" do
- should_not exactly_match_xml(<<-XML)
+ should_not equal_xml(<<-XML)
<xml>
<one>4</one>
<two>5</two>
@@ -34,7 +36,7 @@
context "when xml has less elements" do
it "should fail" do
- should_not exactly_match_xml(<<-XML)
+ should_not equal_xml(<<-XML)
<xml>
<one>1</one>
</xml>
@@ -44,7 +46,7 @@
context "when xml has more elements" do
it "should fail" do
- should_not exactly_match_xml(<<-XML)
+ should_not equal_xml(<<-XML)
<xml>
<one>1</one>
<two>2</two>
@@ -12,7 +12,7 @@
context "when xml structure is equal with subject" do
it "should pass" do
- should exactly_match_xml_structure(<<-XML)
+ should equal_xml_structure(<<-XML)
<xml>
<one/>
<two/>
@@ -23,7 +23,7 @@
context "when xml structure is equal with subject and elements have different content" do
it "should pass" do
- should exactly_match_xml_structure(<<-XML)
+ should equal_xml_structure(<<-XML)
<xml>
<one>4</one>
<two>5</two>
@@ -34,7 +34,7 @@
context "when xml has less elements" do
it "should fail" do
- should_not exactly_match_xml_structure(<<-XML)
+ should_not equal_xml_structure(<<-XML)
<xml>
<one/>
</xml>
@@ -44,7 +44,7 @@
context "when xml has more elements" do
it "should fail" do
- should_not exactly_match_xml_structure(<<-XML)
+ should_not equal_xml_structure(<<-XML)
<xml>
<one/>
<two/>
View
@@ -1,3 +1 @@
-#require 'rspec'
-
require 'test_xml/spec'
View
@@ -4,15 +4,15 @@ $:.unshift lib unless $:.include?(lib)
require 'test_xml/version'
Gem::Specification.new do |s|
- s.name = "test_xml"
- s.version = TestXml::VERSION
- s.author = "Pavel Gabriel"
- s.homepage = "http://github.com/alovak/test_xml"
- s.summary = "test_xml allows you to test xml with RSpec, Test::Unit, Cucumber"
- s.description = "test_xml allows you to test xml (match stucture and values) with RSpec, Test::Unit, Cucumber"
- s.email = "alovak@gmail.com"
+ s.name = "test_xml"
+ s.version = TestXml::VERSION
+ s.authors = ["Pavel Gabriel", "Nick Sutterer"]
+ s.homepage = "http://github.com/alovak/test_xml"
+ s.summary = "Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber."
+ s.description = "Test your XML with Test::Unit, MiniTest, RSpec, or Cucumber using handy assertions like #assert_xml_equal or #assert_xml_structure_contain."
+ s.email = ["alovak@gmail.com", "apotonick@gmail.com"]
s.require_path = "lib"
- s.has_rdoc = true
+ s.has_rdoc = true
s.extra_rdoc_files = ['README.rdoc']
s.rdoc_options = ['--main', 'README.rdoc']
@@ -24,5 +24,5 @@ Gem::Specification.new do |s|
s.add_development_dependency("rake")
s.add_development_dependency("rdoc")
- s.add_development_dependency("rspec-core")
+ s.add_development_dependency("rspec-core", ["~> 2.2"])
end

0 comments on commit 0797526

Please sign in to comment.