# Spec filename mistery!

**URL:** <https://forum.crystal-lang.org/t/spec-filename-mistery/6565>\
**Category:** Help & Support\
**Created:** [February 10, 2024, 9:37pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565 "2024-02-10T21:37:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [February 10, 2024, 9:37pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/1 "2024-02-10T21:37:19Z")

</div>

I’m coming up against a rather strange problem.

My project consists of several `_spec` files, and all the tests passed until I renamed one of the `_spec` files. The renamed file contains several tests, and the error occurs on the first one (and if I comment on this first test, the next one comes out in error, and so on). For all the tests, I check that the output (a multi-line character string) corresponds to what was expected. The error always occurs on the first line, as if the behavior of the source file algorithm (which generates the string in question) had been altered by the renaming!

I ran several renaming tests, and came to the conclusion that any filename would do, except precisely the one corresponding to the source file. However, this problem doesn’t occur for other specs files that have the same name as the source file.

I also cleared Crystal’s cache, but that didn’t change anything.  
There is, I suppose, a rational explanation for this.  
A clue?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [February 10, 2024, 9:39pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/2 "2024-02-10T21:39:30Z")

</div>

Could you share the error? Is the code public? Otherwise I feel like this is going to be hard to figure out without either.

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [February 10, 2024, 9:51pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/3 "2024-02-10T21:51:03Z")

</div>

Yes, code is public at [GitHub - hutou/tablo: Crystal text table generator](https://github.com/hutou/tablo)

The renamed file is `spec/rowgroup_spec.cr` in the development branch.  
Running the specs should generate the error, rename `spec/rowgroup_spec.cr` to anything else, and no error !

[Edit] I omitted to say that running `crystal spec -v spec/rowgroup_spec.cr` alone does not generate any error !  
… and also that moving `spec/row_spec.cr` from directory `spec/` prevents the error from occurring.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [February 10, 2024, 11:38pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/4 "2024-02-10T23:38:01Z")

</div>

Ah so it’s a spec failure, not an error. Also seems the error is coming from `table_pack_spec.cr` not `rowgroup_spec.cr`.

I looked thru the code a bit, and are you sure it’s not just due to your tests being “unsafe?” I.e. one spec could be mutating some global setting that causes another test case to fail since it’s in a diff state than if you just ran that one spec directly?

Running specs with `--order=random` seem to cause a random spec to fail, so it does seem like _something_ is leaking state between each test case.

FWIW renaming that one file didn’t make a difference for me. But commenting out `row_spec.cr` did allow things to pass. Maybe that’s a clue…

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [February 13, 2024, 11:07pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/5 "2024-02-13T23:07:05Z")

</div>

What is `crystal spec` --debug option used for ?  
Does it mean it is possible to create an executable from `crystal spec` ?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [February 14, 2024, 3:39am UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/6 "2024-02-14T03:39:53Z")

</div>

I mean yea. When you run `crystal spec`, it’s just requiring all your test files and `spec_helper`, compiling a temp binary, and running it. Much like as if you do `crystal run file.cr`.

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [February 14, 2024, 10:19am UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/7 "2024-02-14T10:19:17Z")

</div>

Great, but what is the temp binary filename and where is it located ?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [February 14, 2024, 2:05pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/8 "2024-02-14T14:05:22Z")

</div>

I’d guess `$ crystal env CRYSTAL_CACHE_DIR`, but looks like it mainly just has the `.o` files versus the actual temp binaries. But why? What are you wanting to do? Might be easier to just add some `require` to your `spec_helper` for each spec, then do a `crystal build spec/spec_helper.cr` and use that.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [February 19, 2024, 5:50pm UTC](https://forum.crystal-lang.org/t/spec-filename-mistery/6565/9 "2024-02-19T17:50:04Z")

</div>

`crystal spec` is pretty much equivalent to `crystal run spec/ **/*_spec.cr`. You can just turn that into `crystal build spec/** /*_spec.cr -o spec_runner` to get an executable program.
