waterlink / spec2.cr

Enhanced `spec` testing library for [Crystal](http://crystal-lang.org/).
MIT License
103 stars 22 forks source link

Fix for crystal version 0.24.1 #60

Open ThunderKey opened 6 years ago

ThunderKey commented 6 years ago

With the current version of crystal (0.24.1) the tests fail.

The following changes where made:

1. Changed Time constructor

In spec/elapsed_time_spec.cr I had to change from Time.new(year, month, day, hour, minute, second, millisecond) to Time.new(year, month, day, hour, minute, second) + 57.milliseconds. This is due to an API change in the Time constructor, which dropped milliseconds but added nanoseconds. With this change both older versions and the current work the same.

2. Changed Time::Span constructor

Similar to 1. the constructor of Time::Span changed to now take nanoseconds as a named parameter.

I've added the to_milliseconds method to keep backwards compatibility. I used ms.milliseconds because it's simpler. Alternatively you could use Time::Span.new(nanoseconds: ms * 1_000_000) (note: 100 times more than in the previous version. Using ms.milliseconds in older versions does not break the build, but it ignores any floating points.

If you know a better option to check the crystal version or you don't want backwards compatibility just let me know.

3. Rounding

It seems like there have been minor changes to the rounding of numbers. The delta between 42.05 and 42 changed from 0.049999999999997158 to 0.04999999999999716.

As a workaround I've added a regex matcher that matches both and is in my opinion close enough for the test.

4. String represenations of literal expressions

The expression (2 + 2) is no as a String "(2 + 2)" and not "2 + 2" as before. 2 + 2 on the other hand is in all versions 2 + 2

As a workaround I've swiched from (2 + 2) to 2 + 2.

5. expect_raises without arguments

The methods expect_raises without any arguments got removed. I've added the parameter Exception to the unit test.

Testing

I've tested it with docker containers:

VERSION=0.24.1; docker run --rm -it -v $(pwd):/opt/project crystallang/crystal:$VERSION bash -c "cd /opt/project && crystal deps && ./scripts/test"
VERSION=0.23.1; docker run --rm -it -v $(pwd):/opt/project crystallang/crystal:$VERSION bash -c "cd /opt/project && crystal deps && ./scripts/test"
VERSION=0.22.0; docker run --rm -it -v $(pwd):/opt/project crystallang/crystal:$VERSION bash -c "cd /opt/project && crystal deps && ./scripts/test"
VERSION=0.21.1; docker run --rm -it -v $(pwd):/opt/project crystallang/crystal:$VERSION bash -c "cd /opt/project && crystal deps && ./scripts/test"
VERSION=0.20.1; docker run --rm -it -v $(pwd):/opt/project crystallang/crystal:$VERSION bash -c "cd /opt/project && crystal deps && ./scripts/test"
maiha commented 6 years ago

Nice! I'd like to use this in my fork. Could you make these commits into one?