Permalink
Browse files

Added naked options matcher, since an RJS return just replaces options

contents.
  • Loading branch information...
1 parent c3dc796 commit 80bb30f87f709651ca75659a9d2359b4bd151f38 Stephen Anderson committed Nov 8, 2008
Showing with 39 additions and 3 deletions.
  1. +8 −3 lib/html_matchers.rb
  2. +31 −0 lib/matchers/options_matcher.rb
View
@@ -1,6 +1,11 @@
require 'hpricot'
-%w(check_box_group drop_down radio_group span_text table_body table_header td_link).each do |element|
- require File.join(File.dirname(__FILE__), 'matchers', "#{element}_matcher")
+
+# %w(check_box_group drop_down radio_group span_text table_body table_header td_link).each do |element|
+ # require File.join(File.dirname(__FILE__), 'matchers', "#{element}_matcher")
+# end
+
+Dir.glob(File.dirname(__FILE__) + '/matchers/*.rb').each do |rb|
+ require rb
end
module Spec # :nodoc:
@@ -36,4 +41,4 @@ def have_td_link target_id, expected_link, expected_text
end
end
end
-end
+end
@@ -0,0 +1,31 @@
+module Spec # :nodoc:
+ module Rails
+ module Matchers
+ class OptionsMatcher
+
+ def initialize expected
+ @expected = expected
+ end
+
+ def matches? response
+ @actual = extract_html_content response.body
+ @actual == @expected
+ end
+
+ def failure_message
+ "\nWrong option contents.\nexpected: #{@expected.inspect}\n found: #{@actual.inspect}\n\n"
+ end
+
+ def negative_failure_message
+ "\nShould not have matched contents: #{@expected.inspect}\n\n"
+ end
+
+ def extract_html_content html
+ doc = Hpricot.XML(html)
+ doc.search("/option").map{|n| n.inner_text.strip}
+ end
+
+ end
+ end
+ end
+end

0 comments on commit 80bb30f

Please sign in to comment.