Baseline - an Empty Rails 4 + Ember App
Last night we were wondering how much work is involved in taking a stock Rails 4 application, removing turbolinks and turning it into something ready for doing BDD of an Ember.js application. “Can’t take too long” we thought to ourselves. Famous last words.
Baseline is just this, an empty Rails 4 app, with the environment configured to allow you to immediately start adding your features with Ember on the front-end and a Rails API on the backend. We realise this is a pretty opinionated project, but we all love opinions, right? That’s why we use Rails and Ember in the first place. Let’s talk about some of the things that we’ve added:
In the Rails community, it’s kind of a standing gag that it’s the convention of the community to break with convention and remove the minitest test suite that Rails defaults to and add RSpec. We use RSpec for unit testing our code, and doing functional tests of controller actions. What we love about RSpec is the way that it allows us to build up execution contexts by nesting
context blocks which are then lazily evaluated for each execution context, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
We use Cucumber as our acceptance testing system. It’s pre-configured with Poltergeist to drive the headless webkit brower PhantomJS to make sure that our front-end application behaves as expected. One of the nice things about Cucumber is that it uses a plain-english style syntax (called gherkin) to allow us to write our test scenarios in plain english, for example:
1 2 3 4 5 6 7 8
1 2 3
Guard is a ruby-based file watcher. This doesn’t sound that amazing, but it has a great plugin architecture and great support from the Ruby community meaning that there are a whole lot of guard plugin gems available. we’ve wired up Guard with the various plugins to have it start a complete development environment, including Rails, Sidekiq, RSpec, Cucumber and Jasmine.
Guard watches for file changes, and then uses the rules in it’s
Guardfile to start, restart or run the various plugins. For example, when you modify any files in
config/ it restarts Rails & Sidekiq, when you modify something in
app/models/ it runs the corresponding unit tests in RSpec, and when you modify something in
We’re strong proponents of the continuous flow style of Agile software development and along with that we feel that continuous integration (ie automatically running the full test suite every time you commit) and continuous deployment (automatically deploying your code to production whenever you merge to master and the tests pass), so we’ve made a point of setting up Baseline on Codeship (an excellent cloud-based service for CI and CD) to automatically test and deploy any changes as they happen to Heroku, so that you can see straight away any changes that you make. You can see the current build of Baseline running at http://baseline-rails.herokuapp.com/.
There’s much much more to talk about in Baseline, and we expect it to be the subject of a number of blog entries in the future. Watch this space.