🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

ndp-ayudante

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndp-ayudante

bundlerRubygems
Version
0.6.2
Version published
Maintainers
1
Created
Source

h1. ayudante

  • http://github.com/ndp/ayudante

h2. DESCRIPTION:

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

h2. FEATURES/PROBLEMS:

h3. Fixture Helpers

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

h4. 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()

h4. 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()

h3. Pre and Post Condition Checks

h3. 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

h3. 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

h3. 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

h2. REQUIREMENTS:

  • none

h2. INSTALL:

  Rails::Initializer.run do |config|
    config.gem "ndp-ayudante", :source => "http://gems.github.com", :lib=>'ayudante'
  end

h2. TO COME

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

h2. LICENSE:

(The MIT License)

Copyright (c) 2009 Andrew J. Peterson, ndp@mac.com

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.

FAQs

Package last updated on 10 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts