1
我試圖測試我的葡萄API,但我在我的測試中收到400錯誤,但是當我運行測試應該測試的操作時,我得到201預期的HTTP響應。不知道這裏發生了什麼事。以下是特定的RSpec測試,但您可以通過GitHub上的工廠和實際的Grape API在hackcentral/hackcentral上查看整個項目。以下測試正在測試Alpha :: Applications上的POST創建操作。 (APP/API /阿爾法/ applications.rb)葡萄軌RSpec測試返回400
describe 'POST #create' do
before :each do
@oauth_application = FactoryGirl.build(:oauth_application)
@token = Doorkeeper::AccessToken.create!(:application_id => @oauth_application.id, :resource_owner_id => user.id)
end
context "with valid attributes" do
it "creates a new application" do
expect{
post "http://api.vcap.me:3000/v1/applications?access_token=#{@token.token}", application: FactoryGirl.attributes_for(:application), :format => :json
} .to change(Application, :count).by(1)
end
it "creates a new application, making sure response is #201" do
post "http://api.vcap.me:3000/v1/applications", application: FactoryGirl.attributes_for(:application), :format => :json, :access_token => @token.token
response.status.should eq(201)
end
end
end