Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Chop up all the cucumbers into a fresh delicious salad.
Ruby Cucumber
Pull request Compare This branch is 2 commits ahead, 177 commits behind master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
features
lib
spec
.gitignore
Gemfile
LICENSE
README.md
dill.gemspec

README.md

Dill

Write tastier tests.

Installation

Add dill to your Gemfile. Then add require 'dill/cucumber' to features/support/00_dill.rb.

  • We prefix the file name with 00_ to ensure it's loaded as soon as possible during cucumber boot.

Documentation

See the docs for master.

Widgets

The widgets API is an implementation of the Page Object pattern, with a twist.

Your First Widget

Given the following HTML:

<body>
  <span id="my-widget">My Widget</span>
</body>

You can define a widget as follows:

class MyWidget < Dill::Widget
  root '#my-widget'
end

So, to create a widget, simply extend Dill::Widget (or one of its subclasses) and define the widget's root element.

As long as you include Dill::DSL (done automatically if you require dill/cucumber), you can then get a reference to the widget using #widget, like this:

my_widget = widget(:my_widget)

Philosophy

A test is typically comprised of 3 phases: Arrange (Given), Act (When) and Assert (Then). Widgets care about Act and Assert, so they let you

  1. do things, and
  2. verify things

much like Capybara, but in a more object-oriented manner. So, for example, where, in Capybara, you would test if a node contains some text like this:

expect(page).to have_selector('#my-widget', text: 'My Widget')

you can do the samething using Dill, like this:

expect(widget(:my_widget)).to eq 'My Widget'

This works even if the widget isn't visible yet because, when called, Widget#== assumes that it's expected to return true. If it can't return true, then it will wait a certain amount of time until it can, or, finally, it will give up and return false. The same thing happens with all other operators defined on Widget: !=, >, >=, <, <=, =~ and !~. So remember this: some widget methods will block until they return true, or some pre-defined time passes.

You can take advantage of the OO-nature of the widget API to customize how a widget presents itself to the world. Just override the widget's #value method:

class MyWidget < Dill::Widget
  root '#my-widget'

  def value
    # unsurprisingly, #text returns the widget's text
    text + ", eh?"
  end
end

# use it:

expect(widget(:my_widget)).to eq 'My Widget, eh?'
expect(widget(:my_widget)).to include 'My'

See the documentation for Dill::Widget for information on how to use basic widgets.

Forms

TODO

Lists

See the documentation for Dill::List.

Tables

TODO

The top level document

TODO

Something went wrong with that request. Please try again.