rspec-html 0.2.11 → 0.2.14

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: 8052637b48c07f5312c3c0f6c4f3c42b790691758ab66b92240509bc19512b78
4
- data.tar.gz: 28332c0112b53c97613bb24f387d6b9cef099527d363416856a44eab9e9f7260
3
+ metadata.gz: 01bcf5f299f82598a2836fee0f3ef8eb79af8b8219c65c74f6d130d3aa33a0e3
4
+ data.tar.gz: 8c784dec087fd10eb08a889db1e69dfaecbc1c3120347f66307ddc0071556bd4
5
5
  SHA512:
6
- metadata.gz: aa6583f785fd6e9da9e0a6c6d2a06e4f262e749e75d99e7a808fb937c3d08c882366424ffffcaf70e7d19de44027064435148ac9a8c9b3d4607ca67f218e5377
7
- data.tar.gz: 419571c56771c6c5b46a7197ce3f8f3cb866c00e0db54201c1106e9f2105099c78461feb719b81ddf5d924b6098859f57e5c4107140583805ba84b3c6555a2d5
6
+ metadata.gz: 566fbca771830a80666a798820e683ed857d01bf15c7fc147894986af724399d3b78c01e14316da5e9b3de7ed0e8a3e5a61f5de82512e7cad3c1e096809b4b0c
7
+ data.tar.gz: e12956efafa2e2a917e12640cee2bf43abe24d14f5ab9b19a87173e2e9689b83f741a50a18ece0f0dd9c82843b93c7539443a649ac431b3540a841c2158ba8f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-html (0.2.11)
4
+ rspec-html (0.2.14)
5
5
  nokogiri (~> 1.10)
6
6
  rspec (~> 3.0)
7
7
 
@@ -14,7 +14,9 @@ GEM
14
14
  diff-lcs (1.5.0)
15
15
  i18n (1.10.0)
16
16
  concurrent-ruby (~> 1.0)
17
- nokogiri (1.13.6-x86_64-linux)
17
+ mini_portile2 (2.8.0)
18
+ nokogiri (1.13.8)
19
+ mini_portile2 (~> 2.8.0)
18
20
  racc (~> 1.4)
19
21
  paint (2.2.1)
20
22
  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.11'
10
+ gem 'rspec-html', '~> 0.2.13'
11
11
  ```
12
12
 
13
13
  And rebuild your bundle:
@@ -59,6 +59,11 @@ To select an element matching certain attributes pass a hash to any of the chain
59
59
  expect(document.body.div(id: 'my-div').span(align: 'left')).to contain_text 'some text'
60
60
  ```
61
61
 
62
+ Special attributes like `checked` can be found using the `#attributes` method:
63
+ ```ruby
64
+ expect(document.input(type: 'checkbox', name: 'my-name')).attributes).to include 'checked'
65
+ ```
66
+
62
67
  #### Class Matching
63
68
  _CSS_ classes are treated as a special case: to select an element matching a set of classes pass the `class` parameter:
64
69
  ```ruby
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module HTML
5
- VERSION = '0.2.11'
5
+ VERSION = '0.2.14'
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ module RSpecHTML
9
9
 
10
10
  def_delegators :@search,
11
11
  :has_css?, :has_xpath?, :include?,
12
- :siblings, :text, :truncated_text,
12
+ :siblings, :text, :truncated_text, :attributes,
13
13
  :size, :length, :[],
14
14
  :css, :xpath
15
15
 
@@ -17,7 +17,7 @@ module RSpecHTML
17
17
  @name = name
18
18
  @element = element
19
19
  @options = options
20
- @siblings = siblings
20
+ @siblings = siblings || []
21
21
  @search = Search.new(@element, @siblings)
22
22
  end
23
23
 
@@ -29,7 +29,7 @@ module RSpecHTML
29
29
  alias exist? present?
30
30
 
31
31
  def inspect
32
- "<#{self.class}::#{name.to_s.capitalize}>"
32
+ reconstituted
33
33
  end
34
34
 
35
35
  def to_s
@@ -9,6 +9,7 @@ module RSpecHTML
9
9
  diffable
10
10
 
11
11
  def match(actual)
12
+ raise_argument_error unless actual.is_a?(RSpecHTML::Element)
12
13
  @rspec_actual = actual&.text
13
14
  return regexp_match?(actual) || regexp_siblings_match?(actual) if @expected.is_a?(Regexp)
14
15
 
@@ -32,6 +33,10 @@ module RSpecHTML
32
33
  def string_siblings_match?(actual)
33
34
  actual.siblings.any? { |sibling| (sibling&.text || '').include?(@expected.to_s) }
34
35
  end
36
+
37
+ def raise_argument_error
38
+ raise ArumentError, 'Expected RSpecHTML::Element with `match_text` matcher.'
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -12,7 +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
+ return "<#{name}#{shorthand_options} />" if @options.is_a?(String)
16
16
  return "<#{name}#{formatted_attributes} />" unless @options&.key?(:text)
17
17
 
18
18
  "<#{name}#{formatted_attributes}>#{@options[:text]}</#{name}>"
@@ -33,5 +33,23 @@ module RSpecHTML
33
33
  def formatted_attributes
34
34
  mapped_attributes.empty? ? nil : " #{mapped_attributes.join(' ')}"
35
35
  end
36
+
37
+ def shorthand_options
38
+ case @options[0]
39
+ when '.'
40
+ " #{shorthand_classes}"
41
+ when '#'
42
+ options = %( id="#{@options.partition('#').last.partition('.').first}")
43
+ shorthand_classes.nil? ? options : "#{options} #{shorthand_classes}"
44
+ else
45
+ @options
46
+ end
47
+ end
48
+
49
+ def shorthand_classes
50
+ return nil unless @options.include?('.')
51
+
52
+ %(class="#{@options.partition('.').last.split('.').map(&:strip).reject(&:empty?).join(' ')}")
53
+ end
36
54
  end
37
55
  end
@@ -11,6 +11,10 @@ module RSpecHTML
11
11
  @siblings = siblings
12
12
  end
13
13
 
14
+ def to_s
15
+ @element&.to_s
16
+ end
17
+
14
18
  def include?(val)
15
19
  text.include?(val)
16
20
  end
@@ -56,6 +60,10 @@ module RSpecHTML
56
60
  "#{text[0..max]}...#{text[-max..-1]}"
57
61
  end
58
62
 
63
+ def attributes
64
+ @element&.attributes&.to_h { |key, val| [key.to_sym, val.to_s] } || {}
65
+ end
66
+
59
67
  def size
60
68
  return @element.size if @element.respond_to?(:size)
61
69
 
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.11
4
+ version: 0.2.14
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-06-05 00:00:00.000000000 Z
11
+ date: 2022-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri