Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions spec/elapsed_time_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../src/elapsed_time"

module Spec2
Spec2.describe ElapsedTime do
let(started_at) { Time.new(2014, 4, 21, 13, 27, 33, 57) }
let(started_at) { Time.new(2014, 4, 21, 13, 27, 33) + 57.milliseconds }

describe "#to_s" do
context "when seconds < 1" do
Expand All @@ -21,25 +21,33 @@ module Spec2
).to_s).to eq("999.0 milliseconds")
end

def to_milliseconds(ms)
{% if Crystal::VERSION =~ /\A0\.(2[0-3]|[01][0-9])\./ %} # < 0.24
Time::Span.new(ms * 10_000)
{% else %}
ms.milliseconds
{% end %}
end

it "returns in milliseconds rounded to .2" do
expect(ElapsedTime.new(
started_at,
started_at + Time::Span.new(36 * 10000)
started_at + to_milliseconds(36)
).to_s).to eq("36.0 milliseconds")

expect(ElapsedTime.new(
started_at,
started_at + Time::Span.new(36.5 * 10000)
started_at + to_milliseconds(36.5)
).to_s).to eq("36.5 milliseconds")

expect(ElapsedTime.new(
started_at,
started_at + Time::Span.new(36.57 * 10000)
started_at + to_milliseconds(36.57)
).to_s).to eq("36.57 milliseconds")

expect(ElapsedTime.new(
started_at,
started_at + Time::Span.new(36.573 * 10000)
started_at + to_milliseconds(36.573)
).to_s).to eq("36.57 milliseconds")
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/matchers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Spec2.describe Spec2::Matchers do
expect(42.05).to be_close(42, 0.01)
}.to raise_error(
Spec2::ExpectationNotMet,
"Expected to be close:\n Expected: 42\n Actual: 42.05\n Max-delta: 0.01\n Delta: 0.049999999999997158"
match(/Expected to be close:\n Expected: 42\n Actual: 42.05\n Max-delta: 0.01\n Delta: 0.049999999999997\d+/)
)
end
end
Expand Down Expand Up @@ -522,7 +522,7 @@ Spec2.describe Spec2::Matchers do
end
end

describe (2 + 2) do
describe 2 + 2 do
context "when describe uses literal expression" do
it "fails" do
expect {
Expand Down
2 changes: 1 addition & 1 deletion unit_spec/simple_dsl_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ module SimpleDSLSpec
example = ::Spec2::Context.contexts[0].examples[0]

it "still gets executed" do
expect_raises do
expect_raises(Exception) do
example.run
end

Expand Down