The Crystal Programming Language Forum

Where should I put my integration test?

I have a web API which I want to do integration test against it something simple like this:

describe "POST /object/table_name" do
  it "POST a table json and make a table" do
    data = %({"name": "string", "att": "string"})
    response = HTTP::Client.post("127.0.0.1:5800/object/movie", HTTP::Headers{"User-Agent" => "Crystal"},data)
    response.body.should eq "DB::ExecResult(@rows_affected=0, @last_insert_id=0)"
  end
end

should I put in the spec file?

There isn’t really a set way to handle this since the Spec module doesn’t really try to tell them apart. However I think you have some options:

  1. Make use of Tagging Specs and tag your integration tests. Then you would be able to run them in one group separately from the unit tests
  2. Have separate unit and integration subdirectories under spec, then you could run them separately via like crystal spec spec/unit and crystal spec spec/integration.
  3. Just run it like you would any other test and dont worry about trying to segregate them until it becomes a requirement
1 Like