1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Add custom yard extensions to the Gem

This commit is contained in:
Thomas Walpole 2016-09-09 16:44:32 -07:00
parent f706b123d0
commit 22f39b1caf
5 changed files with 72 additions and 9 deletions

View file

@ -4,10 +4,15 @@
<% @selectors.each do |name, selector| %> <% @selectors.each do |name, selector| %>
<li> <li>
<h3>:<%= name %></h3> <h3>:<%= name %></h3>
<div class="docstring">
<div class="discussion">
<p><%= h(selector.docstring) %></p>
</div>
</div>
<div class="tags"> <div class="tags">
<p class="inline">Locator:</p> <p class="inline">Locator:</p>
<% if locator=selector.tag('locator') %> <% if locator=selector.tag('locator') %>
<p class="inline"><%= locator.text %></p> <p class="inline"><%= h locator.text %></p>
<% end %> <% end %>
<% if selector.has_tag?('filter') %> <% if selector.has_tag?('filter') %>
<p>Filters:</p> <p>Filters:</p>
@ -16,11 +21,11 @@
<li> <li>
<span class="name"><%= filter.name %></span> <span class="name"><%= filter.name %></span>
<% if filter.types %> <% if filter.types %>
<span class="type">(<tt><%= filter.types.join(', ') %></tt>)</span> <span class="type">(<tt><%= h(filter.types.join(', ')) %></tt>)</span>
<% end %> <% end %>
<% if filter.text %> <% if filter.text %>
<div class="inline"><p><%= filter.text %></p></div> <div class="inline"><p><%= h filter.text %></p></div>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>

View file

@ -22,9 +22,6 @@ class AddSelectorHandler < YARD::Handlers::Ruby::Base
# modify the object # modify the object
object.dynamic = true object.dynamic = true
# add custom metadata to the object
object['custom_field'] = 'Generated by add_selector'
end end
end end

View file

@ -2,7 +2,6 @@ require 'rubygems'
require 'rspec/core/rake_task' require 'rspec/core/rake_task'
require 'cucumber/rake/task' require 'cucumber/rake/task'
require 'yard' require 'yard'
require_relative './.yard/yard_extensions'
desc "Run all examples" desc "Run all examples"
RSpec::Core::RakeTask.new(:spec) do |t| RSpec::Core::RakeTask.new(:spec) do |t|

View file

@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.email = ["twalpole@gmail.com", "jonas.nicklas@gmail.com"] s.email = ["twalpole@gmail.com", "jonas.nicklas@gmail.com"]
s.description = "Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website" s.description = "Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website"
s.files = Dir.glob("{lib,spec}/**/*") + %w(README.md History.md License.txt) s.files = Dir.glob("{lib,spec,.yard}/**/*") + %w(README.md History.md License.txt .yardopts)
s.homepage = "https://github.com/jnicklas/capybara" s.homepage = "https://github.com/jnicklas/capybara"
s.require_paths = ["lib"] s.require_paths = ["lib"]

View file

