rspec-html 0.2.15 → 0.2.17

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
  SHA256:
3
- metadata.gz: 8f365aa23d4ca954b964195b0d47f929a99b71fc2b976407ca9d225f70c5ea4c
4
- data.tar.gz: 1f3333b370b7e03e205eeabd8dab11050137652d4267ca14bfbff8098920d4d2
3
+ metadata.gz: 202d1ada700f7071e92c4468a5a6777ce953c080d003ddb38da2b1368e0dc4fb
4
+ data.tar.gz: 16c180dc70119aa3152241e4dfd75249c563df2bf5091a08d594c54b14cf2baa
5
5
  SHA512:
6
- metadata.gz: ff59e58090b970db24849dc4c715ff3e0748c364bbbc11cdfd9fa8a078cb938aea9bebe329e0c8e1c1a4a943bbf2962bff96ffb23c353381b6cda864f98b770a
7
- data.tar.gz: 26291ba3e7932df4ca2ef3cb9bbf52bbd8b89daeb8d90cd2e133290534e97ee9673bc766c9fc0d81c46b21f7f75dbb349bfdf017ee1e29de27e4cfc1e51126ec
6
+ metadata.gz: 0cc5a31d66fe3087d9248cb7528b088d667635672de83174f41b45b8a61d2708ade6f50db6cbcada675049bb30f684ed2df7cc83312b096cf4a0e5d1d1ed9dee
7
+ data.tar.gz: a6611b7dfd07963cbac2d5df0afd403e49afbc57419e5afdb9cc0a5604c73ad0de6407619d577fd03b98ab9675523596bc86aa7dfd89fa8667c58ed3acd95791
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-html (0.2.15)
4
+ rspec-html (0.2.17)
5
5
  nokogiri (~> 1.10)
6
6
  rspec (~> 3.0)
7
7
 
@@ -9,60 +9,63 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ast (2.4.2)
12
- concurrent-ruby (1.1.10)
13
- devpack (0.4.0)
12
+ concurrent-ruby (1.2.2)
13
+ devpack (0.4.1)
14
14
  diff-lcs (1.5.0)
15
- i18n (1.10.0)
15
+ i18n (1.13.0)
16
16
  concurrent-ruby (~> 1.0)
17
- mini_portile2 (2.8.1)
18
- nokogiri (1.13.10)
19
- mini_portile2 (~> 2.8.0)
17
+ json (2.6.3)
18
+ nokogiri (1.13.10-x86_64-linux)
20
19
  racc (~> 1.4)
21
- paint (2.2.1)
22
- parallel (1.22.1)
23
- parser (3.1.2.0)
20
+ paint (2.3.0)
21
+ parallel (1.23.0)
22
+ parser (3.2.2.1)
24
23
  ast (~> 2.4.1)
25
24
  racc (1.6.2)
26
25
  rainbow (3.1.1)
27
26
  rake (13.0.6)
28
- regexp_parser (2.3.1)
27
+ regexp_parser (2.8.0)
29
28
  rexml (3.2.5)
30
- rspec (3.11.0)
31
- rspec-core (~> 3.11.0)
32
- rspec-expectations (~> 3.11.0)
33
- rspec-mocks (~> 3.11.0)
34
- rspec-core (3.11.0)
35
- rspec-support (~> 3.11.0)
36
- rspec-expectations (3.11.0)
29
+ rspec (3.12.0)
30
+ rspec-core (~> 3.12.0)
31
+ rspec-expectations (~> 3.12.0)
32
+ rspec-mocks (~> 3.12.0)
33
+ rspec-core (3.12.2)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-expectations (3.12.3)
37
36
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.11.0)
37
+ rspec-support (~> 3.12.0)
39
38
  rspec-its (1.3.0)
40
39
  rspec-core (>= 3.0.0)
41
40
  rspec-expectations (>= 3.0.0)
42
- rspec-mocks (3.11.2)
41
+ rspec-mocks (3.12.5)
43
42
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.11.0)
45
- rspec-support (3.11.0)
46
- rubocop (1.29.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-support (3.12.0)
45
+ rubocop (1.50.2)
46
+ json (~> 2.3)
47
47
  parallel (~> 1.10)
48
- parser (>= 3.1.0.0)
48
+ parser (>= 3.2.0.0)
49
49
  rainbow (>= 2.2.2, < 4.0)
50
50
  regexp_parser (>= 1.8, < 3.0)
51
51
  rexml (>= 3.2.5, < 4.0)
52
- rubocop-ast (>= 1.17.0, < 2.0)
52
+ rubocop-ast (>= 1.28.0, < 2.0)
53
53
  ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.17.0)
56
- parser (>= 3.1.1.0)
54
+ unicode-display_width (>= 2.4.0, < 3.0)
55
+ rubocop-ast (1.28.0)
56
+ parser (>= 3.2.1.0)
57
+ rubocop-capybara (2.18.0)
58
+ rubocop (~> 1.41)
57
59
  rubocop-rake (0.6.0)
