Latest 0.1.0
Homepage https://github.com/threeplay/RxBehaviorTester
License MIT
Platforms ios 11.0
Dependencies RxSwift, RxBlocking
Authors

CI Status
Version
License
Platform
Maintainability
codecov

Rx Behavior Testing by stream pattern matching and assertions

Testing an observable

struct State {
  var isLoading: Bool
  var isSaveEnabled: Bool
  var name: String
}

let observable: Observable<State> = ...

let decision = testBehavior(of: observable) { dsl in 
  dsl.match { $0.isLoading == false }
  dsl.assert(.always) { $0.isLoading == false }
  dsl.match { $0.name == "Updated Name" }
  dsl.match { $0.isSaveEnabled == true }
  dsl.run(.async) { triggerSaving() }
  dsl.match { $0.isSaveEnabled == false }
}

// Decision will be
//  .correct: If no assertions failed and all match clauses matched
//  .failed: If any assetions failed or observable completes or times out without matching

Matchers

Predicate matcher

  dsl.match { state in 
    predicate  
  }

Always assertion

  dsl.assert(.always) { state in
    assertion
  }

Assertion is checked from the point of definition until the test completes

Bounded assertion

  dsl.assert(.untilNextMatch) { state in
    assertion
  }

Only evaluates the assertion until the next matcher after that the assertion is not checked

Unordered scope

  dsl.unordered {
    dsl...  // matchers/assertions or other scopes
  }

Completes when all of the matchers return a result in any order

First scope

  dsl.first {
    dsl... // matchers/assertions or other scopes
  }

Completes when any of the matchers or assertions returns a result (.correct or .failed)

Requirements

  • Swift 4.2
  • RxSwift 4

Installation

RxBehaviorTester is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'RxBehaviorTester'

Author

Eliran Ben-Ezra, [email protected]

License

RxBehaviorTester is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "RxBehaviorTester",
    "version": "0.1.0",
    "summary": "Rx chains behavior testing",
    "description": "RxBehavior Tester helps with testing Rx chains that have complex behavior byncreating matchers that describe the expected behavior of chain",
    "homepage": "https://github.com/threeplay/RxBehaviorTester",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Eliran Ben-Ezra": "[email protected]"
    },
    "source": {
        "git": "https://github.com/threeplay/RxBehaviorTester.git",
        "tag": "0.1.0"
    },
    "swift_version": "4.2",
    "platforms": {
        "ios": "11.0"
    },
    "dependencies": {
        "RxSwift": [
            "~> 4.0"
        ],
        "RxBlocking": [
            "~> 4.0"
        ]
    },
    "source_files": "RxBehaviorTester/Classes/**/*"
}

Pin It on Pinterest

Share This