Add expanded description of the RSpec version_with_changes matcher to README

This commit is contained in:
Ben Atkins 2016-11-01 01:14:52 -04:00
parent 5a2e709e2e
commit b962040730
2 changed files with 25 additions and 6 deletions

View File

@ -1391,9 +1391,7 @@ describe Widget do
end
```
It is also possible to do assertions on the versions using `have_a_version_with`
and `have_a_version_with_changes` matchers. For more examples, see the
[Widget spec](https://github.com/airblade/paper_trail/blob/master/spec/models/widget_spec.rb)
It is also possible to do assertions on the versions using `have_a_version_with` matcher.
```ruby
describe '`have_a_version_with` matcher' do
@ -1403,13 +1401,33 @@ describe '`have_a_version_with` matcher' do
widget.update_attributes!(name: 'Bob')
end
it "is possible to do assertions on versions" do
it "is possible to do assertions on version attributes" do
expect(widget).to have_a_version_with name: 'Leonard', an_integer: 1
expect(widget).to have_a_version_with an_integer: 1
expect(widget).to have_a_version_with name: 'Tom'
end
end
```
There is also a `have_a_version_with_changes` matcher. This is only usable if your versions table [has an `object_changes` column for storing changesets](#3c-diffing-versions).
```ruby
describe '`have_a_version_with_changes` matcher' do
before do
widget.update_attributes!(name: 'Leonard', an_integer: 1)
widget.update_attributes!(name: 'Tom')
widget.update_attributes!(name: 'Bob')
end
it "is possible to do assertions on version changes" do
expect(widget).to have_a_version_with name: 'Leonard', an_integer: 2
expect(widget).to have_a_version_with an_integer: 2
expect(widget).to have_a_version_with name: 'Bob'
end
end
```
For more examples of the RSpec matchers, see the
[Widget spec](https://github.com/airblade/paper_trail/blob/master/spec/models/widget_spec.rb)
### 7.c. Cucumber

View File

@ -14,7 +14,7 @@ describe Widget, type: :model do
widget.update_attributes!(name: "Bob")
end
it "is possible to do assertions on versions" do
it "is possible to do assertions on version attributes" do
expect(widget).to have_a_version_with name: "Leonard", an_integer: 1
expect(widget).to have_a_version_with an_integer: 1
expect(widget).to have_a_version_with name: "Tom"
@ -28,10 +28,11 @@ describe Widget, type: :model do
widget.update_attributes!(name: "Bob")
end
it "is possible to do assertions on versions" do
it "is possible to do assertions on version changes" do
expect(widget).to have_a_version_with_changes name: "Leonard", an_integer: 2
expect(widget).to have_a_version_with_changes an_integer: 2
expect(widget).to have_a_version_with_changes name: "Tom"
expect(widget).to have_a_version_with_changes name: "Bob"
end
end