watir_pump 0.4.7 → 0.4.8

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: c9ac45f1057344a09c7d15e228a5342a9706ce72bdc2ccfc29803fef63ab050d
4
- data.tar.gz: 04a6ec0412739ea76326266a65d2fae07a3490beb2303ef904bac47b74df7c4b
3
+ metadata.gz: 46afc438adf0692f8cf253804f031984e6d4d068067168a81c964a3b8291387e
4
+ data.tar.gz: f965db8f63df648b50c7a731d7a4c3300187f93fe6f84f68625d4801421d2240
5
5
  SHA512:
6
- metadata.gz: b0a53a55fe324275357fdf8ea9db127404b5c73f78fe57da026a76b9b7dd7c01a7f9e34a012da7d18339f0e3aff606df9a1966e8cbee6d01578b1c2432b82677
7
- data.tar.gz: 5fef97f83fa2ca0a4219b8dff4839bcdf633821b63d00f51937a1097fd0d7de4c776694bb55c141c2707409c5c3ededc0d67b7b7f68d705c507e3d28ef103459
6
+ metadata.gz: 3e17dc240658a4ac2da38fdbcacbfaba31a5401703d65a14d658c292c28ee09df4765955206c47c234fb3c5743c1415e5e90c7bb80412c2e242cd33bbe15e010
7
+ data.tar.gz: 6ba704ad7c61a2316e128fb3be63c96c49f0531760a34b201c96c796749cf973e6fe8c70531c59f3c66b69d7c14580a8aaf9190d67f852f23a592252deed0a52
data/README.md CHANGED
@@ -917,6 +917,33 @@ There's a few methods that components forward directly to its root:
917
917
 
918
918
  Thanks to this one can write just `comp.present?` instead of `comp.root.present?`.
919
919
 
920
+ ### Customized `inspect` method
921
+
922
+ This features is especially useful when using WatirPump with testing frameworks like `rspec`.
923
+
924
+ Consider the following example:
925
+
926
+ ```ruby
927
+ class MyComponent < WatirPump::Component
928
+ span_reader :name, id: 'name'
929
+ span_reader :surname, id: 'surname'
930
+ span_reader :age, id: 'age'
931
+ inspect_properties [:name, :surname, :age]
932
+ end
933
+
934
+ class HomePage < WatirPump::Page
935
+ component :details, MyComponent
936
+ end
937
+
938
+ MyPage.open do
939
+ expect(details).to have_attributes(name: 'John', surname: 'Smith')
940
+ end
941
+ ```
942
+
943
+ In case of expectation (here: `have_attributes`) not matched `rspec` will display the `expected` and `got` values.
944
+ Without the usage of `inspect_properties` the default implementation of `inspect` would be used, and it's not
945
+ very useful for test debugging since it's too verbose. Use `inspect_properties` to have your `rspec` logs easy to work with.
946
+
920
947
  ## Region aka anonymous component
921
948
 
922
949
  If certain HTML section appears only on one page (thus there's no point in creating another `Component` class)
@@ -329,6 +329,24 @@ module WatirPump
329
329
  end
330
330
  end
331
331
  end
332
+
333
+ # Define the customized `inspect` method
334
+ # that will return the desired properties
335
+ # Useful especially when working with testing frameworks that
336
+ # inspect the object under test in case of expectations not being met
337
+ #
338
+ # @param [Symbol] properties (methods) to be included in the result
339
+ #
340
+ # @return Hash
341
+ def inspect_properties(properties)
342
+ define_method :inspect do
343
+ ret = {}
344
+ properties.each do |p|
345
+ ret[p] = public_send(p)
346
+ end
347
+ ret
348
+ end
349
+ end
332
350
  end # << self
333
351
 
334
352
  # Invoked implicity by WatirPump framework.
@@ -412,6 +430,15 @@ module WatirPump
412
430
  end
413
431
  end
414
432
 
433
+ # Customized Ruby's object inspection method
434
+ #
435
+ # @return String
436
+ def inspect
437
+ # rubocop:disable Metrics/LineLength
438
+ "<#{self.class.name} parent: #{parent.class.name} methods: #{public_methods(false).join(', ')}>"
439
+ # rubocop:enable Metrics/LineLength
440
+ end
441
+
415
442
  private
416
443
 
417
444
  def form_field_writers
@@ -10,7 +10,7 @@ module WatirPump
10
10
  include Constants
11
11
 
12
12
  delegate Enumerable.instance_methods(false) => :@arr
13
- delegate %i[[] empty? each] => :@arr
13
+ delegate %i[[] empty? each inspect last] => :@arr
14
14
 
15
15
  def initialize(arr)
16
16
  @arr = arr
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_pump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartek Wilczek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-26 00:00:00.000000000 Z
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport