lib/soaspec/matchers.rb in soaspec-0.2.3 vs lib/soaspec/matchers.rb in soaspec-0.2.4

- old
+ new

@@ -24,11 +24,13 @@ end end # Whether an element exists at expected xpath RSpec::Matchers.define :have_element_at_path do |xpath| - match do |exchange| + match do |object| + # Object like `response` returns the Exchange object from which a path can be obtained + exchange = object.respond_to?(:exchange) ? object.exchange : object expect { exchange[xpath] }.to_not raise_error # Error will be raised if Path returns no value end # TODO: Would be better to print failure message failure_message do |actual| @@ -40,19 +42,22 @@ RSpec::Matchers.alias_matcher :contain_key, :have_element_at_path # Whether an element at xpath (defined by key) has value (defined by value). # @param [Hash] expected_hash Xpath => Value pair (e.g. '//xmlns:GetWeatherResult' => 'Data Not Found') RSpec::Matchers.define :have_xpath_value do |expected_hash| - match do |exchange| + match do |object| + # Object like `response` returns the Exchange object from which a path can be obtained + exchange = object.respond_to?(:exchange) ? object.exchange : object expected_hash = Hash[*expected_hash.flatten] if expected_hash.is_a?(Array) # For some reason Array was occuring expect(exchange[expected_hash.keys.first]).to eq expected_hash.values.first end failure_message do |actual| "expected that xpath '#{expected_hash.keys.first}' has value '#{expected_hash.values.first}' but was '#{actual[expected_hash.keys.first]}'" end - end + +RSpec::Matchers.alias_matcher :have_jsonpath_value, :have_xpath_value RSpec::Matchers.define :be_found do match do |exchange| expect(exchange.exchange_handler.found?(exchange.response)).to be true