Created
October 19, 2012 14:09
-
-
Save xslim/3918405 to your computer and use it in GitHub Desktop.
RSpec to test remote API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
group :test do | |
gem "rspec" | |
gem "remote_http_testing" | |
# Beautifying | |
gem 'awesome_print' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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