Permalink
Browse files

Factor out response readers

  • Loading branch information...
purp committed Jun 22, 2011
1 parent 70ee1b1 commit 0a530f717b3809701e73058ee51157e0b79b828d
Showing with 11 additions and 3 deletions.
  1. +11 −3 spec/spec_helper.rb
View
@@ -7,12 +7,20 @@
require 'fake_name_generator'
-fixtures = File.dirname(File.expand_path(__FILE__)) + "/fixtures"
+FIXTURES = File.dirname(File.expand_path(__FILE__)) + "/fixtures"
+
+def valid_api_body
+ File.read("#{FIXTURES}/VALID_API_KEY.json")
+end
+
+def invalid_api_body
+ File.read("#{FIXTURES}/INVALID_API_KEY.xml")
+end
FakeWeb.allow_net_connect = false
-FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=VALID_API_KEY]i, :body => File.read("#{fixtures}/VALID_API_KEY.json"), :content_type => 'text/json', :status => ['200', 'OK'])
-FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=INVALID_API_KEY]i, :body => File.read("#{fixtures}/INVALID_API_KEY.xml"), :content_type => 'application/xml', :status => ["403", "Forbidden"])
+FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=VALID_API_KEY]i, :body => valid_api_body, :content_type => 'text/json', :status => ['200', 'OK'])
+FakeWeb.register_uri(:get, %r[http://svc\.webservius\.com/v1/CorbanWork/fakename\?(.*&|)wsvKey=INVALID_API_KEY]i, :body => invalid_api_body, :content_type => 'application/xml', :status => ["403", "Forbidden"])
RSpec.configure do |config|
end

0 comments on commit 0a530f7

Please sign in to comment.