Skip to content

Commit

Permalink
Merge pull request #240 from arathunku/add-missing-spec-for-middleware
Browse files Browse the repository at this point in the history
Tests for middleware.
  • Loading branch information
iNecas committed May 12, 2014
2 parents 7160e9a + 4fb3bdf commit 1241222
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/apipie/extractor/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def call(env)
analyze(env) do
@app.call(env)
end
else
@app.call(env)
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/lib/extractor/middleware_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "spec_helper"

describe Apipie::Extractor::Recorder::Middleware do
let(:app) { ->(env) { [200, env, "app"] } }
let(:stack) { Apipie::Extractor::Recorder::Middleware.new(app) }
let(:request) { Rack::MockRequest.new(stack) }
let(:response) { request.get('/') }

it 'correctly process request without recording' do
expect(stack).not_to receive(:analyze)
response
end

it "analyze request if recording is set" do
Apipie.configuration.record = true
expect(Apipie::Extractor.call_recorder).to receive(:analyse_env)
expect(Apipie::Extractor.call_recorder).to receive(:analyse_response)
expect(Apipie::Extractor).to receive(:clean_call_recorder)
response
end
end

0 comments on commit 1241222

Please sign in to comment.