58
60
  rubocop (~> 1.0)
59
- rubocop-rspec (2.10.0)
60
- rubocop (~> 1.19)
61
- ruby-progressbar (1.11.0)
61
+ rubocop-rspec (2.20.0)
62
+ rubocop (~> 1.33)
63
+ rubocop-capybara (~> 2.17)
64
+ ruby-progressbar (1.13.0)
62
65
  strong_versions (0.4.5)
63
66
  i18n (>= 0.5)
64
67
  paint (~> 2.0)
65
- unicode-display_width (2.1.0)
68
+ unicode-display_width (2.4.2)
66
69
 
67
70
  PLATFORMS
68
71
  ruby
data/README.md CHANGED
@@ -97,6 +97,12 @@ expect(document.body.div.span[:class]).to contain_text 'my-class'
97
97
  expect(document.body.div.span['data-content']).to contain_text 'my content'
98
98
  ```
99
99
 
100
+ #### Retrieve all matching elements
101
+ To select all matching elements as an array, use `#all`:
102
+ ```ruby
103
+ expect(document.span.all.map(&:text)).to eql ['foo', 'bar', 'baz']
104
+ ```
105
+
100
106
  #### Indexing a Matching Set
101
107
  To select an index from a set of matched elements use the array-style interface (the first matching element is `1`, not `0`):
102
108
  ```ruby
@@ -130,6 +136,13 @@ expect(document.body).to have_css 'html body div.myclass'
130
136
  expect(document.body).to have_xpath '//html/body/div[@class="myclass"]'
131
137
  ```
132
138
 
139
+ #### Checkboxes
140
+
141
+ Use `be_checked` to test if a checkbox is checked:
142
+ ```ruby
143
+ expect(document.input(type: 'checkbox')).to be_checked
144
+ ```
145
+
133
146
  ### Custom Matchers
134
147
  <a name="matchers"></a>
135
148
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module HTML
5
- VERSION = '0.2.15'
5
+ VERSION = '0.2.17'
6
6
  end
7
7
  end
@@ -9,16 +9,16 @@ module RSpecHTML
9
9
 
10
10
  def_delegators :@search,
11
11
  :has_css?, :has_xpath?, :include?,
12
- :siblings, :text, :truncated_text, :attributes,
12
+ :all, :siblings, :text, :truncated_text, :attributes,
13
13
  :size, :length, :[],
14
- :css, :xpath
14
+ :css, :xpath, :checked?
15
15
 
16
16
  def initialize(element, name, options: {}, siblings: [])
17
17
  @name = name
18
18
  @element = element
19
19
  @options = options
20
20
  @siblings = siblings || []
21
- @search = Search.new(@element, @siblings)
21
+ @search = Search.new(@element, @siblings, self)
22
22
  end
23
23
 
24
24
  def present?
@@ -6,9 +6,10 @@ module RSpecHTML
6
6
  class Search
7
7
  attr_reader :siblings
8
8
 
9
- def initialize(element, siblings)
9
+ def initialize(element, siblings, element_wrapper)
10
10
  @element = element
11
11
  @siblings = siblings
12
+ @element_wrapper = element_wrapper
12
13
  end
13
14
 
14
15
  def to_s
@@ -32,6 +33,18 @@ module RSpecHTML
32
33
  end
33
34
  alias exist? present?
34
35
 
36
+ def checked?
37
+ raise ElementNotFoundError, "Element does not exist: #{element_wrapper.reconstituted}" if @element.nil?
38
+
39
+ @element.attributes.key?('checked')
40
+ end
41
+
42
+ def all
43
+ return [] if @siblings.nil?
44
+
45
+ @siblings.map { |sibling| Element.new(sibling, @element&.name) }
46
+ end
47
+
35
48
  # rubocop:disable Naming/PredicateName
36
49
  def has_css?(*args)
37
50
  !@element&.css(*args)&.empty?
@@ -91,14 +104,16 @@ module RSpecHTML
91
104
 
92
105
  private
93
106
 
107
+ attr_reader :element_wrapper
108
+
94
109
  def index(val)
95
110
  zero_index_error if val.zero?
96
- self.class.new(@siblings[val - 1], @element.name)
111
+ self.class.new(@siblings[val - 1], @element.name, element_wrapper)
97
112
  end
98
113
 
99
114
  def range(val)
100
115
  zero_index_error if val.first.zero?
101
- self.class.new(@siblings[(val.first - 1)..(val.last - 1)], :range)
116
+ self.class.new(@siblings[(val.first - 1)..(val.last - 1)], :range, element_wrapper)
102
117
  end
103
118
 
104
119
  def zero_index_error
data/lib/rspec_html.rb CHANGED
@@ -15,6 +15,7 @@ require 'rspec_html/matchers'
15
15
  module RSpecHTML
16
16
  class Error < StandardError; end
17
17
  class NoResponseError < Error; end
18
+ class ElementNotFoundError < Error; end
18
19
 
19
20
  def self.root
20
21
  Pathname.new(__dir__).parent
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-12 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri