/
select_spec.rb
61 lines (52 loc) · 2.01 KB
/
select_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
shared_examples_for "select" do
describe "#select" do
before do
@session.visit('/form')
end
it "should return value of the first option" do
@session.find_field('Title').value.should == 'Mrs'
end
it "should return value of the selected option" do
@session.select("Miss", :from => 'Title')
@session.find_field('Title').value.should == 'Miss'
end
it "should select an option from a select box by id" do
@session.select("Finish", :from => 'form_locale')
@session.click_button('awesome')
extract_results(@session)['locale'].should == 'fi'
end
it "should select an option from a select box by label" do
@session.select("Finish", :from => 'Locale')
@session.click_button('awesome')
extract_results(@session)['locale'].should == 'fi'
end
it "should favour exact matches to option labels" do
@session.select("Mr", :from => 'Title')
@session.click_button('awesome')
extract_results(@session)['title'].should == 'Mr'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
end
end
context "with an option that doesn't exist" do
it "should raise an error" do
running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::OptionNotFound)
end
end
context "with multiple select" do
it "should select one option" do
@session.select("Ruby", :from => 'Language')
@session.click_button('awesome')
extract_results(@session)['languages'].should == ['Ruby']
end
it "should select multiple options" do
@session.select("Ruby", :from => 'Language')
@session.select("Javascript", :from => 'Language')
@session.click_button('awesome')
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
end
end
end
end