forked from teamcapybara/capybara
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearchable_spec.rb
66 lines (51 loc) · 1.96 KB
/
searchable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require File.expand_path('spec_helper', File.dirname(__FILE__))
module Capybara
describe Searchable do
class Klass
include Searchable
def all_unfiltered(locator, options = {})
[]
end
end
describe "#all" do
before do
@searchable = Klass.new
end
it "should return unfiltered list without options" do
node1 = stub(Node)
node2 = stub(Node)
@searchable.should_receive(:all_unfiltered).with('//x').and_return([node1, node2])
@searchable.all('//x').should == [node1, node2]
end
context "with :text filter" do
before do
@node1 = stub(Node, :text => 'node one text (with parens)')
@node2 = stub(Node, :text => 'node two text [-]')
@searchable.stub(:all_unfiltered).and_return([@node1, @node2])
end
it "should accept regular expression" do
@searchable.all('//x', :text => /node one/).should == [@node1]
@searchable.all('//x', :text => /node two/).should == [@node2]
end
it "should accept text" do
@searchable.all('//x', :text => "node one").should == [@node1]
@searchable.all('//x', :text => "node two").should == [@node2]
end
it "should allow Regexp reserved words in text" do
@searchable.all('//x', :text => "node one text (with parens)").should == [@node1]
@searchable.all('//x', :text => "node two text [-]").should == [@node2]
end
end
context "with :visible filter" do
before do
@visible_node = stub(Node, :visible? => true)
@hidden_node = stub(Node, :visible? => false)
@searchable.stub(:all_unfiltered).and_return([@visible_node, @hidden_node])
end
it "should filter out hidden nodes" do
@searchable.all('//x', :visible => true).should == [@visible_node]
end
end
end #all
end
end