capybara-select-2 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17667170ad7048b4fed5d2f4a889317834af92bb
4
- data.tar.gz: b46969cee6569118db22a51b7d502126876779d7
3
+ metadata.gz: 9678aa226fd30f77d126dbc9910dbfb52c6c8d38
4
+ data.tar.gz: c204deba3c13b6e1e23c71d21515f9474b4e09f7
5
5
  SHA512:
6
- metadata.gz: 7fa97abcecdc0b0b4d712c5255a0d48a81acd0012baccc32306bec47d39af51dcf9e1bb574ac91af399715fd5ab4a43810d3bd82639c6d9a04d042aad4ce8c60
7
- data.tar.gz: 56d141d5ec1e6f604016bb8d9adbc177097a73fff97ff99953d527212ae052fd5627ffff1f3336a8f2f2fcf0ea59859b5b947d15c6c1500307ce6c0b96bbddc3
6
+ metadata.gz: 57acf0411c48a5a2a82616d8f944cb17e0b49b11088068430f209c18764b9d2bf17cbfc65fcb55ed4f1080052b57af94e881c664ff8823cd1f66cc9becb4e418
7
+ data.tar.gz: 6856a1f8b811ae3a4febadac8979d36facf4a32768485fb38b902b0ac2947699c366f7ed32898f5338757d365f9b77b31e394cb42127adb8e26e7d5a04856e45
data/README.md CHANGED
@@ -18,7 +18,9 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install capybara-select-2
20
20
 
21
- ### Rspec
21
+ [Note] In the projects which use RSpec or Cucumber `select2` helper should be loaded automatically
22
+
23
+ ### Manual installation with Rspec
22
24
 
23
25
  In your spec_helper.rb
24
26
 
@@ -28,7 +30,7 @@ RSpec.configure do |config|
28
30
  end
29
31
  ```
30
32
 
31
- ### Cucumber
33
+ ### Manual installation with Cucumber
32
34
 
33
35
  In your env.rb
34
36
 
@@ -36,6 +38,20 @@ In your env.rb
36
38
  World CapybaraSelect2
37
39
  ```
38
40
 
41
+ ## Configuration
42
+
43
+ CapybaraSelect2 expects select2 version 4 by default. If you are using version 3 or 2 please specify it in your spec helper
44
+
45
+ ```
46
+ CapybaraSelect2::Config.select2_version = 3
47
+
48
+ # or
49
+
50
+ CapybaraSelect2.configure do |config|
51
+ config.select2_version = 3
52
+ end
53
+ ```
54
+
39
55
  ## Usage
40
56
 
41
57
  ### Select from a node containing select2 control
@@ -1,6 +1,17 @@
1
1
  require "capybara_select2/version"
2
2
  require 'capybara_select2/helpers'
3
+ require 'capybara_select2/config'
3
4
 
4
5
  module CapybaraSelect2
5
6
  include Helpers
6
7
  end
8
+
9
+ if defined?(RSpec)
10
+ RSpec.configure do |config|
11
+ config.include CapybaraSelect2
12
+ end
13
+ end
14
+
15
+ if respond_to?(:World)
16
+ World(CapybaraSelect2)
17
+ end
@@ -0,0 +1,15 @@
1
+ module CapybaraSelect2
2
+
3
+ def self.configure
4
+ yield Config
5
+ end
6
+
7
+ class Config
8
+ class << self
9
+ attr_accessor :select2_version
10
+ end
11
+ end
12
+
13
+ Config.select2_version ||= 4
14
+
15
+ end
@@ -1,21 +1,27 @@
1
1
  module CapybaraSelect2
2
2
  module Helpers
3
3
  def select2(value, options = {})
4
- open_select = "" +
5
- ".select2-choice, .select2-search-field," + # v2 & v3
6
- ".select2-selection" # v4
7
-
8
- search_input = "" +
9
- ".select2-dropdown-open input.select2-focused," + # v2
10
- ".select2-drop-active input.select2-input," + # v3
11
- ".select2-container--focus input.select2-search__field," + # v4 single
12
- ".select2-container--open input.select2-search__field" # v4 multi
13
-
14
- option = "" +
15
- ".select2-container-active .select2-result," + # v2
16
- ".select2-drop-active .select2-result," + # v3
17
- ".select2-results .select2-results__option" # v4
18
-
4
+ version = Config.select2_version.to_s
5
+
6
+ open_select = {
7
+ '2' => ".select2-choice, .select2-search-field",
8
+ '3' => ".select2-choice, .select2-search-field",
9
+ '4' => ".select2-selection"
10
+ }[version]
11
+
12
+ search_input = {
13
+ '2' => ".select2-dropdown-open input.select2-focused",
14
+ '3' => ".select2-dropdown-open input.select2-input",
15
+ '4' => (
16
+ ".select2-container--focus input.select2-search__field," + # single
17
+ ".select2-container--open input.select2-search__field") # multi
18
+ }[version]
19
+
20
+ option = {
21
+ '2' => ".select2-container-active .select2-result",
22
+ '3' => ".select2-drop-active .select2-result",
23
+ '4' => ".select2-results .select2-results__option"
24
+ }[version]
19
25
 
20
26
  container = if options[:xpath]
21
27
  find(:xpath, options[:xpath])
@@ -1,3 +1,3 @@
1
1
  module CapybaraSelect2
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-select-2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Kavalionak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-05 00:00:00.000000000 Z
11
+ date: 2018-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,6 +142,7 @@ files:
142
142
  - capybara_select2.gemspec
143
143
  - lib/capybara-select-2.rb
144
144
  - lib/capybara_select2.rb
145
+ - lib/capybara_select2/config.rb
145
146
  - lib/capybara_select2/helpers.rb
146
147
  - lib/capybara_select2/version.rb
147
148
  homepage: https://github.com/Hirurg103/capybara_select2