-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing a new testing module to replace the external gems `phlex-testing-capybara` and `phlex-testing-nokogiri`.
- Loading branch information
1 parent
815c94e
commit ceffded
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require "phlex" | ||
|
||
module Phlex::Testing | ||
autoload :SGML, "phlex/testing/sgml" | ||
autoload :Capybara, "phlex/testing/capybara" | ||
autoload :Nokogiri, "phlex/testing/nokogiri" | ||
autoload :Nokolexbor, "phlex/testing/nokolexbor" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "capybara" | ||
|
||
module Phlex::Testing::Capybara | ||
include Phlex::Testing::SGML | ||
|
||
def self.included(mod) | ||
if defined?(Minitest::Test) && Minitest::Test > mod | ||
require "capybara/minitest" | ||
include Capybara::Minitest::Assertions | ||
end | ||
|
||
if defined?(RSpec::Core::ExampleGroup) && RSpec::Core::ExampleGroup > mod | ||
require "capybara/rspec" | ||
include Capybara::RSpecMatchers | ||
end | ||
end | ||
|
||
attr_reader :page | ||
alias_method :component, :page | ||
|
||
def render(...) | ||
@page = ::Capybara::Node::Simple.new( | ||
render_to_string(...), | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "nokogiri" | ||
|
||
module Phlex::Testing::Nokogiri | ||
include Phlex::Testing::SGML | ||
|
||
def render_fragment(...) | ||
::Nokogiri::HTML5.fragment( | ||
render_to_string(...), | ||
) | ||
end | ||
|
||
def render_document(...) | ||
::Nokogiri::HTML5( | ||
render_to_string(...), | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "nokolexbor" | ||
|
||
module Phlex::Testing::Nokolexbor | ||
include Phlex::Testing::SGML | ||
|
||
def render_fragment(...) | ||
Nokolexbor::DocumentFragment.parse( | ||
render_to_string(...), | ||
) | ||
end | ||
|
||
def render_document(...) | ||
::Nokolexbor::HTML( | ||
render_to_string(...), | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Phlex::Testing::SGML | ||
def render_to_string(component, &) | ||
component.call(view_context:, &) | ||
end | ||
|
||
def view_context = nil | ||
end |