Skip to content

Commit

Permalink
Bump v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nepalez committed Apr 3, 2021
1 parent 725fd9e commit d9bc933
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ 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.5.0] - [2021-04-03]

### Added

- Support for <de>serialization PORO objects (nepalez)

```yaml
# target.yml
---
number: <%= object(be_positive) %>
```
```ruby
RSpec.describe "something" do
subject { { "number" => 42 } }

# no explicit params is needed here
let(:target) { load_fixture "target.yml" }

it { is_expected.to match(target) }
end
```

## [0.4.1] - [2021-03-31]

### Fixed
Expand Down Expand Up @@ -275,3 +298,4 @@ This is a first public release with features extracted from production app.
[0.3.0]: https://github.com/nepalez/fixturama/compare/v0.2.0...v0.3.0
[0.4.0]: https://github.com/nepalez/fixturama/compare/v0.3.0...v0.4.0
[0.4.1]: https://github.com/nepalez/fixturama/compare/v0.4.0...v0.4.1
[0.5.0]: https://github.com/nepalez/fixturama/compare/v0.4.1...v0.5.0
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,38 @@ This feature can also be useful to produce a "partially defined" fixtures with [
subject { load_fixture "#{__dir__}/data.yml", user: kind_of(ActiveRecord::Base) }
```

Since the v0.5.0 we support another way to serialize PORO objects in fixtures. Just wrap them to the `object()` method:

```yaml
---
:account: <%= object(user) %>
```

This time you don't need sending objects explicitly.

```ruby
RSpec.describe "example" do
subject { load_fixture "#{__dir__}/data.yml" }
let(:user) { FactoryBot.create(:user) }
# The same object will be returned
it { is_expected.to eq(account: user) }
end
```

Under the hood we use `Marshal.dump` and `Marshal.restore` to serialize and deserialize the object back.

**Notice**, that deserialization creates a new instance of the object which is not equivalent to the source (`user` in the example above)!
In most cases this is enough. For example, you can provide matchers like:

```yaml
---
number: <%= object(be_positive) %>
```

The loaded object would contain `{ "number" => be_positive }`.

### Seeding

The seed (`seed_fixture`) file should be a YAML/JSON with opinionated parameters, namely:
Expand Down
2 changes: 1 addition & 1 deletion lib/fixturama/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Fixturama
# The current version of the gem
VERSION = "0.4.1"
VERSION = "0.5.0"
end

0 comments on commit d9bc933

Please sign in to comment.