capybara-select-2 0.5.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aaba1602e5f227889734248ce001fe00831ead8a
4
- data.tar.gz: ddbe5b57d2cb74225f29c034c12a1466c7e55804
3
+ metadata.gz: 35a699d3e0d5eec84d768a123c94ba5480793e43
4
+ data.tar.gz: da4ddebbf20ea31461c6fb5be32b3ef3d7a3e6b1
5
5
  SHA512:
6
- metadata.gz: e8c3a064c252b1d3fe56c3642e8e6920061ff866d34b5752f237f75c71172299af60201f2afd56518db482bfc08878cac08706e804dc24467e017244088618fa
7
- data.tar.gz: 48253431a5c902523dfc031a615b160db8f5ed849b860a8ce8d7a8d2a1a83a33333f9936ffdf3f434995dd96befb66e25a4ce0cc00e624c269fb57e148739ad9
6
+ metadata.gz: cc85290a29be0951fa40e6a763ce2f526c59cb6d4c7e438f1e82c7a1a1ed25826464d783774b9b8142f108d8615b6f56e7ca5c5584f42ba594bc9d6683c80040
7
+ data.tar.gz: 7c8324a51abda2745c5d1ce3f9ba0c88407801805f959b6890b41898fe8fa0eedd941ec44ce1685ccc08c971c3042ca156e67d8dcb512224c015181649ff6c20
@@ -1,8 +1,9 @@
1
1
  sudo: required
2
- dist: trusty
2
+ dist: xenial
3
3
  language: ruby
4
4
  rvm:
5
5
  - 2.4.1
6
+ - 2.7.1
6
7
  before_install: gem install bundler -v 2.0.1
7
8
  env:
8
9
  global:
data/README.md CHANGED
@@ -59,14 +59,47 @@ World CapybaraSelect2::Helpers # if need specific helpers
59
59
  ### Examples
60
60
 
61
61
  ```ruby
62
+ select2 'Buy Milk', from: 'Todo'
62
63
  select2 'Buy Milk', css: '#todo'
63
64
  select2 'Buy Milk', xpath: '//div[@id="todo"]'
64
- select2 'Buy Milk', from: 'Things to do'
65
- select2 'Buy Milk', 'Go to gym', css: '#todo'
65
+ ```
66
+
67
+ #### Selecting two or more options
66
68
 
67
- select2 'Buy Milk', from: 'Things to do', search: true
68
- select2 'Buy Milk', from: 'Things to do', search: 'Buy'
69
- select2 'Millennials', from: 'Generation', tag: true
69
+ ```ruby
70
+ select2 'Buy Milk', 'Go to gym', from: 'Todo'
71
+ ```
72
+
73
+ #### Searching
74
+
75
+ ```ruby
76
+ select2 'Buy Milk', from: 'Todo', search: true
77
+ ```
78
+
79
+ #### Searching by text different than an option text
80
+
81
+ ```
82
+ select2 'Buy Milk', from: 'Todo', search: 'Buy'
83
+ ```
84
+
85
+ #### Tagging
86
+
87
+ ```ruby
88
+ select2 'Go to gym', from: 'Todo', tag: true
89
+ ```
90
+
91
+ #### Resolving ambiguous match
92
+
93
+ ```ruby
94
+ # Select the first matching option if there are two or more options with text 'Buy'
95
+ select2 'Buy', from: 'Todo', match: :first
96
+ ```
97
+
98
+ #### Selecting an option by exact text
99
+
100
+ ```ruby
101
+ # Select 'Eat' if there are two or more options with text 'Eat' ('Eat', 'Eat salad')
102
+ select2 'Eat', from: 'Todo', exact_text: true
70
103
  ```
71
104
 
72
105
  [Note] CSS and XPath selectors must identify an HTML node that wraps select2 element or a select2 element itself (an HTML element with the `.select2-container` class)
@@ -75,17 +108,18 @@ select2 'Millennials', from: 'Generation', tag: true
75
108
 
