The Crystal Programming Language Forum

Crystal spec with http listener in source

Hi
Try to check my functions but crystal specs would not run my commands,
because there is http server listener in my code.
is there any whey that I could pass a variable to my module to not start HTTP::Server
when it is running with by “crystal spec” or you can suggest me a better way
when there is Listener or infinite loop inside a source code?

Try to extract as much code into a library kind of interface, such that you have a file which just does something like MyLib::Cli.new(ARGV).start_sever for example. Then for specs you load the library files but not the launcher file and expose and test the library functions and not call start_server, or call it within spawn.

You suggest me to break my code into two different files(and maybe two module) and in the require part of spec file only include the second file(which doesn’t have loop or listener )?

At least two!

1 Like

Thanks.