Skip to content

Commit

Permalink
iterate text_found?'s args from first to last, not from last to first
Browse files Browse the repository at this point in the history
  • Loading branch information
abotalov committed Mar 10, 2013
1 parent aa6a0e0 commit 7c00c53
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/capybara/node/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ def ==(other)
private

def text_found?(*args)
options = (args.last.is_a?(Hash))? args.pop : {}
content = (args.last.is_a?(Regexp))? args.pop : args.pop.to_s
type = args.first
type = args.shift if args.first.is_a?(Symbol) or args.first.nil?
content = args.shift
options = (args.first.is_a?(Hash))? args.first : {}
count = Capybara::Helpers.normalize_whitespace(text(type)).scan(Capybara::Helpers.to_regexp(content)).count

Capybara::CountHelpers.matches_count?(count, options)
Expand Down
6 changes: 3 additions & 3 deletions lib/capybara/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class HaveText < Matcher
attr_reader :type, :content, :options

def initialize(*args)
@options = (args.last.is_a?(Hash))? args.pop : {}
@content = args.pop
@type = args.first
@type = args.shift if args.first.is_a?(Symbol)
@content = args.shift
@options = (args.first.is_a?(Hash))? args.first : {}
end

def matches?(actual)
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@
end.to raise_error(/expected to find text "No such Text" in "Text"/)
end

it "casts has_text? argument to string" do
it "casts Fixnum to string" do
expect do
"<h1>Text</h1>".should have_text(:cast_me)
end.to raise_error(/expected to find text "cast_me" in "Text"/)
"<h1>Text</h1>".should have_text(3)
end.to raise_error(/expected to find text "3" in "Text"/)
end

it "fails if matched text count does not equal to expected count" do
Expand Down

0 comments on commit 7c00c53

Please sign in to comment.