Created
October 30, 2011 19:45
-
-
Save tammersaleh/1326338 to your computer and use it in GitHub Desktop.
This file contains 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 "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 |
This file contains 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
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