@ -18,6 +18,9 @@ Capybara::Selector::FilterSet.add(:_field) do
end end
end end
##
#
# Select elements by XPath expression
# #
# @locator An XPath expression # @locator An XPath expression
# #
@ -25,6 +28,9 @@ Capybara.add_selector(:xpath) do
xpath { |xpath| xpath } xpath { |xpath| xpath }
end end
##
#
# Select elements by CSS selector
# #
# @locator A CSS selector # @locator A CSS selector
# #
@ -32,13 +38,18 @@ Capybara.add_selector(:css) do
css { |css| css } css { |css| css }
end end
##
#
# Select element by id
# #
# @locator The id of the element to match # @locator The id of the element to match
# #
Capybara.add_selector(:id) do Capybara.add_selector(:id) do
xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] } xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
end end
##
#
# Select field elements (input [not of type submit, image, or hidden], textarea, select)
# #
# @locator Matches against the id, name, or placeholder # @locator Matches against the id, name, or placeholder
# @filter [String] :id Matches the id attribute # @filter [String] :id Matches the id attribute
@ -82,6 +93,9 @@ Capybara.add_selector(:field) do
end end
end end
##
#
# Select fieldset elements
# #
# @locator Matches id or contents of wrapped legend # @locator Matches id or contents of wrapped legend
# #
@ -99,6 +113,10 @@ Capybara.add_selector(:fieldset) do
xpath xpath
end end
end end
##
#
# Find links ( <a> elements with an href attribute )
# #
# @locator Matches the id or title attributes, or the string content of the link, or the alt attribute of a contained img element # @locator Matches the id or title attributes, or the string content of the link, or the alt attribute of a contained img element
# #
@ -136,6 +154,10 @@ Capybara.add_selector(:link) do
describe { |options| " with href #{options[:href].inspect}" if options[:href] } describe { |options| " with href #{options[:href].inspect}" if options[:href] }
end end
##
#
# Find buttons ( input [of type submit, reset, image, button] or button elements )
#
Capybara.add_selector(:button) do Capybara.add_selector(:button) do
xpath(:id, :value, :title, :class) do |locator, options={}| xpath(:id, :value, :title, :class) do |locator, options={}|
input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')] input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')]
@ -173,6 +195,10 @@ Capybara.add_selector(:button) do
end end
end end
##
#
# Find links or buttons
#
Capybara.add_selector(:link_or_button) do Capybara.add_selector(:link_or_button) do
label "link or button" label "link or button"
xpath do |locator, options| xpath do |locator, options|
@ -184,6 +210,10 @@ Capybara.add_selector(:link_or_button) do
describe { |options| " that is disabled" if options[:disabled] } describe { |options| " that is disabled" if options[:disabled] }
end end
##
#
# Find text fillable fields ( textarea, input [not of type submit, image, radio, checkbox, hidden, file] )
#
Capybara.add_selector(:fillable_field) do Capybara.add_selector(:fillable_field) do
label "field" label "field"
xpath(:id, :name, :placeholder, :class) do |locator, options| xpath(:id, :name, :placeholder, :class) do |locator, options|
@ -200,6 +230,10 @@ Capybara.add_selector(:fillable_field) do
end end
end end
##
#
# Find radio buttons
#
Capybara.add_selector(:radio_button) do Capybara.add_selector(:radio_button) do
label "radio button" label "radio button"
xpath(:id, :name, :class) do |locator, options| xpath(:id, :name, :class) do |locator, options|
@ -219,6 +253,10 @@ Capybara.add_selector(:radio_button) do
end end
end end
##
#
# Find checkboxes
#
Capybara.add_selector(:checkbox) do Capybara.add_selector(:checkbox) do
xpath(:id, :name, :class) do |locator, options| xpath(:id, :name, :class) do |locator, options|
xpath = XPath.descendant(:input)[XPath.attr(:type).equals('checkbox')] xpath = XPath.descendant(:input)[XPath.attr(:type).equals('checkbox')]
@ -237,6 +275,10 @@ Capybara.add_selector(:checkbox) do
end end
end end
##
#
# Find select elements
#
Capybara.add_selector(:select) do Capybara.add_selector(:select) do
label "select box" label "select box"
xpath(:id, :name, :placeholder, :class) do |locator, options| xpath(:id, :name, :placeholder, :class) do |locator, options|
@ -276,6 +318,10 @@ Capybara.add_selector(:select) do
end end
end end
##
#
# Find option elements
#
Capybara.add_selector(:option) do Capybara.add_selector(:option) do
xpath do |locator| xpath do |locator|
xpath = XPath.descendant(:option) xpath = XPath.descendant(:option)
@ -294,6 +340,10 @@ Capybara.add_selector(:option) do
end end
end end
##
#
# Find file input elements
#
Capybara.add_selector(:file_field) do Capybara.add_selector(:file_field) do
label "file field" label "file field"
xpath(:id, :name, :class) do |locator, options| xpath(:id, :name, :class) do |locator, options|
@ -310,6 +360,10 @@ Capybara.add_selector(:file_field) do
end end
end end
##
#
# Find label elements
#
Capybara.add_selector(:label) do Capybara.add_selector(:label) do
label "label" label "label"
xpath do |locator| xpath do |locator|
@ -337,6 +391,10 @@ Capybara.add_selector(:label) do
end end
end end
##
#
# Find table elements
#
Capybara.add_selector(:table) do Capybara.add_selector(:table) do
xpath(:id, :caption, :class) do |locator, options| xpath(:id, :caption, :class) do |locator, options|
xpath = XPath.descendant(:table) xpath = XPath.descendant(:table)
@ -354,6 +412,10 @@ Capybara.add_selector(:table) do
end end
end end
##
#
# Find frame/iframe elements
#
Capybara.add_selector(:frame) do Capybara.add_selector(:frame) do
xpath(:id, :name, :class) do |locator, options| xpath(:id, :name, :class) do |locator, options|
xpath = XPath.descendant(:iframe) + XPath.descendant(:frame) xpath = XPath.descendant(:iframe) + XPath.descendant(:frame)