diff options
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/assertions.rb | 17 | ||||
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/vendor/html-scanner/html/node.rb | 24 |
3 files changed, 40 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index ad70111f3b..1a501bcd74 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -248,7 +248,22 @@ module Test #:nodoc: tag = find_tag(opts) assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}" end - + + # test 2 html strings to be equivalent, i.e. identical up to reordering of attributes + def assert_dom_equal(expected, actual, message="") + expected_dom = HTML::Document.new(expected).root + actual_dom = HTML::Document.new(actual).root + full_message = build_message(message, "<?> expected to be == to\n<?>.", expected_dom.to_s, actual_dom.to_s) + assert_block(full_message) { expected_dom == actual_dom } + end + + # negated form of +assert_dom_equivalent+ + def assert_dom_not_equal(expected, actual, message="") + expected_dom = HTML::Document.new(expected).root + actual_dom = HTML::Document.new(actual).root + full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s) + assert_block(full_message) { expected_dom != actual_dom } + end end end end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 59160c3e81..9291129e3d 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -838,6 +838,7 @@ module ActionController #:nodoc: end def self.action_methods + #puts "action method: #{public_instance_methods.inspect}" @action_methods ||= (public_instance_methods - hidden_actions).inject({}) { |h, k| h[k] = true; h } end diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index f0f94d19cc..016603a3e7 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -122,6 +122,18 @@ module HTML #:nodoc: def validate_conditions(conditions) Conditions === conditions ? conditions : Conditions.new(conditions) end + + def ==(node) + return false unless self.class == node.class && children.size == node.children.size + + equivalent = true + + children.size.times do |i| + equivalent &&= children[i] == node.children[i] + end + + equivalent + end class <<self def parse(parent, line, pos, content, strict=true) @@ -238,6 +250,11 @@ module HTML #:nodoc: nil end end + + def ==(node) + return false unless super + content == node.content + end end # A Tag is any node that represents markup. It may be an opening tag, a @@ -465,8 +482,13 @@ module HTML #:nodoc: true end + def ==(node) + return false unless super + return false unless closing == node.closing && self.name == node.name + attributes == node.attributes + end + private - # Match the given value to the given condition. def match_condition(value, condition) case condition |