Skip to content

Commit 6a3d358

Browse files
authored
Revert 'Expose Capybara DSL methods directly inside tests.' (#1427)
* Revert * Update CHANGELOG.md
1 parent cfea083 commit 6a3d358

File tree

8 files changed

+7
-332
lines changed

8 files changed

+7
-332
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ title: Changelog
99

1010
## main
1111

12+
* Revert `Expose Capybara DSL methods directly inside tests.` This change unintentionally broke other Capybara methods and thus introduced a regression. We aren't confident that we can fail forward so we have decided to revert this change.
13+
14+
*Joel Hawksley*, *Blake Williams*
15+
1216
* Revert change making content evaluation consistent.
1317

1418
*Blake Williams*

docs/guide/testing.md

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,9 @@ class ExampleComponentTest < ViewComponent::TestCase
2222
end
2323
```
2424

25-
_Note: `assert_selector` only matches on visible elements by default. To match on elements regardless of visibility, add `visible: false`. See the [Capybara documentation](https://rubydoc.info/github/jnicklas/capybara/Capybara/Node/Matchers) for more details._
25+
(Capybara matchers are available if the gem is installed)
2626

27-
## Capybara helpers
28-
29-
The following Capybara helpers are available if `capybara` is installed:
30-
31-
* [`all`](https://rubydoc.info/github/teamcapybara/capybara/Capybara%2FNode%2FFinders:all)
32-
* [`first`](https://rubydoc.info/github/teamcapybara/capybara/Capybara%2FNode%2FFinders:first)
33-
* [`text`](https://rubydoc.info/github/teamcapybara/capybara/Capybara%2FNode%2FSimple:text)
34-
* [`find`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find)
35-
* [`find_all`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_all)
36-
* [`find_button`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_button)
37-
* [`find_by_id`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_by_id)
38-
* [`find_field`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_field)
39-
* [`find_link`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FFinders:find_link)
40-
* [`has_content?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_content%3F)
41-
* [`has_text?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_text%3F)
42-
* [`has_css?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_css%3F)
43-
* [`has_no_content?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_content%3F)
44-
* [`has_no_text?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_text%3F)
45-
* [`has_no_css?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_css%3F)
46-
* [`has_no_xpath?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_xpath%3F)
47-
* [`has_xpath?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_xpath%3F)
48-
* [`has_link?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_link%3F)
49-
* [`has_no_link?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_link%3F)
50-
* [`has_button?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_button%3F)
51-
* [`has_no_button?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_button%3F)
52-
* [`has_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_field%3F)
53-
* [`has_no_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_field%3F)
54-
* [`has_checked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_checked_field%3F)
55-
* [`has_unchecked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_unchecked_field%3F)
56-
* [`has_no_table?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_table%3F)
57-
* [`has_table?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_table%3F)
58-
* [`has_select?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_select%3F)
59-
* [`has_no_select?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_select%3F)
60-
* [`has_selector?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_selector%3F)
61-
* [`has_no_selector?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_selector%3F)
62-
* [`has_no_checked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_checked_field%3F)
63-
* [`has_no_unchecked_field?`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FNode%2FMatchers:has_no_unchecked_field%3F)
64-
* [`within`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within)
65-
* [`within_element`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within)
66-
* [`within_fieldset`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within_fieldset)
67-
* [`within_table`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara%2FSession:within_table)
27+
_Note: `assert_selector` only matches on visible elements by default. To match on elements regardless of visibility, add `visible: false`. See the [Capybara documentation](https://rubydoc.info/github/jnicklas/capybara/Capybara/Node/Matchers) for more details._
6828

6929
## Previews as test cases
7030

lib/view_component.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module ViewComponent
77
extend ActiveSupport::Autoload
88

99
autoload :Base
10-
autoload :CapybaraSimpleSession
1110
autoload :Compiler
1211
autoload :CompileCache
1312
autoload :ComponentError

lib/view_component/capybara_simple_session.rb

Lines changed: 0 additions & 132 deletions
This file was deleted.

lib/view_component/test_helpers.rb

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "view_component/render_preview_helper"
4-
require "view_component/capybara_simple_session"
54

65
module ViewComponent
76
module TestHelpers
@@ -10,28 +9,8 @@ module TestHelpers
109

1110
include Capybara::Minitest::Assertions
1211

13-
CapybaraSimpleSession::DSL_METHODS.each do |method|
14-
if RUBY_VERSION >= "2.7"
15-
class_eval <<~METHOD, __FILE__, __LINE__ + 1
16-
def #{method}(...)
17-
page.method("#{method}").call(...)
18-
end
19-
METHOD
20-
else
21-
define_method method do |*args, &block|
22-
page.send method, *args, &block
23-
end
24-
end
25-
end
26-
27-
def self.included(mod)
28-
Capybara::Node::Simple.send(:define_method, :to_capybara_node) do
29-
self
30-
end
31-
end
32-
3312
def page
34-
@page ||= CapybaraSimpleSession.new(rendered_content)
13+
@page ||= Capybara::Node::Simple.new(rendered_content)
3514
end
3615

3716
def refute_component_rendered

test/sandbox/app/components/capybara_dsl_component.html.erb

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/sandbox/app/components/capybara_dsl_component.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/sandbox/test/capybara_dsl_test.rb

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)