Skip to content

Instantly share code, notes, and snippets.

@xslim
Created October 19, 2012 14:09
Show Gist options
  • Save xslim/3918405 to your computer and use it in GitHub Desktop.
Save xslim/3918405 to your computer and use it in GitHub Desktop.
RSpec to test remote API
require "spec_helper"
describe "Events" do
it "gets events and checks id" do
get '/events.json'
response.status.should be(200)
ap json_response.first
json_response.each { |e| e.should have_key 'id' }
end
end
# Test it: rspec spec/request/events_spec.rb
source :rubygems
group :test do
gem "rspec"
gem "remote_http_testing"
# Beautifying
gem 'awesome_print'
end
require "rubygems"
require "bundler/setup"
require "rspec"
require "remote_http_testing"
require 'ap'
# Add the 'spec' path in the load path
spec_dir = File.dirname(__FILE__)
$LOAD_PATH.unshift(spec_dir)
# Require all ruby files in the 'support' folder
Dir[File.join(spec_dir, "support/**/*.rb")].each {|f| require f}
module RemoteHttpTesting
def server
# What server we are testing
"http://events.dev"
end
# Override for nicer compatibility
def response
last_response
end
end
# Override for nicer compatibility
module Net
class HTTPResponse
def status
self.code.to_i
end
end
end
RSpec.configure do |config|
config.include RemoteHttpTesting
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment