Skip to content

Commit

Permalink
Merge pull request #40 from greyblake/crystal-0-18-0
Browse files Browse the repository at this point in the history
Make it work with Crystal 0.18.0
  • Loading branch information
waterlink authored Jun 15, 2016
2 parents 30bfe0d + bc95c48 commit c30c10b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
16 changes: 8 additions & 8 deletions spec/elapsed_time_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ module Spec2
it "returns in milliseconds" do
expect(ElapsedTime.new(
started_at, started_at + 1.milliseconds,
).to_s).to eq("1 milliseconds")
).to_s).to eq("1.0 milliseconds")

expect(ElapsedTime.new(
started_at, started_at + 50.milliseconds,
).to_s).to eq("50 milliseconds")
).to_s).to eq("50.0 milliseconds")

expect(ElapsedTime.new(
started_at, started_at + 999.milliseconds,
).to_s).to eq("999 milliseconds")
).to_s).to eq("999.0 milliseconds")
end

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

expect(ElapsedTime.new(
started_at,
Expand All @@ -48,15 +48,15 @@ module Spec2
it "returns in seconds" do
expect(ElapsedTime.new(
started_at, started_at + 1.seconds,
).to_s).to eq("1 seconds")
).to_s).to eq("1.0 seconds")

expect(ElapsedTime.new(
started_at, started_at + 34.seconds,
).to_s).to eq("34 seconds")
).to_s).to eq("34.0 seconds")

expect(ElapsedTime.new(
started_at, started_at + 59.seconds,
).to_s).to eq("59 seconds")
).to_s).to eq("59.0 seconds")

expect(ElapsedTime.new(
started_at, started_at + 60.seconds,
Expand All @@ -66,7 +66,7 @@ module Spec2
it "returns in seconds rounded to .2" do
expect(ElapsedTime.new(
started_at, started_at + 7.seconds,
).to_s).to eq("7 seconds")
).to_s).to eq("7.0 seconds")

expect(ElapsedTime.new(
started_at, started_at + 7.3.seconds,
Expand Down
2 changes: 1 addition & 1 deletion 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.05"
"Expected to be close:\n Expected: 42\n Actual: 42.05\n Max-delta: 0.01\n Delta: 0.049999999999997158"
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/high_runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ module Spec2
want_exit(1) if current_runner.failed?
end

delegate current_context, current_runner
delegate current_context, to: current_runner
end
end
23 changes: 12 additions & 11 deletions src/matchers/be.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ module Spec2
def initialize(@actual : T, @expectation : ExpectationProtocol)
end

macro method_missing(name, args, block)
ok = !!(@actual.{{name.id}}({{args.argify}}) {{block}})
#macro method_missing(name, args, block)
macro method_missing(call)
ok = !!(@actual.{{call.name.id}}({{call.args.argify}}) {{call.block}})

{% if args.size == 0 %}
failure = "Expected #{@actual.inspect} to be {{name.id}}"
negated = "Expected #{@actual.inspect} not to be {{name.id}}"
{% if call.args.size == 0 %}
failure = "Expected #{@actual.inspect} to be {{call.name.id}}"
negated = "Expected #{@actual.inspect} not to be {{call.name.id}}"
{% end %}

{% if args.size == 1 %}
failure = "Expected #{@actual.inspect} to be {{name.id}} #{{{args.first.id}}}"
negated = "Expected #{@actual.inspect} not to be {{name.id}} #{{{args.first.id}}}"
{% if call.args.size == 1 %}
failure = "Expected #{@actual.inspect} to be {{call.name.id}} #{{{call.args.first.id}}}"
negated = "Expected #{@actual.inspect} not to be {{call.name.id}} #{{{call.args.first.id}}}"
{% end %}

{% if args.size > 1 %}
failure = "Expected #{@actual.inspect} to be {{name.id}} #{ { {{args.argify}} } }"
negated = "Expected #{@actual.inspect} not to be {{name.id}} #{ { {{args.argify}} } }"
{% if call.args.size > 1 %}
failure = "Expected #{@actual.inspect} to be {{call.name.id}} #{ { {{call.args.argify}} } }"
negated = "Expected #{@actual.inspect} not to be {{call.name.id}} #{ { {{call.args.argify}} } }"
{% end %}

@expectation.callback(ok, failure, negated)
Expand Down
14 changes: 7 additions & 7 deletions src/spec2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ module Spec2
configure_order(Orders::Random)
end

delegate configure_reporter, high_runner
delegate configure_runner, high_runner
delegate configure_order, high_runner
delegate configure_output, high_runner
delegate current_context, high_runner
delegate exit_code, high_runner
delegate run, high_runner
delegate configure_reporter, to: high_runner
delegate configure_runner, to: high_runner
delegate configure_order, to: high_runner
delegate configure_output, to: high_runner
delegate current_context, to: high_runner
delegate exit_code, to: high_runner
delegate run, to: high_runner

macro describe(what, file = __FILE__, line = __LINE__, &block)
::Spec2::DSL.describe({{what}}, {{file}}, {{line}}) {{block}}
Expand Down

0 comments on commit c30c10b

Please sign in to comment.