capybara_test_helpers 1.0.3 → 1.0.4

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: 6f4a30d6c705cf0796a86df659b86b09f110a545e910a38185409ddaed812645
4
- data.tar.gz: 6e76655a1cc49c9b5242d023bb4085cf3aed55ae9fa4bbbf9db5b8deb21b3f8c
3
+ metadata.gz: d725477cf4351a38ec85f06dfce971c56bb356c636f31e4e4cbc3d0801e59907
4
+ data.tar.gz: ac823a9d93f09d45bc99dc2cc01fcbd2ca846d0e50eef7e38825c65f64c76b4b
5
5
  SHA512:
6
- metadata.gz: 3d23884f2f698a54b637786ebe9afd9ea5f723405672713ca5e26f474076a3d956aad1257e8f3303ee0ec47339f2a7feb75ff41f772d2ed3af261856243c1aa7
7
- data.tar.gz: 65851bd3bf3fec126c3d91cf111eed65e1e093540e06fb9e9b1b8e2b1fb4102dbc2f4cdd157d0da97aae6cce4c1273a7096770ecff23cb8eeaea7666dc8431b5
6
+ metadata.gz: c0e9719e25cba88805c39c9afc974deb21956faf8ccd06e4851680fea4b8d7f4b819753672aac329b5e35127ed25bd9de512b89a5f4a0105a768cbabe0312c73
7
+ data.tar.gz: 1049f15f89958182898fd9779d26ea003da857ebd9c20f6e2f355f5cb9553a9138c162f4c84c972d3763780915595a60a51d2e9c36800147fe911bc103472eaf
@@ -1,3 +1,10 @@
1
+ ## Capybara Test Helpers 1.0.4 (2020-11-26) ##
2
+
3
+ * Add `have_no` alias for `have_no_selector`.
4
+ * Add `has_no?` alias for `has_no_selector?`.
5
+ * Remove internal method `wrap_test_helper`.
6
+ * Allow to use locator aliases in `assert_` methods as well, for consistency.
7
+
1
8
  ## Capybara Test Helpers 1.0.3 (2020-11-24) ##
2
9
 
3
10
  * Add `CapybaraTestHelpers::BenchmarkHelpers`
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  [docs]: https://capybara-test-helpers.netlify.app/
2
+ [api]: https://capybara-test-helpers.netlify.app/api/
2
3
  [design patterns]: https://capybara-test-helpers.netlify.app/guide/advanced/design-patterns
3
4
  [installation]: https://capybara-test-helpers.netlify.app/installation
4
5
  [capybara]: https://github.com/teamcapybara/capybara
5
- [capybara dsl]: https://github.com/teamcapybara/capybara#the-dsl
6
6
  [capybara querying]: https://github.com/teamcapybara/capybara#querying
7
7
  [cucumber]: https://github.com/cucumber/cucumber-ruby
8
8
  [rspec]: https://github.com/rspec/rspec
@@ -51,7 +51,7 @@ Write tests that everyone can understand, and leverage your Ruby skills to keep
51
51
 
52
52
  ## Documentation 📖
53
53
 
54
- [Visit the documentation website][docs] to check out the guides, API reference, and examples.
54
+ [Visit the documentation website][docs] to check out the guides, [API reference][api], and examples.
55
55
 
56
56
  ## Installation 💿
57
57
 
@@ -5,8 +5,8 @@ require 'capybara_test_helpers/to_or_expectation_handler'
5
5
  # Internal: Wraps RSpec matchers to allow using them after calling `should` or
6
6
  # `should_not` to perform the assertion.
7
7
  module CapybaraTestHelpers::Assertions
8
- # Public: Allows writing custom on-demand matchers, as well as chaining
9
- # several assertions.
8
+ # Public: Returns a test helper with a positive assertion state.
9
+ # Any assertions called after it will execute as `expect(...).to ...`.
10
10
  def should(negated = false)
11
11
  negated = !!negated # Coerce to boolean.
12
12
  return self if negated == @negated
@@ -15,8 +15,8 @@ module CapybaraTestHelpers::Assertions
15
15
  end
16
16
  [:should_still, :should_now, :and, :and_instead, :and_also, :and_still].each { |should_alias| alias_method should_alias, :should }
17
17
 
18
- # Public: Allows writing custom on-demand matchers, as well as chaining
19
- # several assertions.
18
+ # Public: Returns a test helper with a negative assertion state.
19
+ # Any assertions called after it will execute as `expect(...).not_to ...`.
20
20
  def should_not
21
21
  @negated ? self : should(true)
22
22
  end
@@ -102,6 +102,8 @@ module CapybaraTestHelpers::Assertions
102
102
  end
103
103
  end
104
104
 
105
+ alias have_no have_no_selector
106
+
105
107
  # Public: Allows to check on any input value asynchronously.
106
108
  def have_value(expected_value, **options)
107
109
  synchronize_expectation(**options) { expect(value).to_or not_to, eq(expected_value) }
@@ -53,5 +53,27 @@ module CapybaraTestHelpers::Matchers
53
53
  CapybaraTestHelpers.define_helper_method(self, method_name, target: :to_capybara_node)
54
54
  end
55
55
 
56
+ %i[
57
+ assert_selector
58
+ assert_all_of_selectors
59
+ assert_none_of_selectors
60
+ assert_any_of_selectors
61
+ assert_no_selector
62
+ ].each do |method_name|
63
+ CapybaraTestHelpers.define_helper_method(self, method_name)
64
+ end
65
+
66
+ %i[
67
+ assert_matches_selector
68
+ assert_not_matches_selector
69
+ assert_ancestor
70
+ assert_no_ancestor
71
+ assert_sibling
72
+ assert_no_sibling
73
+ ].each do |method_name|
74
+ CapybaraTestHelpers.define_helper_method(self, method_name, target: :to_capybara_node)
75
+ end
76
+
56
77
  alias has? has_selector?
78
+ alias has_no? has_no_selector?
57
79
  end
@@ -60,18 +60,16 @@ class CapybaraTestHelpers::TestHelper
60
60
  raise_missing_element_error
61
61
  end
62
62
 
63
- # Public: Wraps a Capybara::Node::Element with a test helper object.
64
- def wrap_element(capybara_node)
65
- if capybara_node.is_a?(Enumerable)
66
- capybara_node.map { |node| wrap_element(node) }
63
+ # Public: Wraps a Capybara::Node::Element or test helper with a test helper
64
+ # object of this class.
65
+ def wrap_element(element)
66
+ if element.is_a?(Enumerable)
67
+ element.map { |node| wrap_element(node) }
67
68
  else
68
- self.class.new(capybara_node, test_context: test_context)
69
- end
70
- end
69
+ raise ArgumentError, "#{ element.inspect } must be a test helper or element." unless element.respond_to?(:to_capybara_node)
71
70
 
72
- # Public: Wraps a CapybaraTestHelper with a different test helper object.
73
- def wrap_test_helper(test_helper)
74
- self.class.new(test_helper.query_context, test_context: test_context) if test_helper.query_context
71
+ self.class.new(element.to_capybara_node, test_context: test_context)
72
+ end
75
73
  end
76
74
 
77
75
  # Public: Scopes the Capybara queries in the block to be inside the specified
@@ -140,7 +138,7 @@ private
140
138
  delegate(*method_names, to: :test_context)
141
139
  end
142
140
 
143
- # Public: Allows to define dependencies on other matchers.
141
+ # Public: Allows to make other test helpers available.
144
142
  #
145
143
  # NOTE: When you call a helper the "negated" state is preserved for assertions.
146
144
  #
@@ -153,11 +151,7 @@ private
153
151
  helper_names.each do |helper_name|
154
152
  private define_method(helper_name) { |element = nil|
155
153
  test_helper = test_context.get_test_helper(helper_name)
156
- if element
157
- raise ArgumentError, "#{ element.inspect } must be a test helper or element." unless element.respond_to?(:to_capybara_node)
158
-
159
- test_helper = test_helper.wrap_element(element.to_capybara_node)
160
- end
154
+ test_helper = test_helper.wrap_element(element) if element
161
155
  @negated.nil? ? test_helper : test_helper.should(@negated)
162
156
  }
163
157
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Easily write fluent Page Objects for Capybara in Ruby.
4
4
  module CapybaraTestHelpers
5
- VERSION = '1.0.3'
5
+ VERSION = '1.0.4'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara_test_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximo Mussini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2020-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport