Giter Club home page Giter Club logo

ayudante's Introduction

ayudante

DESCRIPTION:

Collection of useful helpers for writing unit/functional/integration testunit tests.

FEATURES/PROBLEMS:

Fixture Helpers

This uses method_missing to provide additional functions for each of your
fixtures:

assert_list_of_N

This asserts that the lists are the same size and have the same items. Any
difference is reported.

Example:

fixtures :candy_bars
assert_list_of_candy_bars [:almond_joys, :m_and_ms], CandyBar.find_nutty()

assert_set_of_N

This asserts that the lists are the same size and have the same items, but order
is ignored.

Example:

assert_set_of_candy_bars [:almond_joys, :m_and_ms], CandyBar.find_nutty()

assert_contains_N

This asserts that all the items are found in the second parameter, but order
is ignored.

Example:

assert_contains_candy_bars [:almond_joys, :m_and_ms], CandyBar.find_nutty()

Pre and Post Condition Checks

assert_changes

Write:

    assert_changes 'a' do
        a = 'world'
    end

instead of:
    assert a != 'world'
    a = 'world'
    assert_equal 'world', a

The string 'a' passed to assert changes is evaluated in the block context, both before and after the block is run. The first eval is call the pre-condition, and the second the post-condition.

Be explicit about a state change by specifying both the starting and ending values using an expression pointing to array of before and after values:

    o.answer = 'yes'
    assert_changes 'o.answer' => ['yes','no'] do
      o.answer = 'no'
    end

When given one value, it is considered the post-condition value.
The precondition is that the value does NOT equal it:

    i = true
    assert_changes 'i' => false do   # read as: i changes to false
      i = false
    end

Assert that several things change by passing an array:

    a,b = 'hello','hi'
    assert_changes ['a','b'] do
        a = 'world'
        b = 'earth'
    end

Or use a hash, and pass multiple pre/post conditions of arbitrary complexity:

      assert_changes 'post(:a).status' => [:preview, :published],
                            'comment(:c).status' => [:preview, :deleted] do
        ...
      end

assert_no_changes

assert_no_changes has an extended parameter possibilities:

    i,j = 'hello','hi'
    assert_no_changes 'i' do ...                # i (before) == i (after)
    assert_no_changes 'i'=>'hello' do ...       # i == 'hello' before and after
    assert_no_changes ['i','j'] do ...          # neither i nor j change
    assert_no_changes 'i'=>'hello','j'=>'hi' do # or be explicit with multiple

A Complex Example

Provide multiple assertions of arbitrary complexity, referencing fixtures, etc.
Note that assert_changes supports the :no_change symbol:

    assert_changes
        'inotech.services.public.include?(categories(:a))' => [true, :no_change],
            'inotech.services.public.include?(categories(:b))'=>false,
            'inotech.services.public.include?(categories(:c))'=>false do
      post :edit_services_dialog, :id=>inotech.id, :service_category_id=>categories(:a).id
    end

REQUIREMENTS:

  • none

INSTALL:

  • Installing the gem:
    sudo gem install ndp-ayudante --source=http://gems.github.com
  • or in environment.rb
      Rails::Initializer.run do |config|
        config.gem "ndp-ayudante", :source => "http://gems.github.com", :lib=>'ayudante'
      end

TO COME

  • Better error messages on fixture helpers
  • Add assert_includes_N fixture helper
  • Add assert_excludes_N fixture helper

LICENSE:

(The MIT License)

Copyright © 2009 Andrew J. Peterson, [email protected]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
‘Software’), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ayudante's People

Contributors

ndp avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

ericzou

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.