Git Product home page Git Product logo

shoulda-context's Introduction

shoulda-context

Official Documentation

Shoulda’s contexts make it easy to write understandable and maintainable tests for Test::Unit. It’s fully compatible with your existing tests in Test::Unit, and requires no retooling to use.

Refer to the shoulda gem if you want to know more about using shoulda with Rails or RSpec.

Contexts

Instead of writing Ruby methods with lots_of_underscores, shoulda-context adds context, setup, and should blocks…

class CalculatorTest < Test::Unit::TestCase
  context "a calculator" do
    setup do
      @calculator = Calculator.new
    end

    should "add two numbers for the sum" do
      assert_equal 4, @calculator.sum(2, 2)
    end

    should "multiply two numbers for the product" do
      assert_equal 10, @calculator.product(2, 5)
    end
  end
end

… which combine to produce the following test methods:

"test: A User instance should return its full name."
"test: A User instance with a profile should return true when sent #has_profile?."

Assertions

It also has two additional Test::Unit assertions for working with Ruby’s Array:

assert_same_elements([:a, :b, :c], [:c, :a, :b])
assert_contains(['a', '1'], /\d/)
assert_contains(['a', '1'], 'a')

Credits

Shoulda is maintained and funded by thoughtbot. Thank you to all the contributors.

License

Shoulda is Copyright © 2006-2010 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

shoulda-context's People

Contributors

augustl avatar bcardarella avatar bjhess avatar boone avatar cristibalan avatar drmark avatar gfairbrother avatar infused avatar jferris avatar joshuaclayton avatar kron4eg avatar lawrencepit avatar lazyatom avatar lmarburger avatar metaskills avatar mike-burns avatar mjankowski avatar packetmonkey avatar pragdave avatar qrush avatar rmm5t avatar showaltb avatar snowblink avatar stevenbristol avatar technicalpickles avatar terceiro avatar thechrisoshow avatar tomlea avatar webmat avatar zenspider avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.