Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assert_difference

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert_difference

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

assert_difference

Build Status Coverage Status Code Climate Test Coverage Inline docs Gem Version Dependency Status

A nice assert_difference method similar to the one provided by Rails but with some improvements. For example:

assert_difference "Company.count" => +1, "User.count" => +5, "Slot.count" => -1 do
  post :something
end

will assert that a company and 5 users were create (the plus sign is only for the visual aid) and a slot was removed.

Rails' assert_difference would require a more verbose syntax:

assert_difference "Company.count" do
  assert_difference "User.count", +5 do
    assert_difference "Article.count", -1 do
      post :something
    end
  end
end

Expectations can also be ranges, for example:

assert_difference "Blog.count" => +1, "Post.count" => 2..5 do # Generate some sample posts when creating a blog
  post :create
end

On top of that, error reporting is improved by displaying all the counters that didn't match.

To use it with Test::Unit add this code:

class Test::Unit::TestCase
  include AssertDifference
end

or in Rails:

class ActiveSupport::TestCase
  # ...
  include AssertDifference
end

and to use it with RSpec:

RSpec.configure do |config|
  config.include AssertDifference
end

This gem should work without Rails but it does depend on active support >= 3.0.0 and it's tested with active support 3.0, 3.1, 3.2, 4.0 and 4.1 as well as Ruby 1.9.3, 2.0 and 2.1.

Users

This gem is being used by:

  • Watu
  • You? please, let us know if you are using this gem.

Changelog

Next version

  • Modernization of the gem.
  • Test with 100% code coverage.
  • Started using Travis-CI for continuous testing.
  • Started testing in various versions of active support and ruby.
  • Improved documentation.

Version 0.5.0 (Aug 6, 2012)

  • Expectations can be ranges.

Version 0.4.2 (Aug 6, 2012)

  • Fixed important typo.

Version 0.4.1 (Aug 6, 2012)

  • Better error reporting (all unmatching counters).

Version 0.4.0 (Feb 21, 2012)

  • Fix crash on missing gems.
  • Return what the blocks returns.

Version 0.3.1 (Aug 25, 2011)

  • Fixed documentation.

Version 0.3.0 (Aug 24, 2011)

  • Better organization of code with modules.
  • Switched to bundler from jeweler.
  • Removed unneeded dependencies.
  • Cleaned up documentation.

Version 0.1.0 (Oct 2, 2010)

  • Initial release. Code extracted from a personal project.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Add some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright (c) 2010, 2011, 2012, 2014 José Pablo Fernández. See LICENSE for details.

FAQs

Package last updated on 14 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc