VIew helpers for building views that are easily inspected via Capybara so you don't have to care about markup.
Go to file
John Bintz 1f83533d8a Merge branch 'master' of 2014-04-28 18:58:23 -04:00
lib Merge branch 'master' of 2014-04-28 18:58:23 -04:00
.gitignore initial commit, messing around 2012-11-19 08:39:43 -05:00
Gemfile initial commit, messing around 2012-11-19 08:39:43 -05:00
LICENSE initial commit, messing around 2012-11-19 08:39:43 -05:00 extend dont_find to Capybara::Element 2013-02-25 13:50:25 -05:00
Rakefile initial commit, messing around 2012-11-19 08:39:43 -05:00
semantic_rails_view_helpers.gemspec will need to include capybara and rspec elsewhere for this to work nicely 2013-01-04 10:21:53 -05:00

Make your Rails Capybara testing even faster and more accurate! Looking for hardcoded text strings is for the birds.

A lot of this assumes you're using a form builder to generate forms, like Formtastic. It's faster that way.

Your Views

It's easier to find things in Capybara tests if you add extra data attributes to fields and such. This gem does that for you if you link to and refer to things in a certain way. If you do, your tests turn from text blob and CSS selector messes to nice, clean, simple references to objects and attributes.

Linking to things

Link to things using link_to_model, link_to_model_action, link_to_collection, and link_to_route. Data attributes will be added that Capybara can then find later, and quickly:

  = link_to_route :root
  = link_to_collection [ :admin, :users ]
  = link_to_model current_user
  = link_to_model_action current_user, :edit
# finding those things

within '#menu' do

Form fields

Don't worry about tying your field entry with text labels. It's much easier to look for attributes by name:

find_input(:first_name).set("first name")
find_input(:last_name).set("last name")
set_input(:gender, 'male')


Write out attributes using attributes_for:

  = attributes_for object do |f|
    %h2= f.field(:name)
    %h3= f.field(:description)

Then look for those fields using Capybara! Because you shouldn't care about the DOM, just that your field is in there:

@object = Object.create!(:name => @name, :description => @description)

visit object_path(@object)

find_attribute(:description, @object.description)

You can even make simple tables, a la Active Admin:

  = attributes_table_for object do |f|
    = f.field :name
    = f.field :description

Active Admin

You can add semantic data to Active Admin's attributes_tables in show views. Just require 'semantic_rails_view_helpers/active_admin' in an initializer and you can then target attributes in show views.

Not Finding Things

Sometimes the absence of a thing is just as important as the presence of a thing. Make it easy on yourself:

# selector's not there


# ...after you've already found something...