76
109
  Option | Purpose
77
110
  :------|:-------
78
- css | Identify select2 element by a CSS selector
79
- xpath | Identify select2 element by an XPath selector
80
- from | Identify select2 element by a label
81
- search | Search for an option by the passed string. Search by an option text if `true` passed
82
- tag | Create an option
83
- match | Specifies Capybara's [matching strategy](https://github.com/teamcapybara/capybara#strategy) when selecting an option
84
- exact_text | Whether an option text must match exactly
111
+ `css` | Identify select2 element by a CSS selector
112
+ `xpath` | Identify select2 element by an XPath selector
113
+ `from` | Identify select2 element by a label
114
+ `label` | Identify select2 element by a label
115
+ `search` | Search for an option by the passed string. Search by an option text if `true` is passed
116
+ `tag` | Create an option
117
+ `match` | Specifies Capybara's [matching strategy](https://github.com/teamcapybara/capybara#strategy) when selecting an option
118
+ `exact_text` | Whether an option text must match exactly
85
119
 
86
120
  ### Helpers
87
121
 
88
- Specific select2 helpers that allow more refined access to select2 control
122
+ Specific select2 helpers that allow more refined access to a select2 control
89
123
 
90
124
  ```ruby
91
125
  select2_open label: 'Todo'
@@ -95,15 +129,17 @@ select2_select 'Buy Milk', from: 'Todo'
95
129
  select2_clear xpath: "//div[@id='todo']"
96
130
  ```
97
131
 
