lib/soaspec/matchers.rb in soaspec-0.0.8 vs lib/soaspec/matchers.rb in soaspec-0.0.9

- old
+ new

@@ -1,8 +1,15 @@ require_relative 'hash_methods' +def xpath_for(param) + # TODO: look a using Savon's xpath rather than converting to Nokogiri + result = param[:exchange].xml_doc.at_xpath(param[:xpath], Soaspec::Environment.api_handler.namespaces) + raise 'No value at Xpath' unless result + result +end + RSpec::Matchers.define :contain_value do |expected| match do |actual| expect(actual.response.body.include_value?(expected)).to be true end @@ -19,16 +26,17 @@ failure_message do |actual| "expected that #{actual.response.body} would contain key #{expected}" end end -RSpec::Matchers.define :have_element_at_xpath do |expected| +RSpec::Matchers.define :have_element_at_xpath do |xpath| match do |exchange| - expect(exchange.xml_doc.at_xpath(expected, Soaspec::Environment.api_handler.namespaces).content).not_to be_empty + expect(xpath_for(exchange: exchange, xpath: xpath).content).not_to be_empty end end RSpec::Matchers.define :have_xpath_value do |expected_hash| match do |exchange| - expect(exchange.xml_doc.at_xpath(expected_hash.keys.first, Soaspec::Environment.api_handler.namespaces).content).to eq expected_hash.values.first + expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring + expect(xpath_for(exchange: exchange, xpath: expected_hash.keys.first).content).to eq expected_hash.values.first end end \ No newline at end of file