capybara-select-2 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/README.md +6 -15
- data/capybara_select2.gemspec +1 -1
- data/lib/capybara_select2.rb +0 -1
- data/lib/capybara_select2/helpers.rb +35 -19
- data/lib/capybara_select2/utils.rb +21 -0
- data/lib/capybara_select2/version.rb +1 -1
- metadata +4 -4
- data/lib/capybara_select2/config.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1270129638518b209d629a987b5998c6e80ee997
|
4
|
+
data.tar.gz: b8681b7193f7b789d5c900115474007103fb819c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7b8e06ff700058b083008769bc926d50c0fe24aacfc5507736c7eff9f099f9185f3dcd36acb93d171e60234d727d2ca32ee848a850f46e578d4d652536ab30c
|
7
|
+
data.tar.gz: 6bb11c66346bd4b26d5416548c74939c16013d26b40cd41bd7ecb1d009b5d9fadcdb4f3dff463b2ab20a3c2c8e8e84e9a2371b2ae2737f09530854fe5cd412ef
|
data/.travis.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
sudo: required
|
2
|
+
dist: trusty
|
1
3
|
language: ruby
|
2
4
|
rvm:
|
3
5
|
- 2.4.2
|
@@ -6,3 +8,16 @@ env:
|
|
6
8
|
- MOZ_HEADLESS=1
|
7
9
|
addons:
|
8
10
|
firefox: latest
|
11
|
+
apt:
|
12
|
+
sources:
|
13
|
+
- ubuntu-sdk-team
|
14
|
+
packages:
|
15
|
+
- libqt5webkit5-dev
|
16
|
+
- qtdeclarative5-dev
|
17
|
+
before_install:
|
18
|
+
- export GECKODRIVER_VERSION=0.21.0
|
19
|
+
- wget https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER_VERSION/geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz
|
20
|
+
- mkdir geckodriver
|
21
|
+
- tar -xzf geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz -C geckodriver
|
22
|
+
- export PATH=$PATH:$PWD/geckodriver
|
23
|
+
script: xvfb-run bundle exec rspec
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# CapybaraSelect2 for select2 version 2/3/4
|
2
|
-
!!!
|
2
|
+
!!! CapybaraSelect2 detects version select2 automatically
|
3
3
|
|
4
4
|
[![Build Status](https://travis-ci.org/Hirurg103/capybara_select2.svg?branch=master)](https://travis-ci.org/Hirurg103/capybara_select2)
|
5
5
|
|
@@ -41,20 +41,6 @@ In your env.rb
|
|
41
41
|
World CapybaraSelect2
|
42
42
|
```
|
43
43
|
|
44
|
-
## Configuration
|
45
|
-
|
46
|
-
CapybaraSelect2 expects select2 version 4 by default. If you are using version 3 or 2 please specify it in your spec helper
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
CapybaraSelect2::Config.select2_version = 3
|
50
|
-
|
51
|
-
# or
|
52
|
-
|
53
|
-
CapybaraSelect2.configure do |config|
|
54
|
-
config.select2_version = 3
|
55
|
-
end
|
56
|
-
```
|
57
|
-
|
58
44
|
## Usage
|
59
45
|
|
60
46
|
### Select from a node containing select2 control
|
@@ -84,6 +70,11 @@ select2 'Buy Milk', from: 'Things to do', search: true
|
|
84
70
|
select2 'Millennials', from: 'Generations', tag: true
|
85
71
|
```
|
86
72
|
|
73
|
+
### Select several options at once
|
74
|
+
```ruby
|
75
|
+
select2 'Buy Milk', 'Go to gym', css: '#todo'
|
76
|
+
```
|
77
|
+
|
87
78
|
## Contributing
|
88
79
|
|
89
80
|
1. Add a test case which covers the bug
|
data/capybara_select2.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
32
|
spec.add_development_dependency "capybara", "~> 3.5"
|
33
|
-
spec.add_development_dependency "selenium-webdriver", "~>
|
33
|
+
spec.add_development_dependency "selenium-webdriver", "~> 3.5"
|
34
34
|
spec.add_development_dependency "capybara-screenshot" , "~> 1.0"
|
35
35
|
spec.add_development_dependency "capybara-webkit", "~> 1.15"
|
36
36
|
spec.add_development_dependency "puma", "~> 3.12"
|
data/lib/capybara_select2.rb
CHANGED
@@ -1,43 +1,59 @@
|
|
1
|
+
require 'capybara_select2/utils'
|
2
|
+
|
1
3
|
module CapybaraSelect2
|
2
4
|
module Helpers
|
3
|
-
|
4
|
-
|
5
|
+
|
6
|
+
def select2(*args)
|
7
|
+
options = args.pop
|
8
|
+
values = args
|
9
|
+
|
10
|
+
Utils.validate_options!(options)
|
11
|
+
|
12
|
+
container = if options[:xpath]
|
13
|
+
find(:xpath, options[:xpath])
|
14
|
+
elsif options[:css]
|
15
|
+
find(:css, options[:css])
|
16
|
+
else
|
17
|
+
find("label:not(.select2-offscreen)", text: options[:from])
|
18
|
+
.find(:xpath, '..')
|
19
|
+
.find('.select2-container')
|
20
|
+
end
|
21
|
+
|
22
|
+
container = if container['class'] =~ /select2-container/
|
23
|
+
container
|
24
|
+
else
|
25
|
+
container.find('.select2-container')
|
26
|
+
end
|
27
|
+
|
28
|
+
version = Utils.detect_version(container)
|
5
29
|
|
6
30
|
open_select = {
|
7
31
|
'2' => ".select2-choice, .select2-search-field",
|
8
32
|
'3' => ".select2-choice, .select2-search-field",
|
9
33
|
'4' => ".select2-selection"
|
10
|
-
}
|
34
|
+
}.fetch(version)
|
11
35
|
|
12
36
|
search_input = {
|
13
37
|
'2' => ".select2-dropdown-open input.select2-focused",
|
14
38
|
'3' => ".select2-dropdown-open input.select2-input",
|
15
39
|
'4' => ".select2-container--open input.select2-search__field"
|
16
|
-
}
|
40
|
+
}.fetch(version)
|
17
41
|
|
18
42
|
option = {
|
19
43
|
'2' => ".select2-container-active .select2-result",
|
20
44
|
'3' => ".select2-drop-active .select2-result",
|
21
45
|
'4' => ".select2-results .select2-results__option"
|
22
|
-
}
|
46
|
+
}.fetch(version)
|
23
47
|
|
24
|
-
|
25
|
-
find(
|
26
|
-
elsif options[:css]
|
27
|
-
find(:css, options[:css])
|
28
|
-
else
|
29
|
-
find("label:not(.select2-offscreen)", text: options[:from])
|
30
|
-
.find(:xpath, '..')
|
31
|
-
.find('.select2-container')
|
32
|
-
end
|
48
|
+
values.each do |value|
|
49
|
+
container.find(open_select).click
|
33
50
|
|
34
|
-
|
51
|
+
if options[:search] || options[:tag]
|
52
|
+
find(search_input).set value
|
53
|
+
end
|
35
54
|
|
36
|
-
|
37
|
-
find(search_input).set value
|
55
|
+
find(:xpath, '//body').find(option, text: value).click
|
38
56
|
end
|
39
|
-
|
40
|
-
find(:xpath, '//body').find(option, text: value).click
|
41
57
|
end
|
42
58
|
|
43
59
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CapybaraSelect2
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
def self.detect_version(container)
|
5
|
+
if container['class'] =~ /^select2\s/
|
6
|
+
'4'
|
7
|
+
elsif container['id'] =~ /^s2id_/
|
8
|
+
'3'
|
9
|
+
else
|
10
|
+
'2'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.validate_options!(options)
|
15
|
+
unless options.is_a?(Hash) && [:css, :xpath, :from].any? { |k| options.key?(k) }
|
16
|
+
fail ArgumentError.new("Please specify :css, :xpath or :from in options")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-select-2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Kavalionak
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.5'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: capybara-screenshot
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,8 +156,8 @@ files:
|
|
156
156
|
- capybara_select2.gemspec
|
157
157
|
- lib/capybara-select-2.rb
|
158
158
|
- lib/capybara_select2.rb
|
159
|
-
- lib/capybara_select2/config.rb
|
160
159
|
- lib/capybara_select2/helpers.rb
|
160
|
+
- lib/capybara_select2/utils.rb
|
161
161
|
- lib/capybara_select2/version.rb
|
162
162
|
homepage: https://github.com/Hirurg103/capybara_select2
|
163
163
|
licenses:
|