diff --git a/lib/rack/livereload/body_processor.rb b/lib/rack/livereload/body_processor.rb index c5fc029..234a028 100644 --- a/lib/rack/livereload/body_processor.rb +++ b/lib/rack/livereload/body_processor.rb @@ -4,7 +4,6 @@ module Rack class LiveReload class BodyProcessor LIVERELOAD_JS_PATH = '/__rack/livereload.js' - HEAD_TAG_REGEX = /|/ LIVERELOAD_PORT = 35729 attr_reader :content_length, :new_body, :livereload_added @@ -63,22 +62,20 @@ module Rack def process!(env) @env = env @body.close if @body.respond_to?(:close) + @string_body = '' ; @body.each { |line| @string_body += line.to_s } - @new_body = [] ; @body.each { |line| @new_body << line.to_s } - - @content_length = 0 - @livereload_added = false - - @new_body.each do |line| - if !@livereload_added && line[' 0 + + @processed = true + @new_body = [@string_body] end def app_root diff --git a/rack-livereload.gemspec b/rack-livereload.gemspec index 3e41bd2..6b17ea3 100644 --- a/rack-livereload.gemspec +++ b/rack-livereload.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| # specify any dependencies here; for example: s.add_development_dependency "rspec" + s.add_development_dependency "rspec-its" s.add_development_dependency "cucumber" s.add_development_dependency "httparty" s.add_development_dependency "sinatra" diff --git a/spec/rack/livereload/body_processor_spec.rb b/spec/rack/livereload/body_processor_spec.rb index fad68b6..478eb53 100644 --- a/spec/rack/livereload/body_processor_spec.rb +++ b/spec/rack/livereload/body_processor_spec.rb @@ -2,23 +2,6 @@ require 'spec_helper' require 'nokogiri' describe Rack::LiveReload::BodyProcessor do - describe 'head tag regex' do - let(:regex) { described_class::HEAD_TAG_REGEX } - subject { regex } - - it { should be_kind_of(Regexp) } - - it 'only picks a valid tag' do - regex.match("").to_s.should eq('') - regex.match("").to_s.should eq('') - regex.match("").to_s.should eq("") - end - - it 'responds false when no head tag' do - regex.match("
").should be_false - end - end - let(:processor) { described_class.new(body, options) } let(:body) { [ page_html ] } let(:options) { {} } @@ -143,6 +126,14 @@ describe Rack::LiveReload::BodyProcessor do end end + context 'in html content areas' do + let(:page_html) { " <head></head>" } + + it 'should not add the livereload js' do + processed_body.should == " \n <head/>\n" + end + end + context 'not vendored' do before do processor.stubs(:use_vendored?).returns(false) diff --git a/spec/rack/livereload/processing_skip_analyzer_spec.rb b/spec/rack/livereload/processing_skip_analyzer_spec.rb index e1c856e..bc28426 100644 --- a/spec/rack/livereload/processing_skip_analyzer_spec.rb +++ b/spec/rack/livereload/processing_skip_analyzer_spec.rb @@ -14,7 +14,7 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do describe '#skip_processing?' do it "should skip processing" do - subject.skip_processing?.should be_true + subject.skip_processing?.should be_truthy end end diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index d955ab5..4eaa6ea 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -20,7 +20,7 @@ describe Rack::LiveReload do end it 'should return the js file' do - middleware._call(env).should be_true + middleware._call(env).should be_truthy end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d5e604a..06f4343 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,14 @@ require 'mocha/api' require 'webmock/rspec' +require 'rspec/its' require 'rack-livereload' RSpec.configure do |c| + c.expect_with :rspec do |config| + config.syntax = :should + end + c.mock_with :mocha end