Sha256: 4cdd13eff759cd37d907ea6fdd59ebd81d8cef460171986e341b9918b73be4a0
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "JavascriptEraser" do it "should be a middleware" do JavascriptEraser.new(lambda{}).should be_respond_to(:call) end describe "#call" do it "should erase the whole body if it's a javascript content type" do je = JavascriptEraser.new( lambda { |env| [200, { "Content-Type" => "text/javascript" }, "blah"] } ) je.call(nil)[2].should == "" end it "should erase the javascript tags if it's html" do class Response; attr_accessor :body; def initialize; @body="blah <script type='text/javascript'>doStuff();</script>"; end; end je = JavascriptEraser.new( lambda { |env| [200, {}, Response.new] } ) je.call(nil)[2].body.should == "blah " end it "should erase the event attributes if it's html" do class Response; attr_accessor :body; def initialize; @body="blah <div onclick='javascript:doStuff();'></div>"; end; end je = JavascriptEraser.new( lambda { |env| [200, {}, Response.new] } ) je.call(nil)[2].body.should == "blah <div></div>" end it "should log a message if the response type is unknown" do je = JavascriptEraser.new( lambda { |env| [200, {}, {}] } ) $stdout.should_receive(:write).at_least(1).times je.call(nil) end it "should not log a message if the response type is Rack::File" do module Rack; class File; end; end; je = JavascriptEraser.new( lambda { |env| [200, {}, Rack::File.new] } ) $stdout.should_receive(:write).exactly(0).times je.call(nil) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
javascript_eraser-1.0.2 | spec/javascript_eraser_spec.rb |