Support describing non-class/non-module constants
Noticed that one cannot describe a non-class/non-module constant.
Examples
src/test.cr
module Test
FOO = [1,2,3]
end
spec/test_spec.cr
require "./spec_helper"
Spectator.describe Test::FOO do
it "not be nil" do
expect(Test::FOO.length).to_not eq(nil)
end
end
Output
error in line 1
Error: while requiring "./spec/test_spec.cr"
There was a problem expanding macro 'describe'
Called macro defined in lib/spectator/src/spectator.cr:27:3
27 | macro describe(description, &block)
Which expanded to:
> 1 | # This macro creates the foundation for all specs.
> 2 | # Every group of examples is defined a separate module - `SpectatorExamples`.
> 3 | # There's multiple reasons for this.
> 4 | #
> 5 | # The first reason is to provide namespace isolation.
> 6 | # We don't want the spec code to accidentally pickup types and values from the `Spectator` module.
> 7 | # Another reason is that we need a root module to put all examples and groups in.
> 8 | # And lastly, the spec DSL needs to be given to the block of code somehow.
> 9 | # The DSL is included in the `SpectatorTest` class.
> 10 | #
> 11 | # For more information on how the DSL works, see the `DSL` module.
> 12 |
> 13 | # Root-level class that contains all examples and example groups.
> 14 | class SpectatorTest
> 15 | # Pass off the description argument and block to `DSL::StructureDSL.describe`.
> 16 | # That method will handle creating a new group for this spec.
> 17 | describe(Test::FOO) do
> 18 | it("not be nil") do
> 19 | (expect(Test::FOO.length)).to_not(eq(nil))
> 20 | end
> 21 | end
> 22 | end
> 23 |
Error: expanding macro
There was a problem expanding macro 'describe'
Called macro defined in lib/spectator/src/spectator/dsl/groups.cr:46:5
46 | macro describe(what, &block)
Which expanded to:
> 1 | context(Test::FOO) do
> 2 | it("not be nil") do
> 3 | (expect(Test::FOO.length)).to_not(eq(nil))
> 4 | end
> 5 | end
> 6 |
Error: expanding macro
In lib/spectator/src/spectator/dsl/groups.cr:24:30
24 | {{described_type.name}}
^---
Error: undefined macro method 'ArrayLiteral#name'
In src/test.cr:5:9
5 | FOO = [1,2,3]
^
Error: undefined macro method 'ArrayLiteral#name'