我已经浏览了网页,但是,唉,我似乎无法让Rspec正确发送内容类型,所以我可以测试我的JSON API.我正在使用RABL gem用于模板,Rails 3.0.11和Ruby 1.9.2-p180.
我的卷曲输出,工作正常(应该是401,我知道):
mrsnuggles:tmp gaahrdner$ curl -i -H "Accept: application/json" -X POST -d @bleh http://localhost:3000/applications
HTTP/1.1 403 Forbidden
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
X-Ua-Compatible: IE=Edge
X-Runtime: 0.561638
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Date: Tue, 06 Mar 2012 01:10:51 GMT
Content-Length: 74
Connection: Keep-Alive
Set-Cookie: _session_id=8e8b73b5a6e5c95447aab13dafd59993; path=/; HttpOnly
{"status":"error","message":"You are not authorized to access this page."}
Run Code Online (Sandbox Code Playgroud)
我的一个测试用例中的示例:
describe ApplicationsController do
render_views
disconnect_sunspot
let(:application) { Factory.create(:application) }
subject { application }
context "JSON" do
describe "creating a new application" do
context …Run Code Online (Sandbox Code Playgroud)