-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up matchers into separate files
- Loading branch information
Showing
15 changed files
with
328 additions
and
258 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
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rspec/rails/matchers/base_matcher" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
class Base < RSpec::Rails::Matchers::BaseMatcher | ||
attr_reader :matched | ||
|
||
def matches?(actual) | ||
@matched = super | ||
@matched.present? | ||
end | ||
end | ||
end | ||
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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require "katalyst/kpop/matchers/base" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
# @api private | ||
class CapybaraMatcher < Base | ||
attr_reader :matched | ||
|
||
def matches?(actual) | ||
super | ||
rescue ::Capybara::ElementNotFound | ||
nil | ||
end | ||
|
||
def match(expected, actual) | ||
actual.find(expected) | ||
end | ||
|
||
def description | ||
"match #{expected}" | ||
end | ||
|
||
def describe_expected | ||
expected.inspect | ||
end | ||
|
||
def describe_actual | ||
response = actual.native.children.to_html.gsub(/\s+/, " ") | ||
response = "#{response[0..120]}..." if response.length > 120 | ||
response.inspect | ||
end | ||
|
||
def failure_message | ||
"expected #{describe_expected} but received #{describe_actual} instead" | ||
end | ||
|
||
def failure_message_when_negated | ||
"expected not to find #{expected}" | ||
end | ||
end | ||
end | ||
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require "katalyst/kpop/matchers/base" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
# @api private | ||
class CapybaraParser < Base | ||
def match(_, actual) | ||
@html = Nokogiri::HTML5.parse(actual.body) | ||
Capybara::Node::Simple.new(@html) | ||
end | ||
end | ||
end | ||
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rspec/rails/matchers/base_matcher" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
# @api private | ||
class ChainedMatcher < RSpec::Rails::Matchers::BaseMatcher | ||
Input = Struct.new(:matched) | ||
|
||
delegate :failure_message, :failure_message_when_negated, to: :@matcher | ||
|
||
def initialize(*matchers) | ||
super() | ||
matchers.each { |m| self << m } | ||
end | ||
|
||
def <<(matcher) | ||
matcher = matcher.new if matcher.is_a?(Class) | ||
(@matchers ||= []) << matcher | ||
self | ||
end | ||
|
||
def match(_, actual) | ||
@matcher = Input.new(actual) | ||
@matchers.all? do |matcher| | ||
input = @matcher.matched | ||
@matcher = matcher | ||
matcher.matches?(input) | ||
end | ||
end | ||
|
||
def description | ||
@matchers.last.description | ||
end | ||
end | ||
end | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "katalyst/kpop/matchers/capybara_matcher" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
# @api private | ||
class FrameMatcher < CapybaraMatcher | ||
def initialize(id: "kpop") | ||
super("turbo-frame##{id}") | ||
end | ||
end | ||
end | ||
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "katalyst/kpop/matchers/capybara_matcher" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
# @api private | ||
class ModalMatcher < CapybaraMatcher | ||
def initialize | ||
super("[data-controller*='kpop--modal']") | ||
end | ||
|
||
def description | ||
"contain a kpop modal" | ||
end | ||
end | ||
end | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "katalyst/kpop/matchers/capybara_matcher" | ||
|
||
module Katalyst | ||
module Kpop | ||
module Matchers | ||
# @api private | ||
class RedirectFinder < CapybaraMatcher | ||
def initialize | ||
super("[data-controller='kpop--redirect']") | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.