diff --git a/Rakefile b/Rakefile index 6026a792..018af256 100644 --- a/Rakefile +++ b/Rakefile @@ -214,9 +214,10 @@ end #### Custom testing tasks require 'rubygems' -require 'spec/rake/spectask' -Spec::Rake::SpecTask.new do |t| - t.spec_opts = ["--color", "--diff=u"] +require 'spec/rake/spectask' +Rake::Task[:default].prerequisites.clear +Spec::Rake::SpecTask.new(:default) do |t| + t.spec_opts = ["--color", "--require=spec/differs/inline.rb", "--diff=RedClothDiffers::Inline"] t.spec_files = FileList['spec/**/*_spec.rb'] end diff --git a/spec/differs/inline.rb b/spec/differs/inline.rb new file mode 100644 index 00000000..deefafbd --- /dev/null +++ b/spec/differs/inline.rb @@ -0,0 +1,48 @@ +require "spec/runner/differs/load-diff-lcs" +require 'pp' + +module RedClothDiffers + unless defined?(Inline) + class Inline + def initialize(options) + @options = options + end + + DIFF_ASCII_COLORS = { + "=" => "\e[0m", + "+" => "\e[42m", + "-" => "\e[41m", + "!" => "\e[43m" + } + + def diff_as_string(data_new, data_old) + output = "" + last_action = nil + sdiff = Diff::LCS.sdiff(data_old, data_new) + sdiff.each do |change| + unless change.action == last_action + output << DIFF_ASCII_COLORS[change.action] + last_action = change.action + end + output << case change.action + when "+" + change.new_element + when "-" + change.old_element + when "=" + change.old_element + when "!" + change.old_element + end + end + + output + end + + def diff_as_object(target,expected) + diff_as_string(PP.pp(target,""), PP.pp(expected,"")) + end + end + + end +end diff --git a/spec/fixtures/filter_html.yml b/spec/fixtures/filter_html.yml index 4e6d5bff..573152d0 100644 --- a/spec/fixtures/filter_html.yml +++ b/spec/fixtures/filter_html.yml @@ -21,7 +21,7 @@ filtered_html:

Just a little harmless xss <script src=http://ha.ckers.org/ name: escapes partial inline script tag desc: The end tag is malformed, but it must be escaped since a browser would recognize it in: Just a little harmless xss Just a little harmlesoos xss <script src=http://ha.ckers.org/xss.js></script

+filtered_html:

Just a little harmless xss <script src=http://ha.ckers.org/xss.js></script

valid_html: false --- name: escapes partial scanner-level script tag diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8b5754af..0f24bd5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,6 @@ class FormatterExampleGroup < Spec::Example::ExampleGroup - def self.examples_from_yaml(&block) formatter = description.downcase define_method("format_as_#{formatter}", &block) @@ -40,4 +39,4 @@ def self.fixtures end -Spec::Example::ExampleGroupFactory.register(:formatter, FormatterExampleGroup) \ No newline at end of file +Spec::Example::ExampleGroupFactory.register(:formatter, FormatterExampleGroup) diff --git a/test/helper.rb b/test/helper.rb deleted file mode 100644 index 97140f30..00000000 --- a/test/helper.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'test/unit' -$:.unshift File.dirname(__FILE__) + "/../lib" -require 'redcloth' - - -# Colorize differences in assert_equal failure messages. -begin - require 'rubygems' - require 'diff/lcs' - require 'test/unit' - - DIFF_COLOR = "\e[7m" unless defined?(DIFF_COLOR) - DEFAULT_COLOR = "\e[0m" unless defined?(DEFAULT_COLOR) - - def highlight_differences(a, b) - sdiff = Diff::LCS.sdiff(a, b, Diff::LCS::ContextDiffCallbacks) - return highlight_string(sdiff, :old, a), highlight_string(sdiff, :new, b) - end - - def highlight_string(sdiff, pos, s) - s = s.dup - offset = 0 - sdiff.each do |hunk| - if hunk.first.send("#{pos}_element") - s.insert(hunk.first.send("#{pos}_position") + offset, DIFF_COLOR) - offset += DIFF_COLOR.length - end - if hunk.last.send("#{pos}_element") - s.insert(hunk.last.send("#{pos}_position") + 1 + offset, DEFAULT_COLOR) - offset += DEFAULT_COLOR.length - end - end - s = DEFAULT_COLOR + s + DEFAULT_COLOR - end - - module Test::Unit::Assertions - # Show differences in expected and actual - def assert_equal(expected, actual, message=nil) - full_message = build_message(message, <