98
- Helper | Purpose
99
- :------|:-------
100
- select2_open | Open select2 control
101
- select2_close | Close select2 control
102
- select2_search | Type into a select2 search field
103
- select2_select | Select an option from an opened select2 control
104
- select2_clear | Remove selected options (for multi select only)
132
+ Helper | Purpose | Options
133
+ :------|:--------|:-------
134
+ `select2_open(options)` | Open select2 control | `label`, `css`, `xpath`
135
+ `select2_close` | Close select2 control | -
136
+ `select2_search(term, options)` | Type into a select2 search field | `label`, `from`, `css`, `xpath`
137
+ `select2_select(value, options)` | Select an option from an opened select2 control | `label`, `from`, `css`, `xpath`, `match`, `exact_text`
138
+ `select2_clear(options)` | Remove selected options (for multi select only) | `label`, `from`, `css`, `xpath`
139
+
140
+ See description for each option in the [Options](https://github.com/Hirurg103/capybara_select2#options) section
105
141
 
106
- [!Note] Helpers above are not available in tests by default. To use them include `CapybaraSelect2::Helpers` in your test invironment (see [Configuration section](https://github.com/Hirurg103/capybara_select2#configuration))
142
+ [Note] Helpers above are not available in tests by default. To use them include `CapybaraSelect2::Helpers` in your test invironment (see [Configuration section](https://github.com/Hirurg103/capybara_select2#configuration))
107
143
 
108
144
  ### RSpec matchers
109
145
 
@@ -12,17 +12,18 @@ module CapybaraSelect2
12
12
 
13
13
  container = Utils.find_select2_container(options, page)
14
14
  version = Utils.detect_select2_version(container)
15
- extended_options = options.merge({ container: container, version: version, page: page })
15
+ options_with_select2_details =
16
+ options.merge({ container: container, version: version, page: page })
16
17
 
17
18
  values.each do |value|
18
- Helpers.select2_open(extended_options)
19
+ Helpers.select2_open(options_with_select2_details)
19
20
 
20
21
  if options[:search] || options[:tag]
21
22
  term = options[:search].is_a?(String) ? options[:search] : value
22
- Helpers.select2_search(term, extended_options)
23
+ Helpers.select2_search(term, options_with_select2_details)
23
24
  end
24
25
 
25
- Helpers.select2_select(value, extended_options)
26
+ Helpers.select2_select(value, options_with_select2_details)
26
27
  end
27
28
  end
28
29
 
@@ -6,13 +6,10 @@ module CapybaraSelect2
6
6
  module_function
7
7
 
8
8
  def select2_open(options)
9
- options = options.dup
10
- options[:from] ||= options[:label]
9
+ options = Utils.set_option_aliases(options)
11
10
  Utils.validate_options!(options)
12
11
 
13
- _page = options[:page] || page
14
- container = options[:container] || Utils.find_select2_container(options, _page)
15
- version = options[:version] || Utils.detect_select2_version(container)
12
+ _, container, version = Utils.get_page_container_and_version(options, self)
16
13
  opener_selector = Selectors.opener_selector(version)
17
14
 
18
15
  container.find(:css, opener_selector).click
@@ -23,40 +20,32 @@ module CapybaraSelect2
23
20
  end
24
21
 
25
22
  def select2_search(text, options)
26
- options = options.dup
27
- options[:from] ||= options[:label]
23
+ options = Utils.set_option_aliases(options)
28
24
  Utils.validate_options!(options)
29
25
 
30
- _page = options[:page] || page
31
- container = options[:container] || Utils.find_select2_container(options, _page)
32
- version = options[:version] || Utils.detect_select2_version(container)
26
+ page, _, version = Utils.get_page_container_and_version(options, self)
33
27
  search_input_selector = Selectors.search_input_selector(version)
34
28
 
35
- _page.find(:xpath, '//body').find(:css, search_input_selector).set text
29
+ page.find(:xpath, '//body').find(:css, search_input_selector).set text
36
30
  end
37
31
 
38
32
  def select2_select(value, options)
39
33
  Utils.validate_options!(options)
40
34
 
41
- _page = options[:page] || page
42
- container = options[:container] || Utils.find_select2_container(options, _page)
43
- version = options[:version] || Utils.detect_select2_version(container)
35
+ page, _, version = Utils.get_page_container_and_version(options, self)
44
36
  option_selector = Selectors.option_selector(version)
45
37
 
46
- find_options = { text: value }
47
- find_options[:match] = options[:match] if options[:match]
48
- find_options[:exact_text] = options[:exact_text] if options[:exact_text]
38
+ find_options = options.select { |k, _| [:match, :exact_text].include?(k) }
39
+ find_options = find_options.merge(text: value)
49
40
 
50
- _page.find(:xpath, '//body').find(:css, option_selector, find_options).click
41
+ page.find(:xpath, '//body').find(:css, option_selector, **find_options).click
51
42
  end
52
43
 
53
44
  def select2_clear(options)
54
- options = options.dup
55
- options[:from] ||= options[:label]
45
+ options = Utils.set_option_aliases(options)
56
46
  Utils.validate_options!(options)
57
47
 
58
- container = Utils.find_select2_container(options, page)
59
- version = Utils.detect_select2_version(container)
48
+ _, container, version = Utils.get_page_container_and_version(options, self)
60
49
  remove_option_selector = Selectors.remove_option_selector(version)
61
50
 
62
51
  container.all(remove_option_selector).map(&:click)
@@ -1,6 +1,10 @@
1
1
  module CapybaraSelect2
2
2
  module Utils
3
3
 
4
+ def self.set_option_aliases(options)
5
+ options.dup.tap { |o| o[:from] ||= o[:label] }
6
+ end
7
+
4
8
  def self.detect_select2_version(container)
5
9
  if container['class'] =~ /^select2\s/
6
10
  '4'
@@ -35,5 +39,13 @@ module CapybaraSelect2
35
39
  end
36
40
  end
37
41
 
42
+ def self.get_page_container_and_version(options, context)
43
+ page = options[:page] || context.page
44
+ container = options[:container] || find_select2_container(options, page)
45
+ version = options[:version] || detect_select2_version(container)
46
+
47
+ [page, container, version]
48
+ end
49
+
38
50
  end
39
51
  end
@@ -1,3 +1,3 @@
1
1
  module CapybaraSelect2
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Kavalionak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler