lib/soaspec/matchers.rb in soaspec-0.0.30 vs lib/soaspec/matchers.rb in soaspec-0.0.31

- old
+ new

@@ -1,53 +1,51 @@ require_relative 'hash_methods' -require_relative 'xpath_not_found' +require_relative 'not_found_errors' # TODO: Mathcers are specific to SOAP. Make generic for REST and others by using actual.api_class # Whether response has any element with the provided value RSpec::Matchers.define :contain_value do |expected| match do |actual| expect(actual.api_class.include_value?(actual.response, expected)).to be true end - # TODO: Fix this for REST failure_message do |actual| - "expected that #{actual.response.body} would contain value #{expected}" + "expected that #{actual.api_class.response_body(actual.response, format: :hash)} would contain value #{expected}" end end # Whether substring exists in body of response (more general than above) RSpec::Matchers.define :include_in_body do |expected| match do |actual| expect(actual.api_class.include_in_body?(actual.response, expected)).to be true end - # TODO: Fix this for REST failure_message do |actual| - "expected that #{actual.response.body.to_xml} would contain value #{expected}" + "expected that #{actual.api_class.response_body(actual.response, format: :xml)} would contain value #{expected}" end end # Whether expected element exists in body RSpec::Matchers.define :contain_key do |expected| match do |actual| - expect(actual.response.body.include_key?(expected)).to be true + expect(actual.api_class.include_key?(actual.response, expected)).to be true end failure_message do |actual| - "expected that #{actual.response.body} would contain key #{expected}" + "expected that #{actual.api_class.response_body(actual.response, format: :hash)} would contain key #{expected}" end end # Whether an element exists at expected xpath RSpec::Matchers.define :have_element_at_xpath do |xpath| match do |exchange| - expect { exchange[xpath] }.to_not raise_error + expect { exchange[xpath] }.to_not raise_error # Error will be raised if XPath returns no value end failure_message do |actual| - "expected that #{actual.response.to_xml} would have element at xpath '#{xpath}'" + "expected that #{actual.api_class.response_body(actual.response, format: :xml)} would have element at xpath '#{xpath}'" end end # 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') \ No newline at end of file