Fixed an issue where named subjects could crash the compiler

Received:

Nil assertion failed (NilAssertionError)
  from ???
  ...
Error: you've found a bug in the Crystal compiler. ...

for this code:

subject(point) { Point.new }
describe "#x" do
  subject { point.x }
end

Redefining subjects with a named subject broke.
This commit fixes that with a simply flip in the definitions.
This commit is contained in:
Michael Miller 2019-05-21 13:44:19 -06:00
parent ec9e598882
commit 01b5d71ad0

View file

@ -781,8 +781,8 @@ module Spectator::DSL
# It is cached so that the same instance is used throughout the test.
# The subject will be recreated for each test it is used in.
macro subject(name, &block)
subject {{block}}
let({{name.id}}) { subject }
let({{name.id}}) {{block}}
subject { {{name.id}} }
end
# Defines an expression by name.