{"id":18832024,"url":"https://github.com/hamcrest/ochamcrest","last_synced_at":"2025-05-15T20:01:06.452Z","repository":{"id":1242330,"uuid":"1180662","full_name":"hamcrest/OCHamcrest","owner":"hamcrest","description":"Hamcrest for Objective-C: Powerful, combinable, extensible matchers for verification","archived":false,"fork":false,"pushed_at":"2025-03-21T04:43:11.000Z","size":10616,"stargazers_count":715,"open_issues_count":0,"forks_count":101,"subscribers_count":31,"default_branch":"main","last_synced_at":"2025-05-08T12:41:58.555Z","etag":null,"topics":["hamcrest","objective-c","testing","xctest"],"latest_commit_sha":null,"homepage":"http://hamcrest.org","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hamcrest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2010-12-18T22:29:39.000Z","updated_at":"2025-03-21T04:43:14.000Z","dependencies_parsed_at":"2023-07-05T21:32:47.949Z","dependency_job_id":"787625cc-4efb-49b4-993c-cc14a3c4b597","html_url":"https://github.com/hamcrest/OCHamcrest","commit_stats":{"total_commits":1200,"total_committers":27,"mean_commits":44.44444444444444,"dds":0.4675,"last_synced_commit":"87f204a87391f9d04d7ceaef792ec994122addc1"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2FOCHamcrest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2FOCHamcrest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2FOCHamcrest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2FOCHamcrest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hamcrest","download_url":"https://codeload.github.com/hamcrest/OCHamcrest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414457,"owners_count":22067263,"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":["hamcrest","objective-c","testing","xctest"],"created_at":"2024-11-08T01:56:35.158Z","updated_at":"2025-05-15T20:01:05.540Z","avatar_url":"https://github.com/hamcrest.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![ochamcrest](http://hamcrest.org/images/logo.jpg)\n\n# OCHamcrest\n\n[![Build Status](https://github.com/hamcrest/OCHamcrest/actions/workflows/build.yml/badge.svg)](https://github.com/hamcrest/OCHamcrest/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/hamcrest/OCHamcrest/badge.svg)](https://coveralls.io/r/hamcrest/OCHamcrest)\n[![Swift Package Index Platform Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fhamcrest%2FOCHamcrest%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/hamcrest/OCHamcrest)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods Version](https://img.shields.io/cocoapods/v/OCHamcrest.svg?style=flat)](https://cocoapods.org/pods/OCHamcrest)\n[![Mastodon Follow](https://img.shields.io/mastodon/follow/109765011064804734?domain=https%3A%2F%2Fiosdev.space\n)](https://iosdev.space/@qcoding)\n\nOCHamcrest is an Objective-C module providing:\n\n* a library of \"matcher\" objects for declaring rules to check whether a given object matches those\n  rules.\n* a framework for writing your own matchers.\n\nMatchers can be combined to create flexible expressions of intent in tests.\nThey can also be used for other purposes, such as user input validation.\n\n\u003c!-- toc --\u003e\n## Contents\n\n  * [My First OCHamcrest Test](#my-first-ochamcrest-test)\n  * [Predefined Matchers](#predefined-matchers)\n    * [Object](#object)\n    * [Number](#number)\n    * [Text](#text)\n    * [Logical](#logical)\n    * [Collection](#collection)\n    * [Decorator](#decorator)\n    * [Syntactic Sugar](#syntactic-sugar)\n  * [Common Questions](#common-questions)\n    * [How Can I Assert on an Asynchronous Call?](#how-can-i-assert-on-an-asynchronous-call)\n    * [Can I Add Custom Matchers?](#can-i-add-custom-matchers)\n    * [What About Swift?](#what-about-swift)\n  * [How Do I Add OCHamcrest to My Project?](#how-do-i-add-ochamcrest-to-my-project)\n    * [Swift Package Manager](#swift-package-manager)\n    * [CocoaPods](#cocoapods)\n    * [Carthage](#carthage)\n    * [Prebuilt Framework](#prebuilt-framework)\n    * [Build Your Own](#build-your-own)\n  * [Author](#author)\u003c!-- endToc --\u003e\n\n\n## My First OCHamcrest Test\n\nWe'll start by writing a very simple Xcode unit test, but instead of using XCTest's\n`XCTAssertEqualObjects` function, we'll use OCHamcrest's `assertThat` construct and a predefined\nmatcher:\n\n```obj-c\n@import OCHamcrest;\n@import XCTest;\n\n@interface BiscuitTest : XCTestCase\n@end\n\n@implementation BiscuitTest\n\n- (void)testEquals\n{\n    Biscuit* theBiscuit = [[Biscuit alloc] initWithName:@\"Ginger\"];\n    Biscuit* myBiscuit = [[Biscuit alloc] initWithName:@\"Ginger\"];\n    assertThat(theBiscuit, equalTo(myBiscuit));\n}\n\n@end\n```\n\nThe `assertThat` function is a stylized sentence for making a test assertion. In this example, the\nsubject of the assertion is the object `theBiscuit`, which is the first method parameter. The second\nmethod parameter is a matcher for `Biscuit` objects, here a matcher that checks one object is equal\nto another using the `-isEqual:` method. The test passes since the `Biscuit` class defines an\n`-isEqual:` method.\n\nOCHamcrest's functions are actually declared with an \"HC_\" package prefix (such as `HC_assertThat`\nand `HC_equalTo`) to avoid name clashes. To make test writing faster and test code more legible,\noptional short syntax is provided by default. For example, instead of writing `HC_assertThat`,\nsimply write `assertThat`.\n\n\n## Predefined Matchers\n\nOCHamcrest comes with a library of useful matchers:\n\n### Object\n\n  * `conformsTo` - match object that conforms to protocol\n  * `equalTo` - match equal object\n  * `hasDescription` - match object's `-description`\n  * `hasProperty` - match return value of method with given name\n  * `instanceOf` - match object type\n  * `isA` - match object type precisely, no subclasses\n  * `nilValue`, `notNilValue` - match `nil`, or not `nil`\n  * `sameInstance` - match same object\n  * `throwsException` - match block that throws an exception\n  * HCArgumentCaptor - match anything, capturing all values\n\n### Number\n\n  * `closeTo` - match number close to a given value\n  * `greaterThan`, `greaterThanOrEqualTo`, `lessThan`,\n  `lessThanOrEqualTo` - match numeric ordering\n  * `isFalse` - match zero\n  * `isTrue` - match non-zero\n\n### Text\n\n  * `containsSubstring` - match part of a string\n  * `endsWith` - match the end of a string\n  * `equalToIgnoringCase` - match the complete string but ignore case\n  * `equalToIgnoringWhitespace` - match the complete string but ignore extra\n  whitespace\n  * `startsWith` - match the beginning of a string\n  * `stringContainsInOrder`, `stringContainsInOrderIn` - match parts of a string, in relative order\n\n### Logical\n\n  * `allOf`, `allOfIn` - \"and\" together all matchers\n  * `anyOf`, `anyOfIn` - \"or\" together all matchers\n  * `anything` - match anything (useful in composite matchers when you don't\n  care about a particular value)\n  * `isNot` - negate the matcher\n\n### Collection\n\n  * `contains`, `containsIn` - exactly match the entire collection\n  * `containsInAnyOrder`, `containsInAnyOrderIn` - match the entire collection, but in any order\n  * `containsInRelativeOrder`, `containsInRelativeOrderIn` - match collection containing items in relative order\n  * `everyItem` - match if every item in a collection satisfies a given matcher\n  * `hasCount` - match number of elements against another matcher\n  * `hasCountOf` - match collection with given number of elements\n  * `hasEntries` - match dictionary with key-value pairs in a dictionary\n  * `hasEntriesIn` - match dictionary with key-value pairs in a list\n  * `hasEntry` - match dictionary containing a key-value pair\n  * `hasItem` - match if given item appears in the collection\n  * `hasItems`, `hasItemsIn` - match if all given items appear in the collection, in any order\n  * `hasKey` - match dictionary with a key\n  * `hasValue` - match dictionary with a value\n  * `isEmpty` - match empty collection\n  * `isIn` - match when object is in given collection\n  * `onlyContains`, `onlyContainsIn` - match if collection's items appear in given list\n\n### Decorator\n\n  * `describedAs` - give the matcher a custom failure description\n  * `is` - decorator to improve readability - see \"Syntactic sugar\" below\n\nThe arguments for many of these matchers accept not just a matching value, but\nanother matcher, so matchers can be composed for greater flexibility. For\nexample, `only_contains(endsWith(@\".\"))` will match any collection where every\nitem is a string ending with period.\n\n### Syntactic Sugar\n\nOCHamcrest strives to make your tests as readable as possible. For example, the `is` matcher is a\nwrapper that doesn't add any extra behavior to the underlying matcher. The following assertions are\nall equivalent:\n\n```obj-c\nassertThat(theBiscuit, equalTo(myBiscuit));\nassertThat(theBiscuit, is(equalTo(myBiscuit)));\nassertThat(theBiscuit, is(myBiscuit));\n```\n\nThe last form is allowed since `is` wraps non-matcher arguments with `equalTo`. Other matchers that\ntake matchers as arguments provide similar shortcuts, wrapping non-matcher arguments in `equalTo`.\n\n\n## Common Questions\n\n### How Can I Assert on an Asynchronous Call?\n\n`assertWithTimeout` will keep evaluating an expression until the matcher is satisfied or a timeout\nis reached. For example,\n\n```obj-c\nassertWithTimeout(5, thatEventually(self.someString), is(@\"expected\"));\n```\n\nThis repeatedly checks for this string to evaluate to \"expected\" before timing out after 5 seconds.\n`thatEventually` is a convenience macro to create a block.\n\n### Can I Add Custom Matchers?\n\nOCHamcrest comes bundled with lots of useful matchers, but you'll probably find that you need to\ncreate your own from time to time to fit your testing needs. See the\n[\"Writing Custom Matchers\" guide for more information](https://github.com/hamcrest/OCHamcrest/wiki/Writing-Custom-Matchers).\n\n### What About Swift?\n\nTry the [native Swift implementation of Hamcrest](https://github.com/nschum/SwiftHamcrest).\n\n\n## How Do I Add OCHamcrest to My Project?\n\nThe [Examples](https://github.com/hamcrest/OCHamcrest/tree/main/Examples) folder shows projects\nready to use OCHamcrest via Swift Package Manager, CocoaPods, or through the prebuilt framework.\n\n### Swift Package Manager\n\nInclude an OCHamcrest package in your Package.swift manifest's array of `dependencies`:\n\n\u003c!-- snippet: swiftpm-declare-dependencies --\u003e\n\u003ca id='snippet-swiftpm-declare-dependencies'\u003e\u003c/a\u003e\n```swift\ndependencies: [\n    .package(\n        url: \"https://github.com/hamcrest/OCHamcrest\",\n        .upToNextMajor(from: \"9.1.0\")\n    ),\n],\n```\n\u003csup\u003e\u003ca href='/Examples/MacExample-SwiftPackageManager/Package.swift#L13-L20' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-swiftpm-declare-dependencies' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\nThen add OCHamcrest to the dependencies of your `.testTarget`:\n\n\u003c!-- snippet: swiftpm-use-dependencies --\u003e\n\u003ca id='snippet-swiftpm-use-dependencies'\u003e\u003c/a\u003e\n```swift\n.testTarget(\n    name: \"ExampleTests\",\n    dependencies: [\n        \"Example\",\n        \"OCHamcrest\",\n    ]\n),\n```\n\u003csup\u003e\u003ca href='/Examples/MacExample-SwiftPackageManager/Package.swift#L27-L35' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-swiftpm-use-dependencies' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n### CocoaPods\n\nIf you want to add OCHamcrest using Cocoapods then add the following dependency to your Podfile.\nMost people will want OCHamcrest in their test targets, and not include any pods from their main\ntargets:\n\n```ruby\ntarget 'MyTests' do\n  inherit! :search_paths\n  use_frameworks!\n  pod 'OCHamcrest', '~\u003e 9.1'\nend\n```\n\n### Carthage\n\nAdd the following to your Cartfile:\n\n    github \"hamcrest/OCHamcrest\" ~\u003e 9.1\n\nThen drag the the built framework from the appropriate Carthage/Build directory into your project,\nbut with \"Copy items into destination group's folder\" disabled.\n\n### Prebuilt Framework\n\nA prebuilt binary is available on [GitHub](https://github.com/hamcrest/OCHamcrest/releases/). The\nbinary is packaged as OCHamcrest.xcframework, containing these architectures:\n  * macOS\n  * Mac Catalyst\n  * iOS device\n  * iOS simulator\n  * tvOS device\n  * tvOS simulator\n  * visionOS device\n  * visionOS simulator\n  * watchOS device\n  * watchOS simulator\n\nDrag the XCFramework into your project.\n\n### Build Your Own\n\nIf you want to build OCHamcrest yourself, clone the repo, then\n\n```sh\n$ cd Resources\n$ ./MakeDistribution.sh\n```\n\n## Author\n\nJon Reid is the author of _[iOS Unit Testing by Example](https://iosunittestingbyexample.com)._ His website is [Quality Coding](https://qualitycoding.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamcrest%2Fochamcrest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhamcrest%2Fochamcrest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamcrest%2Fochamcrest/lists"}