capybara-select2 0.0.8 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/capybara-select2.rb +22 -6
- data/lib/capybara-select2/version.rb +1 -1
- data/lib/capybara/selectors/tag_selector.rb +15 -0
- metadata +12 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 334d41a92551a946599f4b522bea5b8a325c42a7
|
4
|
+
data.tar.gz: 8f4a3b4207c4082966f035718af482b4cfc5cc9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82d7ad06d1913edbfcc1d8d9ed03552b3aff5db0df354aa2d7af18f8695f2ede07280d933801c4c5a84540810a6dd58346130262a0724f9801fc2f9c3ed0cc3a
|
7
|
+
data.tar.gz: efd69d8a26593103798e5a1c5c237e3332dcb42e1f0991b4e438ac7d5e001c2f3c4246f557adc44c4c2058a89613a84f6f0220817a9bc9ce670972f491916642
|
data/lib/capybara-select2.rb
CHANGED
@@ -1,28 +1,44 @@
|
|
1
1
|
require "capybara-select2/version"
|
2
|
+
require 'capybara/selectors/tag_selector'
|
2
3
|
require 'rspec/core'
|
3
4
|
|
4
5
|
module Capybara
|
5
6
|
module Select2
|
6
7
|
def select2(value, options = {})
|
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
|
+
raise "Must pass a hash containing 'from' or 'xpath' or 'css'" unless options.is_a?(Hash) and [:from, :xpath, :css].any? { |k| options.has_key? k }
|
8
9
|
|
9
10
|
if options.has_key? :xpath
|
10
11
|
select2_container = first(:xpath, options[:xpath])
|
12
|
+
elsif options.has_key? :css
|
13
|
+
select2_container = first(:css, options[:css])
|
11
14
|
else
|
12
15
|
select_name = options[:from]
|
13
16
|
select2_container = first("label", text: select_name).find(:xpath, '..').find(".select2-container")
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
# Open select2 field
|
20
|
+
if select2_container.has_selector?(".select2-choice")
|
21
|
+
select2_container.find(".select2-choice").click
|
22
|
+
else
|
23
|
+
select2_container.find(".select2-choices").click
|
24
|
+
end
|
25
|
+
|
26
|
+
if options.has_key? :search
|
27
|
+
find(:xpath, "//body").find(".select2-with-searchbox input.select2-input").set(value)
|
28
|
+
page.execute_script(%|$("input.select2-input:visible").keyup();|)
|
29
|
+
drop_container = ".select2-results"
|
30
|
+
else
|
31
|
+
drop_container = ".select2-drop"
|
32
|
+
end
|
17
33
|
|
18
34
|
[value].flatten.each do |value|
|
19
|
-
|
20
|
-
find(:xpath, "//body").find(".select2-drop li", text: value).click
|
35
|
+
find(:xpath, "//body").find("#{drop_container} li.select2-result-selectable", text: value).click
|
21
36
|
end
|
22
37
|
end
|
23
38
|
end
|
24
39
|
end
|
25
40
|
|
26
|
-
RSpec.configure do |
|
27
|
-
|
41
|
+
RSpec.configure do |config|
|
42
|
+
config.include Capybara::Select2
|
43
|
+
config.include Capybara::Selectors::TagSelector
|
28
44
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Capybara
|
2
|
+
module Selectors
|
3
|
+
module TagSelector
|
4
|
+
def select2_tag(value, options = {})
|
5
|
+
if options[:from]
|
6
|
+
find(:fillable_field, options[:from]).set(value)
|
7
|
+
else
|
8
|
+
find('input.select2-input').set(value)
|
9
|
+
end
|
10
|
+
|
11
|
+
find('.select2-drop li', text: value).click
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-select2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- William Yeung
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: capybara
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Helper for triggering select for select2 javascript library
|
@@ -56,29 +51,28 @@ files:
|
|
56
51
|
- lib/capybara-select2.rb
|
57
52
|
- lib/capybara-select2/version.rb
|
58
53
|
- lib/capybara/select2.rb
|
54
|
+
- lib/capybara/selectors/tag_selector.rb
|
59
55
|
homepage: ''
|
60
56
|
licenses: []
|
57
|
+
metadata: {}
|
61
58
|
post_install_message:
|
62
59
|
rdoc_options: []
|
63
60
|
require_paths:
|
64
61
|
- lib
|
65
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
63
|
requirements:
|
68
|
-
- -
|
64
|
+
- - ">="
|
69
65
|
- !ruby/object:Gem::Version
|
70
66
|
version: '0'
|
71
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
68
|
requirements:
|
74
|
-
- -
|
69
|
+
- - ">="
|
75
70
|
- !ruby/object:Gem::Version
|
76
71
|
version: '0'
|
77
72
|
requirements: []
|
78
73
|
rubyforge_project:
|
79
|
-
rubygems_version:
|
74
|
+
rubygems_version: 2.4.5
|
80
75
|
signing_key:
|
81
|
-
specification_version:
|
76
|
+
specification_version: 4
|
82
77
|
summary: ''
|
83
78
|
test_files: []
|
84
|
-
has_rdoc:
|