<casionaut>
I've seen an if statement example out in the wild which looks like: `if 0 < x < 5` Since it doesn't use any logical operators, it looks foreign to me. Could someone explain this syntax?
<FromGitter>
<Blacksmoke16> pretty sure its just making sure `x` is between `0` and `5`exclusive
<FromGitter>
<Blacksmoke16> i.e. `(1..4).includes? x`
Sankalp has quit [Read error: Connection reset by peer]
Sankalp has joined #crystal-lang
Sankalp has joined #crystal-lang
Sankalp has quit [Changing host]
analogsalad has quit [Quit: bye]
ur5us has joined #crystal-lang
<SamantazFox_>
Hello there!
<SamantazFox_>
How can I make sure that the relative path to a file I need to use in my test is always good?
<SamantazFox_>
Let's say I'm in `spec/`. I have a folder named `include_tests` where some of my tests are located, and my test resources are in `../test_res`
<SamantazFox_>
How can I easily load them without having to hard-coding `../test_res/myfile.json` in `spec/helper.cr` and `../../test_res/myfile.json` in `spec/include_tests/myclass_spec.cr`
<FromGitter>
<Blacksmoke16> Can you just glob require test_res
<SamantazFox_>
Blacksmoke16 test_res only contain JSON files, that needs to be parsed
<FromGitter>
<Blacksmoke16> Ah gotcha
<FromGitter>
<Blacksmoke16> I'd say you can use a helper method to do this. I think I have an example somewhere, sec
<FromGitter>
<Blacksmoke16> then can do like `File.read datapath "myfile.json"`
<SamantazFox_>
`__DIR__` is always the project's root dir?
<FromGitter>
<Blacksmoke16> no, its the dir of the file its called in
<FromGitter>
<Blacksmoke16> absolute path to the directory the file is defined in*
<SamantazFox_>
I've created a bunch of files under `spec/` (some in subfolders) with only `pp File.expand_path("./")` in them, and they all print `$HOME/project/dir/`
<FromGitter>
<Blacksmoke16> pretty sure thats because thats not the same thing and expands based on your $PWD of where you run the binary
<SamantazFox_>
(and both `crystal spec` and `crystal spec spec/some/file.cr` yield the same result
<FromGitter>
<Blacksmoke16> i.e. `cd .. && crystal run dir/app.cr`
<FromGitter>
<Blacksmoke16> and see what it is then
<FromGitter>
<Blacksmoke16> > Relative paths are referenced from the current working directory of the process unless dir is given, in which case it will be used as the starting point. ⏎ ⏎ https://crystal-lang.org/api/master/File.html#expand_path(path:Path|String,dir=nil,*,home=false):String-class-method
<SamantazFox_>
In the context of a compiled binary, it's easy to figure out, but for specs, that's less obvious
<SamantazFox_>
and yep, it's the `$PWD` at the moment where `crystal spec` is run
<FromGitter>
<Blacksmoke16> right, so prob just want to use `__DIR__` so its always predictable