使用HTTP post请求的Rspec测试在本地传递,但在CI服务器上失败

时间:2015-01-21 08:08:08

标签: ruby-on-rails rspec http-post codeship

我有一个Rspec测试,发出POST请求并发送一个标头,因为需要身份验证:

it 'creates a client for an organization if none exists' do
  VCR.use_cassette('create_client') do
    post "/organizations/#{@organization.id}/clients", nil, { 'TOKEN' => @token }

    expect(last_response.status).to be(201)
    expect(json_response).to be_a(Hash)
    expect(json_response["organization_id"]).to eq(@organization.id)
    expect(json_response.keys).to include('auth_token')
   end
   expect(@organization.client).to_not be_nil
end

当我在本地计算机上运行测试时,这会毫无问题地通过,但会在CI服务器上失败(在这种情况下为Codeship):

Failure/Error: post "/organizations/#{@organization.id}/clients", nil, { 'TOKEN' => @token }
MyModule::MyClass::Errors::InvalidOptionError:
  bad URI(is not URI?):

当我从post请求中删除标题部分时,测试显然会失败,因为标记头是必需的,但是post请求将没有错误。

为什么会发生这种情况?我很感激任何意见。

1 个答案:

答案 0 :(得分:0)

原来这是Elasticsearch on Codeship的一个问题。