Giter Club home page Giter Club logo

spectie's Introduction

Spectie

Spectie (rhymes with “necktie”) is a pure Ruby behavior-driven integration testing framework for RSpec.

Spectie was written with the following beliefs:

  • Business stakeholders or analysts are often not writing comprehensive (or any) acceptance criteria.

  • Business stakeholders or analysts are usually unwilling or unable to follow a strict format for writing the acceptance criteria that they are writing.

  • On many projects, the communication with the business stakeholders or analysts are accessible enough that written acceptance criteria is not necessary, but discussed requirements still need to be implemented, and therefore need to be tested.

  • Good developers recognize the benefits of top-down, BDD-style integration testing in helping to ensure that the code that is written to implement a feature directly satisfies business requirements, and doesn’t get over-engineered or over-complicated.

  • Good developers love Ruby.

Spectie tries to strike the proper balance between writing readable tests, and just getting your work done in the most efficient way possible. It does this by providing a consistent structure for writing your integration test code in a BDD fashion, with the breakdown of features, scenarios, and their given/when/then statements. However, a little bit of syntactic sugar goes a long way to aid in the understanding of code, while too much can add unnecessary complexity and actually decrease maintainability. So, Spectie keeps things pretty close to the underlying technology at all times, since most of the time, it’s a developer that’s really writing the tests.

With these ideas in mind, what Spectie provides is:

  • A small number of methods on top of RSpec for making your integration tests readable. This isn’t much more than “Given/When/Then”.

  • A configuration and mapping layer for different integration testing code, such as what’s provided by ActionController’s integration.rb, or the Ruby client for Selenium.

  • Common functionality for supported integration testing solutions, such as the option to restart the Selenium browser between tests, or simply clear the cookies.

Advantages of having your integration tests written with Spectie:

  • It’s Ruby.

  • If you’re familiar with RSpec already, all the same functionality is available.

  • All new syntax beyond RSpec is kept to a minimum, and exists solely to facilitate developer-driven BDD.

  • Use familiar methods for code navigation and reuse.

Example

Rails

Feature "Compelling Feature" do
  Scenario "As a user, I would like to use a compelling feature" do
    Given :i_have_an_account
    And   :i_have_logged_in

    When  :i_access_a_compelling_feature

    Then  :i_am_presented_with_stunning_results
  end

  def i_have_an_account
    @user = create_user
  end

  def i_have_logged_in
    log_in_as @user
  end

  def i_access_a_compelling_feature
    get compelling_feature_path
    response.should be_success
  end 

  def i_am_presented_with_stunning_results
    response.should have_text("Simply stunning!")
  end
end

Installation

Gem

sudo gem install spectie

Rails plugin

script/plugin install git://github.com/ryankinderman/spectie.git

Git

git clone git://github.com/ryankinderman/spectie.git

Configuration

Ruby on Rails

In spec/spec_helper.rb, after require 'spec/rails', add:

require 'spectie/rails'

That’s it. Spectie registers itself with RSpec, so you can run your integration tests with the usual rake spec:integration command. Also, all of the usual methods in a Rails integration testing session are available for you to use as well.

Selenium

In spec/spec_helper.rb, add:

require 'spectie/selenium'

The Selenium example group uses the Ruby client for Selenium Remote Control. Spectie encapsulates the communication with the Selenium driver to:

  • Target and connect to a remote machine

  • Start and stop the web browser

To this end, you can configure Selenium along with the rest of your RSpec configuration like so:

Spec::Runner.configure do |config|
  # Indicates whether Spectie should control the Selenium driver's starting
  # and stopping, cookie cleanup, etc.
  #
  # Set this to 'false' to manage this stuff outside of Spectie.
  config.selenium.controlled = true

  # Specify the connection options for the Selenium driver.
  # :host       the host name or IP address of the machine running the Selenium
  #             server
  # :port       the port of the Selenium server
  # :browser    the browser command to pass to Selenium server
  # :timeout_in_seconds   how long to wait before a wait_for_* method
  # :url        the URL that the machine running Selenium server should use to
  #             connect to the web app being tested
  config.selenium.driver_options = {
    :host => "10.211.55.127",
    :port => 4444,
    :browser => "*firefox",
    :timeout_in_seconds => 300,
    :url => "http://10.211.55.1:4567"
  }

  # Indicates whether Spectie should only start the browser once for the entire
  # test suite, and just clear out the cookies before each test, or whether it
  # should restart the browser between tests.
  config.selenium.start_browser_once = true

end

Author

Ryan Kinderman ([email protected])

Copyright © 2009 Ryan Kinderman. See LICENSE for details.

spectie's People

Contributors

ryankinderman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

robb-broome

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.