require 'stoor/add_after' require 'spec_helper' module Stoor describe AddAfter, 'content-type matching' do context 'default with text/plain response' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/plain' }, '
'] } } let(:app) { AddAfter.new(inner_app, //, 'stuff') } it "skips" do get '/' expect(last_response.body).to eq('') end end context 'default with text/html response' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, ''] } } let(:app) { AddAfter.new(inner_app, //, 'stuff') } it "processes" do get '/' expect(last_response.body).to eq('stuff') end end context 'specifying text/plain with text/html response' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, ''] } } let(:app) { AddAfter.new(inner_app, //, 'stuff', 'text/plain') } it "skips" do get '/' expect(last_response.body).to eq('') end end context 'specifying regexp with text/html response' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/whatever' }, ''] } } let(:app) { AddAfter.new(inner_app, //, 'stuff', /\Atext\//) } it "processes" do get '/' expect(last_response.body).to eq('stuff') end end end describe AddAfter, 'insertion' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, ''] } } let(:app) { AddAfter.new(inner_app, //, 'stuff') } it 'adds text after the first occurrence of a search string' do get '/' expect(last_response.body).to eq('stuff') end end describe AddAfter, 'insertion with two potential matches' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, ' '] } } let(:app) { AddAfter.new(inner_app, //, 'stuff') } it 'adds text only after the first occurrence of a search string' do get '/' expect(last_response.body).to eq('stuff ') end end describe AddAfter, 'insertion if response is an Array' do let(:inner_app) { ->(env) { [200, { 'Content-Type' => 'text/html' }, [ '