Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveSupport::Testing::TimeHelpers#to_travel does not support today #25848

Closed
abepetrillo opened this issue Jul 15, 2016 · 4 comments
Closed

Comments

@abepetrillo
Copy link

Steps to reproduce

  1. Create a new rails 5.0.0 app
  2. bundle exec rails console
  3. Create a test which implements the helper:
it "Changes current time to given time" do
  travel_to(Date.parse("monday")) do
    expect(Date.today).to eql Date.parse('monday') #=> false
  end
end

Expected behavior

the today method should return the date we just travelled to

Actual behavior

today gives the real time, and ignores the current time that travel_to is using.

System configuration

Rails version: 5.0.0

Ruby version: 2.3.1

@DeOldSax
Copy link

I tried to reproduce your case.

begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end

gemfile(true) do
  source 'https://rubygems.org'
  gem 'rails', github: 'rails/rails'
  gem 'byebug'
  gem 'rspec-rails'
end

require 'active_support/testing/time_helpers'
require 'active_support/core_ext/object/blank'
require 'minitest/autorun'

RSpec.configure do |config|
  config.include ActiveSupport::Testing::TimeHelpers
end

RSpec.describe "Date" do
  it "Changes current time to given time" do
    travel_to(Date.parse("monday")) do
      expect(Date.today).to eql Date.parse('monday') #=> false
    end
  end
end

Specs are passing and while debbuging Date.today also returns monday.

@rafaelfranca
Copy link
Member

Yes, same here. It may be something in your application.

@abepetrillo
Copy link
Author

abepetrillo commented Jul 16, 2016

Let me try reproducing it on a new app. Thanks for your time guys!

@bvicenzo
Copy link

For me, this returns the current friday instead of the same day 🤔

#!/usr/bin/env ruby

begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end

gemfile(true) do
  source 'https://rubygems.org'
  gem 'rails', github: 'rails/rails'
  gem 'byebug'
  gem 'rspec-rails'
end

require 'active_support/testing/time_helpers'
require 'active_support/core_ext/object/blank'
require 'minitest/autorun'

RSpec.configure do |config|
  config.include ActiveSupport::Testing::TimeHelpers
end

RSpec.describe "Date" do
  it "Changes current time to given time" do
    travel_to('2021-02-12') do
      expect(Date.parse('Friday')).to eq Date.new(2021, 2, 12) #=> false
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants