[#25 state:open] Added tests to create matches_id? function in link
This commit is contained in:
parent
8ce99ccf9a
commit
275829d382
|
@ -33,11 +33,22 @@ module Webrat
|
||||||
html =~ matcher || title =~ matcher
|
html =~ matcher || title =~ matcher
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def matches_id?(id_or_regexp)
|
||||||
|
if id_or_regexp.is_a?(Regexp)
|
||||||
|
(id =~ id_or_regexp) ? true : false
|
||||||
|
else
|
||||||
|
(id == id_or_regexp) ? true : false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
@element.innerHTML
|
@element.innerHTML
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
def id
|
||||||
|
@element['id']
|
||||||
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
|
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
|
||||||
|
|
|
@ -20,4 +20,54 @@ describe Webrat::Link do
|
||||||
link.click
|
link.click
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should matches_text? on regexp" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:text).and_return("Link Text")
|
||||||
|
link.matches_text?(/link/i).should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should matches_text? on link_text" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:text).and_return("Link Text")
|
||||||
|
link.matches_text?("Link Text").should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not matches_text? on link_text case insensitive" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:text).and_return("Link Text")
|
||||||
|
link.should_receive(:title).and_return(nil)
|
||||||
|
link.matches_text?("link_text").should == false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should match text including " do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:text).and_return("Link Text")
|
||||||
|
link.matches_text?("Link Text").should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not matches_text? on wrong text" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:text).and_return("Some Other Link")
|
||||||
|
link.should_receive(:title).and_return(nil)
|
||||||
|
link.matches_text?("Link Text").should == false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should matches_id? on exact matching id" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:id).and_return("some_id")
|
||||||
|
link.matches_id?("some_id").should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not matches_id? on incorrect id" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:id).and_return("other_id")
|
||||||
|
link.matches_id?("some_id").should == false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should matches_id? on matching id by regexp" do
|
||||||
|
link = Webrat::Link.new(@session, nil)
|
||||||
|
link.should_receive(:id).and_return("some_id")
|
||||||
|
link.matches_id?(/some/).should == true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue