waterlink / spec2.cr

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

Allow to re-define `let`'s type in neighbour/inner/parent contexts with same name #6

Closed waterlink closed 8 years ago

waterlink commented 8 years ago

Example of problem:

let(stuff :: String) { "stuff" }

context "some" do
  let(stuff :: Int32) { 42 }
  # => Can't cast 42 to String
end

This happens, since let defines stuff macro as macro stuff (no args). So first defined will always be used, since they have one scope.

waterlink commented 8 years ago

Have no idea how to fix it at this point. At least without any sort of scoping.

waterlink commented 8 years ago

Maybe it is possible RFC to crystal to be able to define scopes for macros somehow:

macro stuff
  "stuff"
end
stuff # => "stuff"

macro_scope
  # .. there is no `stuff` macro here .. so:
  macro stuff
    42
  end
  stuff # => 42
end
waterlink commented 8 years ago

Maybe it is not actually a problem, just use different names for different types in specs?

waterlink commented 8 years ago

When second let is of the same type, everything works correctly as expected.