I am new to ruby and rails. I am used to working in IDEs (Xcode, Visual Studio, etc.) where I can perform project-wide/workspace-wide "build/compile" operations.
Let's say that I modify a number of ruby files in my rails project. I haven't yet written tests that will exercise all of my changes.
Is there a way to ensure that all of my *.rb files compile without directly exercising them at runtime? I'd really just like to perform a "compile all of my ruby/erb files" operation so that I know that I don't currently have any syntax errors.
UPDATE
I probably should have mentioned that I've been writing code professionally for 20 years. I realize that Ruby isn't compiled like, say, C++, but that doesn't mean that its syntax can't be checked. In my case, I've decided to use ruby-lint to catch basic syntax errors without having to exercise the code at runtime.
If you're on Linux or Mac or some funny windows box with the gnu find command, you can do something like:
find /your/application_directory -name=*.rb -exec ruby -c {} \;
This will find all ruby scripts in the app directory and run ruby -c
on them, which will run a syntax check and respond with Syntax OK
or an error message if there is an error in the script.
You can also create a macro of this to your editor, so that when you save or press a key combination it will run ruby -c on the file and give you the results. In vim you can use this in your .vimrc :
map <Leader>c :w !ruby -c<cr>
Which maps Leader-c to write the file and check it's syntax using ruby -c
.
Verifying your rake-tasks and views for syntax errors might be a little trickier, but many of the templating engines like haml have similiar -c syntax check parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With