capybara-extensions 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: be82a50d10aa44c6b41eed1bdadbe9ccc47962d9
4
- data.tar.gz: 66a534229850cad98e8a94c9b1a6af35c4b3c01a
3
+ metadata.gz: 7a7578ae423b1860a572ad5da560de3bffbd51cc
4
+ data.tar.gz: 80483da282e01105341220adee22a236414aed51
5
5
  SHA512:
6
- metadata.gz: a9fa104f4f7223a6578ef81b9a2a3762791641a2b57e3dbec208cf9d2426f85cfda12cc4adc975e825c40f6734422b9d7b44d2de309a83b3d1845275070b223b
7
- data.tar.gz: 06102011a95173369fddad6c73caf117237de3c09090c69ed0d93733cb9a76ccd1bb6c9a98793fdb122b26b18b65f8c30dc6b0ee82e49ba4be369ca9e10c15a5
6
+ metadata.gz: 66607ca434bc7c7e1d909b3b0034116cae887b95788af1e34123fac25f7310dc7d0afe204093e53c53226916aa834ad0fcb4231ab441e19aba863465d53c2458
7
+ data.tar.gz: 911eb6947f96f1e2e2125d42e89040d790fc6df5984ce204019baffd2c9fd6493e82e3de182e4d6c132040184d4d1b867e1f358133ff83b9b5dd23637d3ba657
@@ -54,7 +54,7 @@ module CapybaraExtensions::Finders
54
54
 
55
55
  # Find an HTML img based on the src and/or alt values.
56
56
  #
57
- # @param options [Hash] Must pass a hash containing the src and/or alt of the image sought.
57
+ # @param options [Hash] Must pass a hash containing the src and/or alt of the image sought. You may pass a Regexp with src; however, this should be done sparingly, as CapybaraExtensions::Locators#image_locator will find and iterate over all images in the current scope.
58
58
  # @return [Capybara::Element] the found element
59
59
  #
60
60
  def find_image(options = {})
@@ -8,8 +8,16 @@ module CapybaraExtensions::Locators
8
8
  #
9
9
  def image_locator(options)
10
10
  locator = String.new
11
+
12
+ if options[:src]
13
+ if Regexp === options[:src] && image = _find_image_with_regex(options[:src])
14
+ locator.concat("[@src='#{image}']")
15
+ else options[:src]
16
+ locator.concat "[@src='#{options[:src]}']"
17
+ end
18
+ end
19
+
11
20
  locator.concat "[@alt='#{options[:alt]}']" if options[:alt]
12
- locator.concat "[@src='#{options[:src]}']" if options[:src]
13
21
  locator
14
22
  end
15
23
 
@@ -25,4 +33,17 @@ module CapybaraExtensions::Locators
25
33
  locator.concat "[@content='#{content}']"
26
34
  locator
27
35
  end
36
+
37
+ private
38
+
39
+ def _find_image_with_regex(src)
40
+ all_images = all('img')
41
+ all_images.each do |image|
42
+ if image.native.attributes['src'].value.match(src).nil?
43
+ return nil
44
+ else
45
+ return image.native.attributes['src'].value
46
+ end
47
+ end
48
+ end
28
49
  end
@@ -6,7 +6,7 @@ module CapybaraExtensions::Matchers
6
6
 
7
7
  # Checks that the current node has an image with the given src or alt.
8
8
  #
9
- # @param options [Hash] must pass a hash containing src and/or alt to match against.
9
+ # @param options [Hash] must pass a hash containing src and/or alt to match against. You may pass a Regexp with src.
10
10
  # @return [Boolean] true if the image matches.
11
11
  #
12
12
  def has_image?(options = {})
@@ -1,3 +1,3 @@
1
1
  module CapybaraExtensions
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -347,7 +347,16 @@ describe '.string' do
347
347
  it 'finds an image when passed src and alt' do
348
348
  string.find_image(src: 'http://example.com/johndoe', alt: 'John Doe').native.attributes['src'].value.must_equal image
349
349
  string.find_image(src: 'http://example.com/johndoe').native.attributes['src'].value.must_equal image
350
+ string.find_image(src: /johndo/).native.attributes['src'].value.must_equal image
350
351
  string.find_image(alt: 'John Doe').native.attributes['src'].value.must_equal image
351
352
  end
353
+
354
+ it 'returns ElementNotFound when passed invalid src or alt' do
355
+ assert_raises(Capybara::ElementNotFound) { string.find_image(src: 'http://example.com/johndoe', alt: 'John Doh') }
356
+ assert_raises(Capybara::ElementNotFound) { string.find_image(src: 'http://example.com/johndoh', alt: 'John Doe') }
357
+ assert_raises(Capybara::ElementNotFound) { string.find_image(src: 'http://example.com/johndoh') }
358
+ assert_raises(Capybara::ElementNotFound) { string.find_image(alt: 'John Doh') }
359
+ assert_raises(Capybara::ElementNotFound) { string.find_image(src: /johndoh/) }
360
+ end
352
361
  end
353
362
  end
@@ -18,6 +18,8 @@ describe '.string' do
18
18
 
19
19
  it 'returns true if the image has an src with the argument' do
20
20
  string.has_image?(src: 'http://example.com/johndoe').must_equal true
21
+ string.has_image?(src: /johndo/).must_equal true
22
+ string.has_image?(src: /johndoh/).must_equal false
21
23
  end
22
24
 
23
25
  it 'returns false if the image does not have an src with the argument' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dupuis Jr.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-04 00:00:00.000000000 Z
12
+ date: 2013-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder