test_selector 0.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/MIT-LICENSE +20 -0
- data/README.md +65 -0
- data/Rakefile +29 -0
- data/lib/test_selector.rb +11 -0
- data/lib/test_selector/html_helper.rb +40 -0
- data/lib/test_selector/railtie.rb +6 -0
- data/lib/test_selector/test_helper.rb +28 -0
- data/lib/test_selector/version.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8fc605136ce5d55d5833d229f09affee57ddbd3fd743c2f0160aadc3c60197da
|
4
|
+
data.tar.gz: 7149ad57815f1bbf594441a94d627e370d60fb52a09faca9e6d4efe002e193a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48d26f850c21c63ac9f44f84ec32fd6a7ea4e0cb728b32e59c6a507a20553a53f526d8ea459be4729f70c1a3c98149f9599240bdc20a3fdbd9a2edccd806ccf8
|
7
|
+
data.tar.gz: 3e0c2c5fb284e5115422aff736eefca6b14287dd4d386b24de3cd00c1a71ec2e3e906b4c8e01d6baeb8abb935f6d4b176fd3c9f6201f2e623b3612237821faf5
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 FatboyPunk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# TestSelector
|
2
|
+
Based on [TestSelector](https://github.com/DefactoSoftware/test_selector) for
|
3
|
+
Elixir, a gem that adds a `test-selector` to the HTML so it can be found in the
|
4
|
+
tests.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
After installing this gem the views have a helper method `test_selector` that
|
8
|
+
can be used as:
|
9
|
+
|
10
|
+
```erb
|
11
|
+
<!--- app/views/some/view.erb --->
|
12
|
+
<p <%= test_selector "description", 1 %>the description of entity 1</p>
|
13
|
+
|
14
|
+
<p <%= test_selector "description", 2 %>the description of entity 2</p>
|
15
|
+
```
|
16
|
+
|
17
|
+
That will result in:
|
18
|
+
|
19
|
+
```HTML
|
20
|
+
<p test-selector="_app_views_some_view_erb__description" test-value="1">the description of entity 1</p>
|
21
|
+
|
22
|
+
<p test-selector="_app_views_some_view_erb__description" test-value="2">the description of entity 2</p>
|
23
|
+
```
|
24
|
+
|
25
|
+
In the test this can be found with:
|
26
|
+
|
27
|
+
```rb
|
28
|
+
it "assert the second description" do
|
29
|
+
... # some setup
|
30
|
+
|
31
|
+
test_part = test_selector(path, "description", 1)
|
32
|
+
expect(find_test_selector page.body, test_part).to have_content "the description of entity 2"
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
Add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
- dependencie: rails
|
41
|
+
|
42
|
+
Add to `:development` and `:test` in the `Gemfile`
|
43
|
+
```ruby
|
44
|
+
gem 'test_selector'
|
45
|
+
```
|
46
|
+
|
47
|
+
Execute:
|
48
|
+
```bash
|
49
|
+
$ bundle
|
50
|
+
```
|
51
|
+
|
52
|
+
`include` in the test framework you're using, for RSpec:
|
53
|
+
```erb
|
54
|
+
require 'test_selector'
|
55
|
+
|
56
|
+
RSpec.configure do |config|
|
57
|
+
...
|
58
|
+
|
59
|
+
config.include TestSelector::TestHelpers
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'TestSelector'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'bundler/gem_tasks'
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << 'test'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TestSelector
|
4
|
+
module HTMLHelper
|
5
|
+
def test_selector(name = nil, value = nil)
|
6
|
+
return if disable?
|
7
|
+
|
8
|
+
called_by = caller
|
9
|
+
setup_test_selector(called_by, name, value)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def setup_test_selector(called_by, name = nil, value = nil)
|
15
|
+
return if disable?
|
16
|
+
|
17
|
+
if name && value
|
18
|
+
"test-selector=#{get_selector(called_by)}__#{name} test-value=#{value}"
|
19
|
+
elsif name
|
20
|
+
"test-selector=#{get_selector(called_by)}__#{name}"
|
21
|
+
else
|
22
|
+
"test-selector=#{get_selector(called_by)}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_selector(called_by)
|
27
|
+
return if disable?
|
28
|
+
|
29
|
+
first_line = called_by.split('/n').first.first
|
30
|
+
file_hash = first_line.split('`').second
|
31
|
+
file_under_path = "#{file_hash.split('_erb__').first}_erb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def disable?
|
35
|
+
Rails.env == 'production'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ActionView::Base.send :include, TestSelector::HTMLHelper
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TestSelector
|
4
|
+
module TestHelper
|
5
|
+
def test_selector(path, name = nil, value = nil)
|
6
|
+
underscore_path = path.gsub(%r{/|\.}, '_')
|
7
|
+
|
8
|
+
if name && value
|
9
|
+
"test-selector=_#{underscore_path}__#{name} test-value=#{value}"
|
10
|
+
elsif name
|
11
|
+
"test-selector=_#{underscore_path}__#{name}"
|
12
|
+
else
|
13
|
+
"test-selector=_#{underscore_path}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_test_selector(html, selector)
|
18
|
+
test_selector = selector.split(' ').first
|
19
|
+
test_value = selector.split(' ').second
|
20
|
+
doc = Nokogiri::HTML(html).css("[#{test_selector}]")
|
21
|
+
if test_value
|
22
|
+
doc.css("[#{test_value}]").to_s
|
23
|
+
else
|
24
|
+
doc.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_selector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcel Horlings
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.10.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.2.2
|
41
|
+
description: test_selector can be used to find specific elements in your tests without
|
42
|
+
adding css variables or other html elements to your production environment
|
43
|
+
email:
|
44
|
+
- marcel@devrain.io
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/test_selector.rb
|
53
|
+
- lib/test_selector/html_helper.rb
|
54
|
+
- lib/test_selector/railtie.rb
|
55
|
+
- lib/test_selector/test_helper.rb
|
56
|
+
- lib/test_selector/version.rb
|
57
|
+
homepage: https://github.com/fatboypunk/test_selector
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.0.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Add test_selectors to rails views and use them in tests
|
80
|
+
test_files: []
|