Simplify the way to freeze time in specs

This commit is contained in:
Javi Martín
2018-08-30 18:06:31 +02:00
parent eeb7463ff4
commit 02b8bc6f69
3 changed files with 10 additions and 15 deletions

View File

@@ -1,16 +1,8 @@
require 'rails_helper'
feature 'Residence' do
feature 'Residence', :with_frozen_time do
let(:officer) { create(:poll_officer) }
background do
travel_to Time.now # TODO: use `freeze_time` after migrating to Rails 5.
end
after do
travel_back
end
feature "Officers without assignments" do
scenario "Can not access residence verification" do

View File

@@ -1,9 +1,8 @@
require 'rails_helper'
feature 'Officing Results' do
feature 'Officing Results', :with_frozen_time do
background do
travel_to Time.now # TODO: use `freeze_time` after migrating to Rails 5.
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
@poll = @officer_assignment.booth_assignment.poll
@@ -18,10 +17,6 @@ feature 'Officing Results' do
login_as(@poll_officer.user)
end
after do
travel_back
end
scenario 'Only polls where user is officer for results are accessible' do
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)

View File

@@ -82,6 +82,14 @@ RSpec.configure do |config|
Bullet.end_request
end
config.before(:each, :with_frozen_time) do
travel_to Time.now # TODO: use `freeze_time` after migrating to Rails 5.
end
config.after(:each, :with_frozen_time) do
travel_back
end
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options.
config.example_status_persistence_file_path = "spec/examples.txt"