diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fb20f2..077dfec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.0] - [2020-02-17] + +### Added + +- Stubbing and seeding from the same source file via the `call_fixture` method (nepalez) + +```yaml +# ./changes.yml +--- +- type: user + params: + id: 1 + +- const: DEFAULT_USER_ID + value: 1 + +- url: https://example.com/users/default + method: get + responses: + - body: + id: 1 + name: Andrew +``` + +```ruby +before { call_fixture "#{__dir__}/changes.yml" } +``` + ## [0.1.0] - [2020-02-09] ### Added @@ -200,3 +228,4 @@ This is a first public release with features extracted from production app. [0.0.6]: https://github.com/nepalez/fixturama/compare/v0.0.5...v0.0.6 [0.0.7]: https://github.com/nepalez/fixturama/compare/v0.0.6...v0.0.7 [0.1.0]: https://github.com/nepalez/fixturama/compare/v0.0.7...v0.1.0 +[0.2.0]: https://github.com/nepalez/fixturama/compare/v0.1.0...v0.2.0 diff --git a/README.md b/README.md index 801e74d..e1c8022 100644 --- a/README.md +++ b/README.md @@ -124,16 +124,17 @@ Use the `count: 2` key to create more objects at once. ### Stubbing -Another opinionated format we use for stubs (`stub_fixture`). The gem supports stubbing both message chains and constants. +The gem supports stubbing message chains, constants and http requests with the following keys. For message chains: - `class` for stubbed class - `chain` for messages chain - `arguments` (optional) for specific arguments -- `actions` for an array of actions for consecutive invocations of the chain - -Every action either `return` some value, or `raise` some exception +- `actions` for an array of actions for consecutive invocations of the chain with keys + - `return` for a value to be returned + - `raise` for an exception to be risen + - `repeate` for a number of invocations with this action For constants: @@ -152,6 +153,7 @@ For http requests: - `status` - `body` - `headers` + - `repeate` for the number of times this response should be returned before switching to the next one ```yaml # ./stubs.yml @@ -179,6 +181,7 @@ For http requests: - <%= profile_id %> actions: - return: true + repeate: 1 # this is the default value - raise: ActiveRecord::RecordNotFound - const: NOTIFIER_TIMEOUT_SEC @@ -192,6 +195,7 @@ For http requests: password: bar responses: - status: 200 # for the first call + repeate: 1 # this is the default value, but you can set another one - status: 404 # for any other call - uri: htpps://example.com/foo # exact string! @@ -231,6 +235,30 @@ I find it especially helpful when I need to check different edge cases. Instead Looking at the spec I can easily figure out the "structure" of expectation, while looking at fixtures I can check the concrete corner cases. +## Single Source of Changes + +If you will, you can list all stubs and seeds at the one single file like + +```yaml +# ./changes.yml +--- +- type: user + params: + id: 1 + name: Andrew + +- const: DEFAULT_USER_ID + value: 1 +``` + +This fixture can be applied via `call_fixture` method just like we did above with `seed_fixture` and `stub_fixture`: + +```ruby +before { call_fixture "#{__dir__}/changes.yml" } +``` + +In fact, since the `v0.2.0` all those methods are just the aliases of the `call_fixture`. + ## License The gem is available as open source under the terms of the [MIT License][license]. diff --git a/fixturama.gemspec b/fixturama.gemspec index 6b50727..d1eb24d 100644 --- a/fixturama.gemspec +++ b/fixturama.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "fixturama" - gem.version = "0.1.0" + gem.version = "0.2.0" gem.author = "Andrew Kozin (nepalez)" gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/nepalez/fixturama"