diff --git a/.yard/templates_custom/default/class/html/selectors.erb b/.yard/templates_custom/default/class/html/selectors.erb index 50037ff5..8180ec21 100644 --- a/.yard/templates_custom/default/class/html/selectors.erb +++ b/.yard/templates_custom/default/class/html/selectors.erb @@ -4,10 +4,15 @@ <% @selectors.each do |name, selector| %>
  • :<%= name %>

    +
    +
    +

    <%= h(selector.docstring) %>

    +
    +

    Locator:

    <% if locator=selector.tag('locator') %> -

    <%= locator.text %>

    +

    <%= h locator.text %>

    <% end %> <% if selector.has_tag?('filter') %>

    Filters:

    @@ -16,11 +21,11 @@
  • <%= filter.name %> <% if filter.types %> - (<%= filter.types.join(', ') %>) + (<%= h(filter.types.join(', ')) %>) <% end %> <% if filter.text %> — -

    <%= filter.text %>

    +

    <%= h filter.text %>

    <% end %>
  • <% end %> diff --git a/.yard/yard_extensions.rb b/.yard/yard_extensions.rb index 64f76506..cc5bbbd2 100644 --- a/.yard/yard_extensions.rb +++ b/.yard/yard_extensions.rb @@ -22,9 +22,6 @@ class AddSelectorHandler < YARD::Handlers::Ruby::Base # modify the object object.dynamic = true - - # add custom metadata to the object - object['custom_field'] = 'Generated by add_selector' end end diff --git a/Rakefile b/Rakefile index 280cbc04..51736c94 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,6 @@ require 'rubygems' require 'rspec/core/rake_task' require 'cucumber/rake/task' require 'yard' -require_relative './.yard/yard_extensions' desc "Run all examples" RSpec::Core::RakeTask.new(:spec) do |t| diff --git a/capybara.gemspec b/capybara.gemspec index 31c4d0fe..9c0beb44 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| 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.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.require_paths = ["lib"] diff --git a/lib/capybara/selector.rb b/lib/capybara/selector.rb index c6ed2927..86133b49 100644 --- a/lib/capybara/selector.rb +++ b/lib/capybara/selector.rb @@ -18,6 +18,9 @@ Capybara::Selector::FilterSet.add(:_field) do end end +## +# +# Select elements by XPath expression # # @locator An XPath expression # @@ -25,6 +28,9 @@ Capybara.add_selector(:xpath) do xpath { |xpath| xpath } end +## +# +# Select elements by CSS selector # # @locator A CSS selector # @@ -32,13 +38,18 @@ Capybara.add_selector(:css) do css { |css| css } end +## +# +# Select element by id # # @locator The id of the element to match # Capybara.add_selector(:id) do xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] } end - +## +# +# Select field elements (input [not of type submit, image, or hidden], textarea, select) # # @locator Matches against the id, name, or placeholder # @filter [String] :id Matches the id attribute @@ -82,6 +93,9 @@ Capybara.add_selector(:field) do end end +## +# +# Select fieldset elements # # @locator Matches id or contents of wrapped legend # @@ -99,6 +113,10 @@ Capybara.add_selector(:fieldset) do xpath end end + +## +# +# Find links ( 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 # @@ -136,6 +154,10 @@ Capybara.add_selector(:link) do describe { |options| " with href #{options[:href].inspect}" if options[:href] } end +## +# +# Find buttons ( input [of type submit, reset, image, button] or button elements ) +# Capybara.add_selector(:button) do xpath(:id, :value, :title, :class) do |locator, options={}| 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 +## +# +# Find links or buttons +# Capybara.add_selector(:link_or_button) do label "link or button" xpath do |locator, options| @@ -184,6 +210,10 @@ Capybara.add_selector(:link_or_button) do describe { |options| " that is disabled" if options[:disabled] } end +## +# +# Find text fillable fields ( textarea, input [not of type submit, image, radio, checkbox, hidden, file] ) +# Capybara.add_selector(:fillable_field) do label "field" xpath(:id, :name, :placeholder, :class) do |locator, options| @@ -200,6 +230,10 @@ Capybara.add_selector(:fillable_field) do end end +## +# +# Find radio buttons +# Capybara.add_selector(:radio_button) do label "radio button" xpath(:id, :name, :class) do |locator, options| @@ -219,6 +253,10 @@ Capybara.add_selector(:radio_button) do end end +## +# +# Find checkboxes +# Capybara.add_selector(:checkbox) do xpath(:id, :name, :class) do |locator, options| xpath = XPath.descendant(:input)[XPath.attr(:type).equals('checkbox')] @@ -237,6 +275,10 @@ Capybara.add_selector(:checkbox) do end end +## +# +# Find select elements +# Capybara.add_selector(:select) do label "select box" xpath(:id, :name, :placeholder, :class) do |locator, options| @@ -276,6 +318,10 @@ Capybara.add_selector(:select) do end end +## +# +# Find option elements +# Capybara.add_selector(:option) do xpath do |locator| xpath = XPath.descendant(:option) @@ -294,6 +340,10 @@ Capybara.add_selector(:option) do end end +## +# +# Find file input elements +# Capybara.add_selector(:file_field) do label "file field" xpath(:id, :name, :class) do |locator, options| @@ -310,6 +360,10 @@ Capybara.add_selector(:file_field) do end end +## +# +# Find label elements +# Capybara.add_selector(:label) do label "label" xpath do |locator| @@ -337,6 +391,10 @@ Capybara.add_selector(:label) do end end +## +# +# Find table elements +# Capybara.add_selector(:table) do xpath(:id, :caption, :class) do |locator, options| xpath = XPath.descendant(:table) @@ -354,6 +412,10 @@ Capybara.add_selector(:table) do end end +## +# +# Find frame/iframe elements +# Capybara.add_selector(:frame) do xpath(:id, :name, :class) do |locator, options| xpath = XPath.descendant(:iframe) + XPath.descendant(:frame)