Skip to content

Commit

Permalink
Switch to a custom inline differ.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber committed May 20, 2009
1 parent b807458 commit 29714c3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 67 deletions.
7 changes: 4 additions & 3 deletions Rakefile
Expand Up @@ -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

Expand Down
48 changes: 48 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion spec/fixtures/filter_html.yml
Expand Up @@ -21,7 +21,7 @@ filtered_html: <p>Just a little harmless xss &lt;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 <script src=http://ha.ckers.org/xss.js></script
filtered_html: <p>Just a little harmlesoos xss &lt;script src=http://ha.ckers.org/xss.js&gt;&lt;/script</p>
filtered_html: <p>Just a little harmless xss &lt;script src=http://ha.ckers.org/xss.js&gt;&lt;/script</p>
valid_html: false
---
name: escapes partial scanner-level script tag
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Expand Up @@ -4,7 +4,6 @@

class FormatterExampleGroup < Spec::Example::ExampleGroup


def self.examples_from_yaml(&block)
formatter = description.downcase
define_method("format_as_#{formatter}", &block)
Expand Down Expand Up @@ -40,4 +39,4 @@ def self.fixtures

end

Spec::Example::ExampleGroupFactory.register(:formatter, FormatterExampleGroup)
Spec::Example::ExampleGroupFactory.register(:formatter, FormatterExampleGroup)
61 changes: 0 additions & 61 deletions test/helper.rb

This file was deleted.

0 comments on commit 29714c3

Please sign in to comment.