Skip to content

Instantly share code, notes, and snippets.

@tammersaleh
Created October 30, 2011 19:45
Show Gist options
  • Save tammersaleh/1326338 to your computer and use it in GitHub Desktop.
Save tammersaleh/1326338 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe "given some agents" do
before do
create(:agent, name: "Agent 1")
create(:agent, name: "Agent 2")
end
describe "GET /agents.json", :as => :api do
its(:status) { should == 200 }
its(:content_type) { should == "application/json" }
describe "JSON response" do
subject { response.json_body }
it { should include(name: "Agent 1") }
it { should include(name: "Agent 2") }
end
end
end
shared_context "API Controller", :as => :api do
before do
regexp = Regexp.new("(GET|PUT|POST|DELETE|HEAD) ([^ ]+)")
if match = regexp.match(example.full_description)
http_method = match[1].downcase
request_path = match[2]
send(http_method, request_path, params, environment)
else
raise "#{example.full_description.inspect} doesn't match #{regexp.inspect}"
end
end
let(:params) { {} } # override in tests
let(:environment) { {} } # override in tests
subject {response}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment