rspec-html 0.2.8 → 0.2.9

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
  SHA256:
3
- metadata.gz: a271ab933a02e1c5456ea472551e09d194132d79d9f47924cc8aa9cc4ae9c832
4
- data.tar.gz: 230f1ae1e54404f1766b909074bea3d0b83d748f8a57a7df9c497a60137c4fc4
3
+ metadata.gz: 152d9f0198dc22aa14461a8814b98d3be18e663e1b9b95206247cdc3c99ffdf7
4
+ data.tar.gz: ea64b6dafe91b0e13a46e3231a493c0a2b7097458ac02b28d5599639dc3f585f
5
5
  SHA512:
6
- metadata.gz: ad8a71ee657b000eb1b334d365da8f723ec0466c69aa7580b8104c87aae23066ca703cdbbea3717ac3b422fb57b59c8784ecef4a8eeb3366a0f719bd5f2808eb
7
- data.tar.gz: a1eeede78f3c7bddc433c2162c4355779c55bd9c6c0ce984f42ad347eaef3e8c5cc22e7b78dbe29450a353c8acd679a24acaccd4a6add6981223ba90eaf45901
6
+ metadata.gz: 728cc6614e604366f38f90d85e93d9822480bbe56b7542810c4887d1723db4b2d39963b8c77a7d5415b5a8fe21489df56135c13630442f2201d18ba4bc2d01a3
7
+ data.tar.gz: b77a735db02261431fea9caabf7d3674c7365198709167780761a983e8175a11ce7d770d81c75202b23a719c8faf110559321fff305f4ccb1eba527176c1d763
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-html (0.2.8)
4
+ rspec-html (0.2.9)
5
5
  nokogiri (~> 1.10)
6
6
  rspec (~> 3.0)
7
7
 
@@ -14,7 +14,7 @@ GEM
14
14
  diff-lcs (1.5.0)
15
15
  i18n (1.10.0)
16
16
  concurrent-ruby (~> 1.0)
17
- nokogiri (1.13.5-x86_64-linux)
17
+ nokogiri (1.13.6-x86_64-linux)
18
18
  racc (~> 1.4)
19
19
  paint (2.2.1)
20
20
  parallel (1.22.1)
data/README.md CHANGED
@@ -7,7 +7,7 @@ _RSpec::HTML_ provides a simple object interface to HTML responses from [_RSpec
7
7
  Add the gem to your `Gemfile`:
8
8
 
9
9
  ```ruby
10
- gem 'rspec-html', '~> 0.2.8'
10
+ gem 'rspec-html', '~> 0.2.9'
11
11
  ```
12
12
 
13
13
  And rebuild your bundle:
@@ -63,6 +63,17 @@ expect(document.body.div(id: 'my-div').span(class: 'my-class my-other-class')).t
63
63
 
64
64
  Classes can be provided in any order, i.e. `'my-class my-other-class'` is equivalent to `'my-other-class my-class'`.
65
65
 
66
+ #### Simple CSS Matching
67
+ To use a simple CSS selector when no other attributes are needed, pass a string to the tag method:
68
+ ```ruby
69
+ expect(document.body.div('#my-id.my-class1.my-class2')).to contain_text 'some text'
70
+ ```
71
+
72
+ This is effectively shorthand for:
73
+ ```ruby
74
+ expect(document.body.div(id: 'my-id', class: 'my-class1 my-class2')).to contain_text 'some text'
75
+ ```
76
+
66
77
  #### Text Matching
67
78
  To select an element that includes a given text string (i.e. excluding mark-up) use the `text` option:
68
79
  ```ruby
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module HTML
5
- VERSION = '0.2.8'
5
+ VERSION = '0.2.9'
6
6
  end
7
7
  end
@@ -12,6 +12,7 @@ module RSpecHTML
12
12
  name = @tag.to_s.downcase
13
13
  return '#document' if name == 'document'
14
14
  return name if name == 'document'
15
+ return "<#{name}#{@options} />" if @options.is_a?(String)
15
16
  return "<#{name}#{formatted_attributes} />" unless @options&.key?(:text)
16
17
 
17
18
  "<#{name}#{formatted_attributes}>#{@options[:text]}</#{name}>"
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RSpecHTML
4
4
  # Provides element/attribute/text searching for HTML entities
5
+ # rubocop:disable Metrics/ClassLength
5
6
  class Search
6
7
  def initialize(element, siblings)
7
8
  @element = element
@@ -95,17 +96,23 @@ module RSpecHTML
95
96
  end
96
97
 
97
98
  def where(tag, query, all: false)
98
- matched = if query[:class]
99
- where_class(tag, query[:class]) & where_xpath(tag, query.merge(class: nil))
100
- else
101
- where_xpath(tag, query)
102
- end
99
+ matched = matched_from_query(tag, query)
103
100
  return nil unless matched || all
104
101
  return matched&.first unless all
105
102
 
106
103
  matched
107
104
  end
108
105
 
106
+ def matched_from_query(tag, query)
107
+ if query.is_a?(String)
108
+ @element&.css("#{tag}#{query}")
109
+ elsif query[:class]
110
+ where_class(tag, query[:class]) & where_xpath(tag, query.merge(class: nil))
111
+ else
112
+ where_xpath(tag, query)
113
+ end
114
+ end
115
+
109
116
  def where_xpath(tag, query)
110
117
  conditions = "[#{where_conditions(query)}]" unless query.compact.empty?
111
118
  @element&.xpath("//#{tag}#{conditions}")
@@ -132,4 +139,5 @@ module RSpecHTML
132
139
  @element&.css(tag.to_s)
133
140
  end
134
141
  end
142
+ # rubocop:enable Metrics/ClassLength
135
143
  end
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.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-08 00:00:00.000000000 Z
11
+ date: 2022-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri