Permalink
Browse files

added should_not have_drop_down capability. [#2]

  • Loading branch information...
1 parent 9379af1 commit 3f0923ddd705c7137c56e577c19ccb7112e4ed7b Stephen Anderson committed Sep 28, 2008
Showing with 16 additions and 2 deletions.
  1. +9 −2 lib/matchers/drop_down_matcher.rb
  2. +7 −0 spec/drop_down_matcher_spec.rb
@@ -3,19 +3,26 @@ module Rails
module Matchers
class DropDownMatcher
def initialize target_id, expected
- @xpath = "select##{target_id}/option"
+ @target_id = target_id
@expected = expected
end
+
def matches? response
@actual = extract_html_content response.body
@actual == @expected
end
+
def failure_message
"\nWrong drop down contents.\nexpected: #{@expected.inspect}\n found: #{@actual.inspect}\n\n"
end
+
+ def negative_failure_message
+ "\nShould not have matched dropdown with id: #{@target_id}\n\tand contents: #{@expected.inspect}\n\n"
+ end
+
def extract_html_content html
doc = Hpricot.XML(html)
- doc.search(@xpath).map{|n| n.inner_text.strip}
+ doc.search("select##{@target_id}/option").map{|n| n.inner_text.strip}
end
end
end
@@ -5,4 +5,11 @@
response = mock_model(Object, :body => '<select id="choice"><option value="val1">Choice 1</option><option value="val2">Choice 2</option></select>')
response.should have_dropdown('choice', ['Choice 1', 'Choice 2'])
end
+
+ describe 'passed wrong id' do
+ it 'should not match' do
+ response = mock_model(Object, :body => '<select id="choice"><option value="val1">Choice 1</option><option value="val2">Choice 2</option></select>')
+ response.should_not have_dropdown('wrong_id', ['Choice 1', 'Choice 2'])
+ end
+ end
end

0 comments on commit 3f0923d

Please sign in to comment.