Skip to content

Commit

Permalink
Add additional tests to showcase other use-cases (#33)
Browse files Browse the repository at this point in the history
This commit adds a test to verify that a selector with dynamic options
can use keyword arguments to generate dynamic options.

Additionally, an additional method and expectation is defined to show
how to define predicate matchers for a parent element that utilize a
child element for assertion. I couldn't find an example of this pattern
already in the tests, but if you feel this is already covered please let
me know and I'll update the commit.
  • Loading branch information
eebs authored Jul 25, 2023
1 parent 332fe4b commit bcc4dbd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion spec/features/has_one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
def heading_tag_name
heading.tag_name
end

def named?(name)
heading.has_text?(name)
end
end

def section_heading_tag_name
Expand All @@ -89,6 +93,7 @@ def section_heading_tag_name

expect(test_page.section.heading_tag_name).to eq("h2")
expect(test_page.section_heading_tag_name).to eq("h2")
expect(test_page.section).to be_named("Section Heading")
end

it "behaves as Capybara would when there's an ambiguous match" do
Expand All @@ -110,7 +115,7 @@ def section_heading_tag_name
expect { test_page.list.item }.to raise_error(Capybara::Ambiguous)
end

it "allows for passing arguments to carry through to Capybara arguments" do
it "allows for passing positional arguments to carry through to Capybara arguments" do
page = build_page(<<-HTML)
<ul>
<li>Item 1</li>
Expand All @@ -133,6 +138,29 @@ def section_heading_tag_name
expect(test_page.list).not_to have_item_named("Item 3")
end

it "allows for passing keyword arguments to carry through to Capybara arguments" do
page = build_page(<<-HTML)
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
HTML

test_page = Class.new(PageEz::Page) do
has_one :list, "ul" do
has_one :item_named, "li", ->(name:) { {text: name} }
end
end.new(page)

page.visit "/"

expect(test_page.list.item_named(name: "Item 1")).to be_visible

expect(test_page.list).to have_item_named(name: "Item 1")
expect(test_page.list).to have_item_named(name: "Item 2")
expect(test_page.list).not_to have_item_named(name: "Item 3")
end

it "allows for passing constant values through to Capybara arguments" do
page = build_page(<<-HTML)
<ul>
Expand Down

0 comments on commit bcc4dbd

Please sign in to comment.