Permalink
Browse files

Added basic error handling for service related errors

  • Loading branch information...
1 parent 5957a3f commit 9d0ea700f277086dff72ace8c329a55a99b8e22c @visoft committed May 16, 2012
Showing with 122 additions and 90 deletions.
  1. +13 −0 features/error_handling.feature
  2. +22 −18 features/step_definitions/service_steps.rb
  3. +87 −72 lib/ruby_odata/service.rb
@@ -0,0 +1,13 @@
+Feature: Error handling
+ In order to assist debugging
+ As a user
+ I want more debug information when an error occurs communicating with the server
+
+Background:
+ Given a HTTP ODataService exists
+ And blueprints exist for the service
+
+Scenario: Violate a data type conversion (empty string to decimal)
+ Given I call "AddToProducts" on the service with a new "Product" object with Price: ""
+ When I save changes it should throw an exception with message containing "HTTP Error 400"
+
@@ -30,19 +30,19 @@
@service = OData::Service.new(BASICAUTH_URL, { :username => username, :password => password })
end
-Given /^a HTTP BasicAuth ODataService exists using username "([^\"]*)" and password "([^\"]*)" it should throw an exception with message "([^\"]*)"$/ do |username, password, msg|
+Given /^a HTTP BasicAuth ODataService exists using username "([^\"]*)" and password "([^\"]*)" it should throw an exception with message "([^\"]*)"$/ do |username, password, msg|
lambda { @service = OData::Service.new(BASICAUTH_URL, { :username => username, :password => password }) }.should raise_error(msg)
end
-Given /^a HTTP BasicAuth ODataService exists it should throw an exception with message containing "([^\"]*)"$/ do |msg|
+Given /^a HTTP BasicAuth ODataService exists it should throw an exception with message containing "([^\"]*)"$/ do |msg|
lambda { @service = OData::Service.new(BASICAUTH_URL) }.should raise_error(/#{msg}.*/)
end
Given /^a HTTPS BasicAuth ODataService exists it should throw an exception with message containing "([^"]*)"$/ do |msg|
lambda { @service = OData::Service.new(HTTPS_BASICAUTH_URL) }.should raise_error(/#{msg}.*/)
end
-Given /^a HTTP BasicAuth ODataService exists it should throw an exception with message "([^\"]*)"$/ do |msg|
+Given /^a HTTP BasicAuth ODataService exists it should throw an exception with message "([^\"]*)"$/ do |msg|
lambda { @service = OData::Service.new(BASICAUTH_URL) }.should raise_error(msg)
end
@@ -55,7 +55,7 @@
end
Then /^the result should be "([^\"]*)"$/ do |result|
- @service_result.should eq result
+ @service_result.should eq result
end
Then /^the integer result should be ([^\"]*)$/ do |result|
@@ -127,13 +127,13 @@
end
Then /^the method "([^\"]*)" on the result should be of type "([^\"]*)"$/ do |method, type|
- result = @service_result.send(method.to_sym)
+ result = @service_result.send(method.to_sym)
result.class.to_s.should eq type
end
Given /^I call "([^\"]*)" on the service with a new "([^\"]*)" object(?: with (.*))?$/ do |method, object, fields|
fields_hash = parse_fields_string(fields)
-
+
obj = object.constantize.send(:make, fields_hash)
@service.send(method.to_sym, obj)
end
@@ -172,6 +172,10 @@
lambda { @service.send(method.to_sym, obj) }.should raise_error(msg)
end
+When /^I save changes it should throw an exception with message containing "([^"]*)"$/ do |msg|
+ lambda { @service.save_changes }.should raise_error(/#{msg}.*/)
+end
+
Then /^no "([^\"]*)" should exist$/ do |collection|
@service.send(collection)
results = @service.execute
@@ -180,51 +184,51 @@
Then /^the primitive results should be:$/ do |table|
# table is a Cucumber::Ast::Table
- values = table.hashes
+ values = table.hashes
result_table = Cucumber::Ast::Table.new(values)
table.diff!(result_table)
end
Then /^the result should be:$/ do |table|
# table is a Cucumber::Ast::Table
-
+
fields = table.hashes[0].keys
-
+
# Build an array of hashes so that we can compare tables
results = []
-
+
@service_result.each do |result|
obj_hash = Hash.new
fields.each do |field|
obj_hash[field] = result.send(field)
end
results << obj_hash
end
-
+
result_table = Cucumber::Ast::Table.new(results)
-
+
table.diff!(result_table)
end
Then /^the save result should be:$/ do |table|
# table is a Cucumber::Ast::Table
-
+
fields = table.hashes[0].keys
-
+
# Build an array of hashes so that we can compare tables
results = []
-
+
@saved_result.each do |result|
obj_hash = Hash.new
fields.each do |field|
obj_hash[field] = result.send(field)
end
results << obj_hash
end
-
+
result_table = Cucumber::Ast::Table.new(results)
-
- table.diff!(result_table)
+
+ table.diff!(result_table)
end
Then /^a class named "([^\"]*)" should exist$/ do |klass_name|
Oops, something went wrong.

0 comments on commit 9d0ea70

Please sign in to comment.