capybara-choices 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 48d4d08c43c35e41575134cabe959ca8efad0d1282200e03536e8f5be0ff8dfc
4
+ data.tar.gz: b4f0c45a38578bd7c65bdd337c975a5eebc1638aa612793d9a95ca819b177590
5
+ SHA512:
6
+ metadata.gz: 19db6d5a15aaeeb45b48ce99b6cdb98e63b09025d2764e6e31d49e95bf06ea185cfa262433334d962ccdf1592496e7710c6f37b441a8e664d3fb0f7b3006d8ea
7
+ data.tar.gz: 9711c24bf5bd08dcde68d4662f3ca088fe20d354f506f4be04688af9b9dc3b5fc15b7802622d558e5a78cce0a4e1157d125b68842bdee573b2cd9a5be8966285
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.7.0
@@ -0,0 +1,20 @@
1
+ sudo: required
2
+ dist: trusty
3
+ language: ruby
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.0.1
7
+ env:
8
+ global:
9
+ - CC_TEST_REPORTER_ID=e82aca58fe4e7eae020799b830f8df7dd35ec67f7476078d4fe97ae884be8f84
10
+ addons:
11
+ chrome: stable
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter && ./cc-test-reporter before-build
15
+ - # start your web application and listen on `localhost`
16
+ - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
17
+
18
+ script: COVERAGE=1 xvfb-run bundle exec rspec
19
+ after_script:
20
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-choices.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Brendon Stanton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Brendon Stanton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ # capybara-choices
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capybara-choices"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara-choices/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capybara-choices"
8
+ spec.version = CapybaraChoices::VERSION
9
+ spec.authors = ["Brendon Stanton"]
10
+ spec.email = ["brendonstanton@icloud.com"]
11
+
12
+ spec.summary = %q{Capybara helpers for https://github.com/jshjohnson/Choices select box}
13
+ spec.homepage = "https://github.com/bumppoman/capybara-choices"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency "capybara", "~> 3.31"
33
+ spec.add_development_dependency "selenium-webdriver"
34
+ spec.add_development_dependency "webdrivers"
35
+ spec.add_development_dependency "capybara-screenshot" , "~> 1.0"
36
+ spec.add_development_dependency "puma", "~> 4.3"
37
+ spec.add_development_dependency "pry", "~> 0.12"
38
+ spec.add_development_dependency "simplecov", "~> 0.17"
39
+ spec.add_development_dependency "sinatra", "~> 2.0"
40
+ end
@@ -0,0 +1,41 @@
1
+ require 'capybara-choices/version'
2
+ require 'capybara-choices/utils'
3
+ require 'capybara-choices/helpers'
4
+
5
+ module CapybaraChoices
6
+
7
+ def choices(*args)
8
+ options = args.pop
9
+ values = args
10
+
11
+ Utils.validate_options!(options)
12
+
13
+ container = Utils.find_choices_container(options, page)
14
+ options_with_choices_details =
15
+ options.merge({ container: container, page: page })
16
+
17
+ values.each do |value|
18
+ Helpers.choices_open(options_with_choices_details)
19
+
20
+ if options[:search] || options[:tag]
21
+ term = options[:search].is_a?(String) ? options[:search] : value
22
+ Helpers.choices_search(term, options_with_choices_details)
23
+ end
24
+
25
+ Helpers.choices_select(value, options_with_choices_details)
26
+ end
27
+ end
28
+ end
29
+
30
+ if defined?(RSpec)
31
+ require 'rspec/core'
32
+ require 'capybara-choices/rspec/matchers'
33
+
34
+ RSpec.configure do |config|
35
+ config.include CapybaraChoices
36
+ end
37
+ end
38
+
39
+ if respond_to?(:World)
40
+ World(CapybaraChoices)
41
+ end
@@ -0,0 +1,56 @@
1
+ require 'capybara-choices/utils'
2
+ require 'capybara-choices/selectors'
3
+
4
+ module CapybaraChoices
5
+ module Helpers
6
+ module_function
7
+
8
+ def choices_open(options)
9
+ options = Utils.set_option_aliases(options)
10
+ Utils.validate_options!(options)
11
+
12
+ _, container, version = Utils.get_page_container_and_version(options, self)
13
+ opener_selector = Selectors.opener_selector(version)
14
+
15
+ container.find(:css, opener_selector).click
16
+ end
17
+
18
+ def choices_close(options = {})
19
+ page.find(:css, 'body').click
20
+ end
21
+
22
+ def choices_search(text, options)
23
+ options = Utils.set_option_aliases(options)
24
+ Utils.validate_options!(options)
25
+
26
+ page, _, version = Utils.get_page_container_and_version(options, self)
27
+ search_input_selector = Selectors.search_input_selector(version)
28
+
29
+ page.find(:xpath, '//body').find(:css, search_input_selector).set text
30
+ end
31
+
32
+ def choices_select(value, options)
33
+ Utils.validate_options!(options)
34
+
35
+ page, _, version = Utils.get_page_container_and_version(options, self)
36
+ option_selector = Selectors.option_selector(version)
37
+
38
+ find_options = options.select { |k, _| [:match, :exact_text].include?(k) }
39
+ find_options = find_options.merge(text: value)
40
+
41
+ #raise page.find(:xpath, '//body').all(:css, option_selector, **find_options).inspect
42
+ page.find(:xpath, '//body').all(:css, option_selector, **find_options).last.click
43
+ end
44
+
45
+ def choices_clear(options)
46
+ options = Utils.set_option_aliases(options)
47
+ Utils.validate_options!(options)
48
+
49
+ _, container, version = Utils.get_page_container_and_version(options, self)
50
+ remove_option_selector = Selectors.remove_option_selector(version)
51
+
52
+ container.all(remove_option_selector).map(&:click)
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ require 'rspec/expectations'
2
+ require 'capybara-choices/selectors'
3
+
4
+ RSpec::Matchers.define :have_choices_option do |expected|
5
+ def option_matcher(element)
6
+ choices_container = element.find('.choices', match: :first)
7
+
8
+ choices_version = CapybaraChoices::Utils.detect_choices_version(choices_container)
9
+
10
+ CapybaraChoices::Selectors.option_selector(choices_version)
11
+ end
12
+
13
+ match do |element|
14
+ expect(element).to have_css option_matcher(element), text: expected
15
+ end
16
+
17
+ match_when_negated do |element|
18
+ expect(element).not_to have_css option_matcher(element), text: expected
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ module CapybaraChoices
2
+ module Selectors
3
+
4
+ module_function
5
+
6
+ OpenerSelectors = {
7
+ '9' => '.choices__inner'
8
+ }.freeze
9
+
10
+ def opener_selector(choices_version)
11
+ OpenerSelectors.fetch(choices_version)
12
+ end
13
+
14
+ SearchInputSelectors = {
15
+ '9' => '.choices__list.is-active input.choices__input'
16
+ }.freeze
17
+
18
+ def search_input_selector(choices_version)
19
+ SearchInputSelectors.fetch(choices_version)
20
+ end
21
+
22
+ OptionSelectors = {
23
+ '9' => '.choices__list .choices__item'
24
+ }.freeze
25
+
26
+ def option_selector(choices_version)
27
+ OptionSelectors.fetch(choices_version)
28
+ end
29
+
30
+ RemoveOptionSelectors = {
31
+ '9' => '.choices__button'
32
+ }.freeze
33
+
34
+ def remove_option_selector(choices_version)
35
+ RemoveOptionSelectors.fetch(choices_version)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ module CapybaraChoices
2
+ module Utils
3
+
4
+ def self.set_option_aliases(options)
5
+ options.dup.tap { |o| o[:from] ||= o[:label] }
6
+ end
7
+
8
+ def self.detect_choices_version(container)
9
+ '9'
10
+ end
11
+
12
+ def self.validate_options!(options)
13
+ unless options.is_a?(Hash) && [:css, :xpath, :from].any? { |k| options.key?(k) }
14
+ fail ArgumentError.new("Please specify :css, :xpath or :from in options")
15
+ end
16
+ end
17
+
18
+ def self.find_choices_container(options, page)
19
+ container = if options[:xpath]
20
+ page.find(:xpath, options[:xpath])
21
+ elsif options[:css]
22
+ page.find(:css, options[:css])
23
+ else
24
+ page.find(:css, 'label', text: options[:from])
25
+ .find(:xpath, '..')
26
+ .find(:css, '.choices')
27
+ end
28
+
29
+ container
30
+ end
31
+
32
+ def self.get_page_container_and_version(options, context)
33
+ page = options[:page] || context.page
34
+ container = options[:container] || find_choices_container(options, page)
35
+ version = options[:version] || detect_choices_version(container)
36
+
37
+ [page, container, version]
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module CapybaraChoices
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-choices
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brendon Stanton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.31'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.31'
69
+ - !ruby/object:Gem::Dependency
70
+ name: selenium-webdriver
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webdrivers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: capybara-screenshot
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: puma
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.12'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.12'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.17'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.17'
153
+ - !ruby/object:Gem::Dependency
154
+ name: sinatra
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.0'
167
+ description:
168
+ email:
169
+ - brendonstanton@icloud.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".ruby-version"
177
+ - ".travis.yml"
178
+ - Gemfile
179
+ - LICENSE
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - capybara-choices.gemspec
186
+ - lib/capybara-choices.rb
187
+ - lib/capybara-choices/helpers.rb
188
+ - lib/capybara-choices/rspec/matchers.rb
189
+ - lib/capybara-choices/selectors.rb
190
+ - lib/capybara-choices/utils.rb
191
+ - lib/capybara-choices/version.rb
192
+ homepage: https://github.com/bumppoman/capybara-choices
193
+ licenses:
194
+ - MIT
195
+ metadata:
196
+ allowed_push_host: https://rubygems.org
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubygems_version: 3.1.2
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: Capybara helpers for https://github.com/jshjohnson/Choices select box
216
+ test_files: []