{"id":17269255,"url":"https://github.com/djanowski/cutest","last_synced_at":"2025-04-05T09:08:39.700Z","repository":{"id":62556590,"uuid":"801180","full_name":"djanowski/cutest","owner":"djanowski","description":"Isolated tests in Ruby.","archived":false,"fork":false,"pushed_at":"2017-06-17T13:31:58.000Z","size":102,"stargazers_count":153,"open_issues_count":8,"forks_count":24,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T08:08:26.806Z","etag":null,"topics":[],"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/djanowski.png","metadata":{"files":{"readme":"README.markdown","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}},"created_at":"2010-07-27T18:07:25.000Z","updated_at":"2024-10-31T08:42:34.000Z","dependencies_parsed_at":"2022-11-03T06:00:43.027Z","dependency_job_id":null,"html_url":"https://github.com/djanowski/cutest","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djanowski%2Fcutest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djanowski%2Fcutest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djanowski%2Fcutest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djanowski%2Fcutest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djanowski","download_url":"https://codeload.github.com/djanowski/cutest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312081,"owners_count":20918344,"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":[],"created_at":"2024-10-15T08:15:46.145Z","updated_at":"2025-04-05T09:08:39.651Z","avatar_url":"https://github.com/djanowski.png","language":"Ruby","readme":"Cutest\n=======\n\n[![Gem Version](https://badge.fury.io/rb/cutest.svg)](https://badge.fury.io/rb/cutest)\n\nForking tests.\n\nDescription\n-----------\n\nEach test file is run in a forked process to avoid shared state. Once a failure\nis found, you get a report detailing what failed and how to locate the error\nand the rest of the file is skipped.\n\nYou can use the `scope` command around tests: it guarantees that no instance\nvariables are shared between tests.\n\nThere are two commands very similar in nature, but with a subtle difference that\nmakes them easy to combine in order to satisfy different needs: `prepare` and\n`setup`.\n\nThe `prepare` blocks are executed before each test. If you call `prepare` many\ntimes, each passed block is appended to an array. When the test is run, all\nthose prepare blocks are executed in order. The result of the block is\ndiscarded, so it is only useful for preparing the environment (flushing the\ndatabase, removing a directory, etc.).\n\nThe `setup` block is executed before each test and the result is passed as a\nparameter to the `test` block. Unlike `prepare`, each definition of `setup`\noverrides the previous one. Even if you can declare instance variables and\nshare them between tests, the recommended usage is to pass the result of the\nblock as a parameter to the `test` blocks.\n\nThe `test` method executes the passed block after running `prepare` and\n`setup`. This is where assertions must be declared.\n\nThree assertions are available: `assert`, that accepts a value and raises\nif it's false or nil; `assert_equal`, that raises if its arguments are not\nequal; and `assert_raise`, that executes a passed block and compares the raised\nexception to the expected one. In all cases, if the expectation is no met, an\n`AssertionFailed` exception is raised.\n\nYou can customize the output of `assert` by providing a second argument with\na string you want to get as an error report if the assertion is not fulfilled.\nThis can also be used as a simple building block to build custom assertions.\n\nUsage\n-----\n\nIn your terminal:\n\n    $ cutest test/*.rb\n\nIn your tests:\n\n````ruby\nsetup do\n  {:a =\u003e 23, :b =\u003e 43}\nend\n\ntest \"should receive the result of the setup block as a parameter\" do |params|\n  assert params == {:a =\u003e 23, :b =\u003e 43}\nend\n\ntest \"should evaluate the setup block before each test\" do |params|\n  params[:a] = nil\nend\n\ntest \"should preserve the original values from the setup\" do |params|\n  assert 23 == params[:a]\nend\n````\n\nAn example working with a prepare block:\n````ruby\nprepare do\n  Ohm.flush\nend\n\nsetup do\n  Ohm.redis.get(\"foo\")\nend\n\ntest do |foo|\n  assert foo.nil?\nend\n````\n\nAnd working with scopes:\n````ruby\nsetup do\n  @foo = true\nend\n\n@bar = true\n\nscope do\n  test \"should not share instance variables\" do |foo|\n    assert !defined?(@foo)\n    assert !defined?(@bar)\n    assert foo == true\n  end\nend\n````\n\nThe tests in these two examples will pass.\n\nUnlike other testing frameworks, Cutest does not compile all the tests before\nrunning them.\n\nA simple example for adding a custom `empty` assertion:\n````ruby\ndef assert_empty(string)\n  assert(string.empty?, \"not empty\")\nend\n\ntest \"failed custom assertion\" do\n  assert_empty \"foo\"\nend\n````\n\nHandling errors\n---------------\n\nIf you get an error when running the tests, this is what you will see:\n````bash\nException: assert_equal 24, params[:a] # 24 != 23\ntest/setup.rb +14\n````\nRunning the build\n-----------------\n\nUsing Rake:\n````ruby\ntask :test do\n  exec \"cutest test/*.rb\"\nend\n\ntask :default =\u003e :test\n````\n\nUsing Make:\n````yml\n.PHONY: test\n\ntest:\n  cutest test/*.rb\n````\nCommand-line interface\n----------------------\n\nThe tool `cutest` accepts a list of files and sends them to `Cutest.run`. If\nyou need to require a file or library before running the tests, as is the case\nwith test helpers, use the `-r` flag:\n\n    $ cutest -r ./test/helper.rb ./test/*_test.rb\n\nIf you want to check which version you are running, try the `-v` flag.\n\nInstallation\n------------\n\n    $ gem install cutest\n\nLicense\n-------\n\nCopyright (c) 2010 Damian Janowski and Michel Martens\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["Testing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjanowski%2Fcutest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjanowski%2Fcutest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjanowski%2Fcutest/lists"}