lib/soaspec/matchers.rb in soaspec-0.3.2 vs lib/soaspec/matchers.rb in soaspec-0.3.3

- old
+ new

@@ -23,23 +23,24 @@ failure_message do |actual| "expected that #{actual.exchange_handler.response_body(actual.response, format: :raw)} would contain value #{expected}" end end -# Whether an element exists at expected xpath -RSpec::Matchers.define :have_element_at_path do |xpath| +# Whether an element exists at expected path +RSpec::Matchers.define :have_element_at_path do |path| 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 + exchange.element? path # [xpath] + # 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 |object| # Object like `response` returns the Exchange object from which a path can be obtained exchange = object.respond_to?(:exchange) ? object.exchange : object - "expected that #{exchange.exchange_handler.response_body(exchange.response, format: :raw)} would have element at path '#{xpath}'" + "expected that #{exchange.exchange_handler.response_body(exchange.response, format: :raw)} would have element at path '#{path}'" end end RSpec::Matchers.alias_matcher :have_element_at_xpath, :have_element_at_path RSpec::Matchers.alias_matcher :contain_key, :have_element_at_path @@ -74,10 +75,9 @@ # Record response first time this is run. It will fail. Next time, compare it # is the same # @param [Symbol] format Format to save the baseline as. Default is :raw. Use :hash # to store as hash which will ignore order in comparison RSpec::Matchers.define :match_baseline do |format = :raw| - match do |exchange| Soaspec::Baseline.new(exchange, format).matches? end failure_message do |exchange|