Giter Site home page Giter Site logo

itspriddle / splinter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from envato-archive/splinter

0.0 2.0 0.0 51 KB

Chop your specs in half with Splinter, a collection of helpers to submit forms with RSpec and Capybara.

Home Page: http://www.eng5.com

License: Other

Ruby 57.97% HTML 42.03%

splinter's Introduction

Splinter Splinter Build Status

Splinter is a Capybara Ninja. It provides some helpers to aid with filling in Rails forms.

Bonus: Splinter also includes a few performance tweaks which can be used to speed up test suites. These are opt-in.

Splinter has been tested on MRI 2.1.8, 2.2.4 and 2.3.0.

Installation

gem 'splinter'
bundle install

Add to spec_helper.rb:

require 'splinter/rspec'

Performance Tweaks

Capybara runs in a different thread when the driver is not rack-test. This can cause issues with transactional fixtures as ActiveRecord normally creates a new connection per-thread. If you need to force ActiveRecord to share the connection between threads, add the following to spec_helper:

require 'splinter/rspec/shared_connection'

While not technically related to Capybara, the following GC tweak can increase run time by 10% or more in some suites. To enable it, add the following to spec_helper:

require 'splinter/rspec/deferred_garbage_collection'

Screenshots

To capture screenshots on failure, add the following to spec_helper:

Splinter.screenshot_directory = "/path/to/screenshots"

Date/Time/Datetime Helpers

These are mostly borrowed from Hermes::Actions. They're useful for completing the multiple dropdowns required for a date/time/datetime field in a Rails form.

# Select by CSS ID
select_date Time.now, :id_prefix => :publish_at

# Select by label text, label must have for="id_prefix"
select_date Time.now, :from => "Publish at"

There are also select_time, and select_datetime variants with the same usage.

Completing Forms

Here's a little sugar to help complete Rails forms:

complete_form :post do |f|
  f.text_field :name, "I like turtles!"
  f.date       :publish_at, 3.days.from_now
  f.select     :category, "Blog Posts"
  f.checkbox   :published, false
end

After the block is evaluated, the form is completed and submitted.

Javascript Confirm

You can use these helpers to confirm/cancel a javascript "confirm":

javascript_confirm        { click_link "Destroy" }
javascript_confirm(false) { click_link "Destroy" }

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not bump version. (If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull).
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2016 Pressed, LLC. See LICENSE for details.

splinter's People

Contributors

itspriddle avatar fabiokr avatar boone avatar jmazzi avatar tfwright avatar rubemz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.