ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
ur5us has quit [Ping timeout: 240 seconds]
Vexatos has quit [*.net *.split]
mikko has quit [*.net *.split]
Vexatos has joined #crystal-lang
mikko has joined #crystal-lang
mikko has joined #crystal-lang
mikko has quit [Changing host]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 258 seconds]
notzmv has quit [Ping timeout: 260 seconds]
casionaut has joined #crystal-lang
casionaut has quit [Client Quit]
analogsalad has joined #crystal-lang
casionaut has joined #crystal-lang
notzmv has joined #crystal-lang
<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`
<casionaut> Hmm, it compiles but doesn't seem to be working for me when used in that context: https://play.crystal-lang.org/#/r/d7k9
<FromGitter> <Blacksmoke16> one of your `<` was the wrong way
<FromGitter> <Blacksmoke16> i.e. `if 2 < x < 5` not `2 > x < 5`
<casionaut> Ah gotcha
<casionaut> I couldn't find it in the control expressions section of the language reference
<casionaut> That added to the confusion
<casionaut> That's awesome, thanks!
casionaut has quit [Quit: Client closed]
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> ```def datapath(*components) ⏎ File.join("spec", "std", "data", *components) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=628eba20c61b987d33c88264]
<FromGitter> <Blacksmoke16> or something like: ⏎ ⏎ ```def datapath(file) ⏎ File.join( __DIR__, "test_res", file) ⏎ end``` ⏎ ⏎ Would prob do the trick, where that's defined in your spec helper [https://gitter.im/crystal-lang/crystal?at=628eba7be393a3180625d1c8]
<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
<SamantazFox_> yeah, seems like what I need
<SamantazFox_> thanks :)
<FromGitter> <Blacksmoke16> 👍