timecop icon indicating copy to clipboard operation
timecop copied to clipboard

Tests without Date require `DateTime`

Open pvalena opened this issue 6 years ago • 4 comments

through active_supports calculations.rb.

Errors are all same:


  5) Error:
TestTimecopWithoutDate#test_recursive_travel_then_freeze:
NameError: uninitialized constant #<Class:Time>::DateTime
    /usr/share/gems/gems/activesupport-5.2.3/lib/active_support/core_ext/time/calculations.rb:50:in `at_with_coercion'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/time_stack_item.rb:59:in `time'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/time_stack_item.rb:129:in `compute_travel_offset'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/time_stack_item.rb:14:in `initialize'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/timecop.rb:192:in `new'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/timecop.rb:192:in `travel'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/timecop.rb:129:in `send_travel'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/lib/timecop/timecop.rb:62:in `travel'
    /builddir/build/BUILD/rubygem-timecop-0.9.1/usr/share/gems/gems/timecop-0.9.1/test/timecop_without_date_test.rb:93:in `test_recursive_travel_then_freeze'

pvalena avatar Jul 25 '19 17:07 pvalena

Hi there, I'm not sure I understand. Are you having trouble running the Timecop tests? It looks like you're running the test from the packaged gem. I guess there will be lots of path issues doing it that way. If you could provide some high level clarification on what you're trying to do it would help me be more helpful.

joshuacronemeyer avatar Oct 15 '20 20:10 joshuacronemeyer

Hello, sorry for brevity.

Correct, we're running the tests in Fedora during build process, in a %check section, as you can see in a package "specification": https://src.fedoraproject.org/rpms/rubygem-timecop/blob/master/f/rubygem-timecop.spec#_51

Note: we try to minimize dependencies (code coverage, rake, bundler etc.), and we also need to test using system-packaged (installed) gems, and without network connectivity.

That's usually done using some approach simulating what Rakefile executes (in your case directly the files). We require them from ruby instead (shouldn't have any impact, or am I wrong?), which is IMHO more robust way.

What I've basically encountered, during an update, is that there was a require on DateTime, a dependency that was (from the name of the test- intentionaly) missing, and therefore I got that traceback. IOW the tests are supposed to work without DateTime, but activesupports calculations.rb need it. Maybe you require older activesupport? (We have Rails 6.0 in Fedora.)

Reiterating on it, these are the failures I got: https://gist.github.com/pvalena/1adce2b5620a29131cc7283291684b33

Thank you for your response!

pvalena avatar Oct 29 '20 17:10 pvalena

I think the issue is that the test suite is executed this way:

$ ruby -I.:lib -e 'Dir.glob "test/**/*_test.rb", &method(:require)'

Given the test file names, no wonder there are issues. Using similar approach as upstream test suite, all tests pass just fine:

for i in test/*_test.rb; do
  ruby -I.:lib ${i}
done

voxik avatar Jan 18 '22 18:01 voxik

But this might be also given the test restructuring in 0.9.4 ¯_(ツ)_/¯

voxik avatar Jan 18 '22 18:01 voxik