You may already know about
rubocop, a testing tool and a checking tool (for ruby coding styles). They are not realted to be referred here in a same post but we’re using them these days in our company projects though. And actually we’re going to play with automation tests using
guard and its plugins today, which are
Rubocop and RSpecFor you who haven’t heard about
rspechave a look here:
guardhelps us having things rerun automatically when new changes get saved.
guard-rspecgets a spec re-run when you change and save it,
rubocopgets fired by
guard-rubocorpimmediately after any of your files got saved (of course only the ones in the rubocop.yml configuration list), specs get run by
guard-rspecwhen any of your spec gets changed and saved.
Note: One interesting thing is
guard-rspecre-runs only the spec recently changed, not the whole spec directory.
Firstly make sure you have
guardgem installed. Then add
guard-rubocopto the Gemfile:
group :development do
gem 'guard-rspec', require: false
Secondly let’s generate the
Guardfile which contains the configurations.
guard init rubocop
guard init rspec
Lastly, open another console and type in
gnguyen@gnguyen-ubuntu ~/work/bookstore (master)*$ guard
We now have specs and files automatically rerun/re-checked whenever new changes get saved 🙂
RubyMine integrationOnce we have both Guard running and Rubymine installed, we can make them work together seamlessly with just a few more steps.
Step 1: Enable “Save files on frame deactivation”Open the project directory with
Rubymine, go to
File > Settingsthen type
savein the Search box, make sure the checkbox for
Save files on frame deactivationis checked.
Step 2: Add Guard configuration
- Go to
Run > EditConfiguration
- Add new
IRB concolseby clicking the
- Name the new IRB console as ‘guard’ (or whatever you like)
- Set the Guard path in the IRB script field. We can retrieve this path by opening a new Terminal, navigate to the project directory and type
gnguyen@ubuntu ~/my_project$ which guard