close #381; Don't automatically load in RSpec and Cucumber helpers

This commit is contained in:
Ben Atkins 2014-12-29 15:42:49 -05:00
parent 39e1e56374
commit d048508f38
4 changed files with 36 additions and 8 deletions

View File

@ -20,6 +20,8 @@ PaperTrail::Rails::Engine.eager_load!
- [#394](https://github.com/airblade/paper_trail/pull/394) - Add RSpec matcher `have_a_version_with` for easier testing.
- [#391](https://github.com/airblade/paper_trail/issues/391) - `object_changes` value should dump to `YAML` as a normal `Hash`
instead of an `ActiveSupport::HashWithIndifferentAccess`.
- [#381](https://github.com/airblade/paper_trail/issues/381) - `Rspec` and `Cucumber` helpers should not be loaded by
default, regardless of whether those libraries are loaded.
- [#375](https://github.com/airblade/paper_trail/pull/375) / [#374](https://github.com/airblade/paper_trail/issues/374) /
[#354](https://github.com/airblade/paper_trail/issues/354) / [#131](https://github.com/airblade/paper_trail/issues/131) -
Versions should be built with `after_` callbacks so the timestamp field for a version can be forced to match the

View File

@ -992,8 +992,23 @@ You may want to turn PaperTrail off to speed up your tests. See the [Turning Pa
### RSpec
PaperTrail provides a helper that works with [RSpec](https://github.com/rspec/rspec) to make it easier to control when `PaperTrail` is enabled
during testing. By default, PaperTrail will be turned off for all tests.
PaperTrail provides a helper that works with [RSpec](https://github.com/rspec/rspec)
to make it easier to control when `PaperTrail` is enabled during testing.
If you wish to use the helper, you will need to require it in your RSpec test helper like so:
```ruby
# spec/rails_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
...
require 'paper_trail/frameworks/rspec'
```
When the helper is loaded, PaperTrail will be turned off for all tests by default.
When you wish to enable PaperTrail for a test you can either wrap the test in a `with_versioning` block, or pass in `:versioning => true` option to a spec block, like so:
```ruby
@ -1064,7 +1079,18 @@ It is also possible to do assertions on the versions using `have_a_version_with`
### Cucumber
PaperTrail provides a helper for [Cucumber](http://cukes.info) that works similar to the RSpec helper.
By default, PaperTrail will be turned off for all scenarios by a `before` hook added by the helper.
If you wish to use the helper, you will need to require in your cucumber helper like so:
```ruby
# features/support/env.rb
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
...
require 'paper_trail/frameworks/cucumber'
```
When the helper is loaded, PaperTrail will be turned off for all scenarios by a `before` hook added by the helper by default.
When you wish to enable PaperTrail for a scenario, you can wrap code in a `with_versioning` block in a step, like so:
```ruby
@ -1084,16 +1110,16 @@ If you wish to use the `RSpec` or `Cucumber` helpers with [Spork](https://github
manually require the helper(s) in your `prefork` block on your test helper, like so:
```ruby
# spec/spec_helper.rb
# spec/rails_helper.rb
require 'spork'
Spork.prefork do
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'paper_trail/frameworks/rspec'
require 'paper_trail/frameworks/cucumber'
...
@ -1106,9 +1132,10 @@ If you wish to use the `RSpec` or `Cucumber` helpers with [Zeus](https://github.
manually require the helper(s) in your test helper, like so:
```ruby
# spec/spec_helper.rb
# spec/rails_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'paper_trail/frameworks/rspec'

View File

@ -150,5 +150,3 @@ if defined? Rails
else
require 'paper_trail/frameworks/active_record'
end
require 'paper_trail/frameworks/rspec' if defined? RSpec::Core
require 'paper_trail/frameworks/cucumber' if defined? World

View File

@ -9,6 +9,7 @@ end
require 'spec_helper'
require File.expand_path('../../test/dummy/config/environment', __FILE__)
require 'rspec/rails'
require 'paper_trail/frameworks/rspec'
require 'shoulda/matchers'
require 'ffaker'