require 'spec_helper'
describe Rack::EnvNotifier do
include Rack::Test::Methods
def app
@app ||= Rack::Builder.new {
use Rack::EnvNotifier
map '/some/path' do
run lambda { |env| [200, {'Content-Type' => 'text/html'}, <<-EOF
Test page
Howdy
EOF
]}
end
}.to_app
end
describe 'with a notify set on true' do
before do
Rack::EnvNotifier.message = 'warning!!! hot zone!!!'
Rack::EnvNotifier.notify = true
get '/some/path'
end
it 'returns 200' do
last_response.should be_ok
end
it 'has the X-EnvNotifier header' do
last_response.headers.has_key?('X-EnvNotifier').should be_true
end
it 'has only one X-EnvNotifier header' do
h = last_response.headers['X-EnvNotifier']
h.should eq('warning!!! hot zone!!!')
end
it 'has the Notification in the body' do
last_response.body.include?('warning!!! hot zone!!!
').should be_true
end
end
describe 'with a notify set on false' do
before do
Rack::EnvNotifier.message = 'warning!!!'
Rack::EnvNotifier.notify = false
get '/some/path'
end
it 'returns 200' do
last_response.should be_ok
end
it 'has the X-EnvNotifier header' do
last_response.headers.has_key?('X-EnvNotifier').should_not be_true
end
it 'has the Notification in the body' do
last_response.body.include?('warning
').should_not be_true
end
end
describe 'Notification format' do
before do
Rack::EnvNotifier.message = 'notification'
get '/some/path'
end
describe "with default CSS" do
it "does format the Notification" do
Rack::EnvNotifier.notification.should eq(<<-EOF
notification
EOF
)
end
end
context "with custom CSS" do
before do
Rack::EnvNotifier.custom_css = true
end
it "does format the Notification" do
Rack::EnvNotifier.notification.should eq(<<-EOF
notification
EOF
)
end
end
end
end