1

I am trying to test my Grape API, but I am receiving a 400 error in my tests, but when I run the action the test is supposed to test, I get a 201 HTTP response as expected. Not sure what is going on here. Below is the specific RSpec test, but you can view the whole project with the factories and the actual Grape API on GitHub at hackcentral/hackcentral. The test below is testing the POST create action on Alpha::Applications. (app/api/alpha/applications.rb)

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
maclover7
  • 137
  • 1
  • 11

1 Answers1

0

I don't understand why are you testing http://api.vcap.me an not localhost?

You usually test the app on the local enviroment. And this is not the right why to test if the server is working either.

Here is an example of how your test should look like. https://github.com/dblock/grape-on-rails/blob/master/spec/api/ping_spec.rb from an example project

Spike886
  • 609
  • 8
  • 23