capybara-select2 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/capybara-select2.rb +12 -4
- data/lib/capybara-select2/version.rb +1 -1
- metadata +2 -5
- data/.gitignore +0 -17
- data/LICENSE.txt +0 -22
- data/README.md +0 -39
data/lib/capybara-select2.rb
CHANGED
@@ -4,13 +4,21 @@ require 'rspec/core'
|
|
4
4
|
module Capybara
|
5
5
|
module Select2
|
6
6
|
def select2(value, options = {})
|
7
|
-
raise "Must pass a hash containing 'from'"
|
8
|
-
|
7
|
+
raise "Must pass a hash containing 'from' or 'xpath'" unless options.is_a?(Hash) and [:from, :xpath].any? { |k| options.has_key? k }
|
8
|
+
|
9
|
+
if options.has_key? :xpath
|
10
|
+
select2_container = first(:xpath, options[:xpath])
|
11
|
+
else
|
12
|
+
select_name = options[:from]
|
13
|
+
select2_container = first("label", text: select_name).find(:xpath, '..').find(".select2-container")
|
14
|
+
end
|
9
15
|
|
10
|
-
select2_container=first("label", text: select_name).find(:xpath, '..').find(".select2-container")
|
11
16
|
select2_container.find(".select2-choice").click
|
12
17
|
|
13
|
-
|
18
|
+
[value].flatten.each do |value|
|
19
|
+
select2_container.find(:xpath, "a[contains(concat(' ',normalize-space(@class),' '),' select2-choice ')] | ul[contains(concat(' ',normalize-space(@class),' '),' select2-choices ')]").click
|
20
|
+
find(:xpath, "//body").find(".select2-drop li", text: value).click
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-select2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -50,10 +50,7 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
-
- .gitignore
|
54
53
|
- Gemfile
|
55
|
-
- LICENSE.txt
|
56
|
-
- README.md
|
57
54
|
- Rakefile
|
58
55
|
- capybara-select2.gemspec
|
59
56
|
- lib/capybara-select2.rb
|
data/.gitignore
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 William Yeung
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# Capybara::Select2
|
2
|
-
|
3
|
-
All this gem does is something very simple- allow you to trigger select2 dropdown to select the value you want. The original select doesn't with the javascript overrides, so this new helper method does only this thing.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'capybara-select2', group: :test
|
10
|
-
|
11
|
-
Or, add it into your test group
|
12
|
-
|
13
|
-
group :test do
|
14
|
-
gem 'capybara-select2'
|
15
|
-
...
|
16
|
-
end
|
17
|
-
|
18
|
-
And then execute:
|
19
|
-
|
20
|
-
$ bundle
|
21
|
-
|
22
|
-
Or install it yourself as:
|
23
|
-
|
24
|
-
$ gem install capybara-select2
|
25
|
-
|
26
|
-
The gem automatically hook itself into rspec helper using Rspec.configure.
|
27
|
-
|
28
|
-
## Usage
|
29
|
-
|
30
|
-
Just use this method inside your capybara test:
|
31
|
-
select2("Dropdown Text", from: "Label of the dropdown")
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
1. Fork it
|
36
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
-
5. Create new Pull Request
|