spectie
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:Developer-driven BDD-style integration testing in Ruby with RSpec!
= 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}[http://api.rubyonrails.org/classes/ActionController/Integration/Session.html] 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 (ryan@kinderman.net)

== Copyright

Copyright (c) 2009 Ryan Kinderman. See LICENSE for details.

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。