spec/rack/livereload_spec.rb in rack-livereload-0.3.11 vs spec/rack/livereload_spec.rb in rack-livereload-0.3.12
- old
+ new
@@ -10,11 +10,11 @@
its(:app) { should == app }
let(:env) { {} }
let(:options) { {} }
- describe described_class::LIVERELOAD_LOCAL_URI do
+ describe "livereload local uri" do
context 'does not exist' do
before do
stub_request(:any, 'localhost:35729/livereload.js').to_timeout
end
@@ -27,10 +27,20 @@
end
it { should_not use_vendored }
end
+ context 'with custom port' do
+ let(:options) { {:live_reload_port => '12348'}}
+ context 'exists' do
+ before do
+ stub_request(:any, 'localhost:12348/livereload.js')
+ end
+ it { should_not use_vendored }
+ end
+ end
+
context 'specify vendored' do
let(:options) { { :source => :vendored } }
it { should use_vendored }
end
@@ -67,10 +77,40 @@
it 'should pass through' do
middleware.call(env).should == ret
end
end
+ context 'chunked response' do
+ let(:body) { [ '<head></head>' ] }
+ let(:ret) { [ 200, { 'Transfer-Encoding' => 'chunked' }, body ] }
+
+ before do
+ app.stubs(:call).with(env).returns(ret)
+ body.expects(:close).never
+ body.stubs(:respond_to?).with(:close).returns(true)
+ end
+
+ it 'should pass through' do
+ middleware.call(env).should == ret
+ end
+ end
+
+ context 'inline disposition' do
+ let(:body) { [ '<head></head>' ] }
+ let(:ret) { [ 200, { 'Content-Disposition' => 'inline; filename=my_inlined_file' }, body ] }
+
+ before do
+ app.stubs(:call).with(env).returns(ret)
+ body.expects(:close).never
+ body.stubs(:respond_to?).with(:close).returns(true)
+ end
+
+ it 'should pass through' do
+ middleware.call(env).should == ret
+ end
+ end
+
context 'unknown Content-Type' do
let(:ret) { [ 200, {}, [ 'hey ho' ] ] }
before do
app.stubs(:call).with(env).returns(ret)
@@ -118,12 +158,22 @@
it 'should add the livereload js script tag before all other script tags' do
body_dom.at_css("head")[:attribute].should == 'attribute'
body_dom.at_css("script:eq(4)")[:src].should include(described_class::LIVERELOAD_JS_PATH)
body_dom.at_css("script:last-child")[:insert].should == "before"
end
+
end
+ describe "LIVERELOAD_PORT value" do
+ let(:options) { {:live_reload_port => 12345 }}
+ it "sets the variable at the top of the file" do
+ body.should include 'RACK_LIVERELOAD_PORT = 12345'
+ end
+ end
+
+
+
context 'in header tags' do
let(:page_html) { "<header class='hero'><h1>Just a normal header tag</h1></header>" }
let(:body_dom) { Nokogiri::XML(body) }
@@ -138,10 +188,10 @@
middleware.stubs(:use_vendored?).returns(false)
end
it 'should add the LR livereload js script tag' do
body.should include("script")
- body.should include(described_class::LIVERELOAD_LOCAL_URI.gsub('localhost', 'host'))
+ body.should include(middleware.livereload_local_uri.gsub('localhost', 'host'))
end
end
context 'set options' do
let(:middleware) { described_class.new(app, :host => new_host, :port => port, :min_delay => min_delay, :max_delay => max_delay) }