lib/soaspec/matchers.rb in soaspec-0.0.19 vs lib/soaspec/matchers.rb in soaspec-0.0.20
- old
+ new
@@ -1,40 +1,41 @@
-
-require_relative 'hash_methods'
-
-RSpec::Matchers.define :contain_value do |expected|
- match do |actual|
- expect(actual.response.body.include_value?(expected)).to be true
- end
-
- failure_message do |actual|
- "expected that #{actual.response.body} would contain value #{expected}"
- end
-end
-
-RSpec::Matchers.define :contain_key do |expected|
- match do |actual|
- expect(actual.response.body.include_key?(expected)).to be true
- end
-
- failure_message do |actual|
- "expected that #{actual.response.body} would contain key #{expected}"
- end
-end
-
-RSpec::Matchers.define :have_element_at_xpath do |xpath|
- match do |exchange|
- expect(exchange[xpath]).not_to be_empty
- end
-end
-
-RSpec::Matchers.define :have_xpath_value do |expected_hash|
- match do |exchange|
- 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
-
+
+require_relative 'hash_methods'
+require_relative 'xpath_not_found'
+
+RSpec::Matchers.define :contain_value do |expected|
+ match do |actual|
+ expect(actual.response.body.include_value?(expected)).to be true
+ end
+
+ failure_message do |actual|
+ "expected that #{actual.response.body} would contain value #{expected}"
+ end
+end
+
+RSpec::Matchers.define :contain_key do |expected|
+ match do |actual|
+ expect(actual.response.body.include_key?(expected)).to be true
+ end
+
+ failure_message do |actual|
+ "expected that #{actual.response.body} would contain key #{expected}"
+ end
+end
+
+RSpec::Matchers.define :have_element_at_xpath do |xpath|
+ match do |exchange|
+ expect { exchange[xpath] }.to_not raise_error NoElementAtXpath
+ end
+end
+
+RSpec::Matchers.define :have_xpath_value do |expected_hash|
+ match do |exchange|
+ 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
\ No newline at end of file