{"id":13878241,"url":"https://github.com/thoughtbot/shoulda-context","last_synced_at":"2025-05-15T08:08:51.510Z","repository":{"id":48194820,"uuid":"1169910","full_name":"thoughtbot/shoulda-context","owner":"thoughtbot","description":"Shoulda Context makes it easy to write understandable and maintainable tests under Minitest and Test::Unit within Rails projects or plain Ruby projects.","archived":false,"fork":false,"pushed_at":"2024-08-30T13:35:09.000Z","size":1579,"stargazers_count":237,"open_issues_count":8,"forks_count":57,"subscribers_count":34,"default_branch":"main","last_synced_at":"2025-04-10T08:46:37.389Z","etag":null,"topics":["ruby","testing"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thoughtbot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-12-15T01:37:39.000Z","updated_at":"2025-01-26T11:21:26.000Z","dependencies_parsed_at":"2023-02-15T09:16:43.667Z","dependency_job_id":"9884c7b9-1025-4ef5-b571-b49984ca8bfe","html_url":"https://github.com/thoughtbot/shoulda-context","commit_stats":{"total_commits":650,"total_committers":71,"mean_commits":9.154929577464788,"dds":0.7953846153846154,"last_synced_commit":"0551d18c92eebd94db70917d668202508b7d2268"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fshoulda-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fshoulda-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fshoulda-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fshoulda-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoughtbot","download_url":"https://codeload.github.com/thoughtbot/shoulda-context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248613881,"owners_count":21133614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","testing"],"created_at":"2024-08-06T08:01:43.703Z","updated_at":"2025-04-14T18:12:49.836Z","avatar_url":"https://github.com/thoughtbot.png","language":"Ruby","readme":"# Shoulda Context [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] ![Downloads][downloads-badge] [![Hound][hound-badge]][hound]\n\n[version-badge]: https://img.shields.io/gem/v/shoulda-context.svg\n[rubygems]: https://rubygems.org/gems/shoulda-context\n[travis-badge]: https://img.shields.io/travis/thoughtbot/shoulda-context/master.svg\n[travis]: https://travis-ci.org/thoughtbot/shoulda-context\n[downloads-badge]: https://img.shields.io/gem/dtv/shoulda-context.svg\n[hound-badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg\n[hound]: https://houndci.com\n\nShoulda Context makes it easy to write understandable and maintainable tests\nunder Minitest and Test::Unit within Rails projects or plain Ruby projects. It's\nfully compatible with your existing tests and requires no retooling to use.\n\n## Quick links\n\n📖 **[Read the documentation for the latest version.][rubydocs]**\n📢 **[See what's changed in recent versions.][changelog]**\n\n[rubydocs]: http://rubydoc.info/github/thoughtbot/shoulda-context/master/frames\n[changelog]: CHANGELOG.md\n\n[shoulda-context]: https://github.com/thoughtbot/shoulda-context\n\n## Getting started\n\nIf you're working on a Rails app, then make sure to add this gem to the `test`\ngroup in your Gemfile:\n\n``` ruby\ngroup :test do\n  gem 'shoulda-context', '~\u003e 3.0.0.rc1'\nend\n```\n\nIf you're not working on a Rails app, then you can simply add:\n\n``` ruby\ngem 'shoulda-context', '~\u003e 3.0.0.rc1'\n```\n\nThen run `bundle install`.\n\n## Overview\n\nInstead of writing Ruby methods with `lots_of_underscores`, Shoulda Context lets\nyou name your tests and group them together using English.\n\nAt a minimum, the gem provides some convenience layers around core Minitest /\nTest::Unit functionality. For instance, this test case:\n\n```ruby\nclass CalculatorTest \u003c Minitest::Test\n  context \"a calculator\" do\n    setup do\n      @calculator = Calculator.new\n    end\n\n    should \"add two numbers for the sum\" do\n      assert_equal 4, @calculator.sum(2, 2)\n    end\n\n    should \"multiply two numbers for the product\" do\n      assert_equal 10, @calculator.product(2, 5)\n    end\n  end\nend\n```\n\nturns into:\n\n```ruby\nclass CalculatorTest \u003c Minitest::Test\n  def setup\n    @calculator = Calculator.new\n  end\n\n  define_method \"test_: a calculator should add two numbers for the sum\" do\n    assert_equal 4, @calculator.sum(2, 2)\n  end\n\n  define_method \"test_: a calculator should multiply two numbers for the product\" do\n    assert_equal 10, @calculator.product(2, 5)\n  end\nend\n```\n\nHowever, Shoulda Context also provides functionality apart from Minitest /\nTest::Unit that allows you to shorten tests drastically by making use of\nRSpec-compatible matchers. For instance, with [Shoulda\nMatchers][shoulda-matchers] you can write such tests as:\n\n```ruby\nclass User \u003c ActiveSupport::TestCase\n  context \"validations\" do\n    subject { FactoryBot.build(:user) }\n\n    should validate_presence_of(:first_name)\n    should validate_presence_of(:last_name)\n    should validate_uniqueness_of(:email)\n    should_not allow_value('weird').for(:email)\n  end\nend\n```\n\n[shoulda-matchers]: https://github.com/thoughtbot/shoulda-matchers\n\n## API\n\n### DSL\n\nThe primary method in Shoulda Context's API is `context`, which declares a group\nof a tests.\n\nThese methods are available inside of a `context`:\n\n* `setup` — a DSL-y alternative to defining a `setup` method\n* `teardown` — a DSL-y alternative to defining a `teardown` method\n* `should` — There are two forms:\n  1. when passed a name + block, creates a test equivalent to defining a\n  `test_` method\n  2. when passed a matcher, creates a test that will run the matcher, asserting\n  that it passes\n* `should_not` — like the matcher version of `should`, but creates a test that\n  asserts that the matcher fails\n* `should_eventually` — allows you to temporarily skip tests\n* `context` — creates a subcontext\n\nThese methods are available within a test case class, but outside of a\n`context`:\n\n* `should` — same as above\n* `should_not` — same as above\n* `should_eventually` — same as above\n* `described_type` — returns the class being tested, as determined by the class\n  name of the outermost class\n* `subject` — lets you define an object that is the primary focus of the tests\n  within a context; this is most useful when using a matcher as the matcher will\n  make use of this as _its_ subject\n\nAnd these methods are available inside of a test (whether defined via a method\nor via `should`):\n\n* `subject` — an instance of the class under test, which is derived\n  automatically from the name of the test case class but is overridable via the\n  class method version of `subject` above\n\n### Assertions\n\nIn addition to the main API, the gem also provides some extra assertions that\nmay be of use:\n\n* `assert_same_elements` — compares two arrays for equality, but ignoring\n  ordering\n* `assert_contains` — asserts that an array has an item\n* `assert_does_not_contain` — the opposite of `assert_contains`\n* `assert_accepts` — what `should` uses internally; asserts that a matcher\n  object matches against a value\n* `assert_reject` — what `should_not` uses internally; asserts that a matcher\n  object does not match against a value\n\n## Compatibility\n\nShoulda Context is [tested][travis] and supported against Ruby 2.7+, Rails 6.0+,\nMinitest 4.x, and Test::Unit 3.x.\n\n## Versioning\n\nShoulda Context follows Semantic Versioning 2.0 as defined at\n\u003chttp://semver.org\u003e.\n\n## Team\n\nShoulda Context is currently maintained by [Pedro Paiva][VSPPedro]. Previous\nmaintainers include [Elliot Winkler][mcmire], [Travis Jeffery][travisjeffery],\n[Gabe Berke-Williams][gabebw], [Ryan McGeary][rmm5t], [Joe Ferris][jferris], [Dan\nCroaky][croaky], and [Tammer Saleh][tammersaleh].\n\n[VSPPedro]: https://github.com/VSPPedro\n[mcmire]: https://github.com/mcmire\n[travisjeffery]: https://github.com/travisjeffery\n[gabebw]: https://github.com/gabebw\n[rmm5t]: https://github.com/rmm5t\n[jferris]: https://github.com/jferris\n[croaky]: https://github.com/croaky\n[tammersaleh]: https://github.com/tammersaleh\n\n## Copyright/License\n\nShoulda Context is copyright © Tammer Saleh and [thoughtbot,\ninc][thoughtbot-website]. It is free and opensource software and may be\nredistributed under the terms specified in the [LICENSE](LICENSE) file.\n\n[thoughtbot-website]: https://thoughtbot.com?utm_source=github\n\n\u003c!-- START /templates/footer.md --\u003e\n## About thoughtbot\n\n![thoughtbot](https://thoughtbot.com/thoughtbot-logo-for-readmes.svg)\n\nThis repo is maintained and funded by thoughtbot, inc.\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nWe love open source software!\nSee [our other projects][community].\nWe are [available for hire][hire].\n\n[community]: https://thoughtbot.com/community?utm_source=github\n[hire]: https://thoughtbot.com/hire-us?utm_source=github\n\n\n\u003c!-- END /templates/footer.md --\u003e\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fshoulda-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtbot%2Fshoulda-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fshoulda-context/lists"}