How to configure your Rails engine with Rspec, Capybara, and FactoryGirl
1. Run the follow lines to generate a mountable engine
|
|
Tech && Learn && Fun
|
|
Recently, I build some Rails engines. And I found it’s a good way to organize and share reusable code across a number of applications.
Rails Engine is not like Ruby gem. It’s more like a rails app, it has its own controllers, views and migrations. And basically it has two type of engine, full or mountable.
I used to think cucumber for Rails is a little bit over kill for the developer. Because every time you have to write a lot of regular expression to work it out. But in the recently project, we use Capybara and poltergeist with RSpec to solve this problem. It even can test your SPA and integrate with CI very nicely.
Poltergeist is a driver for Capybara. It allows you to run your Capybara tests on a headless WebKit browser, provided by PhantomJS. So, what is headless? That means you don’t need to fire up your browser. What’s that mean? Fast!!
brew install phantomjs
in Mac.Nowaday, all the code should be tested before shipped. But we are all human being, we make mistakes. Sometime you are thinking just one line of code, not a big deal, just push it. Unfortunately, that line of code cause errors. So, we need something to automate test our codes after we pushed it to verify our code pass all the test case or not. That’s why CI introduced.
And for CI, in my option, there are two kinds right now, one is Jenkins with docker(more manual) and one is Codeship/travis-ci(more automated).
If you ever build a SPA app with authentication. The most hard part is keeping users sign-in when they’re coming back/refresh the browser.
So, how could this thing work out?
One possible method is update your header when the user signed in.
There are a lot of way you can integrate Angular with Rails, a common way is put Angular inside the Asset pipeline. It’s easy to integrate that way but the code base is quite mess at the later point. Recently, I found a way to use Yeomen generator and rails-api to work as front-end and back-end together.
Here’s some Pros and Cons for this way:
If you ever work with Rails and TDD, you may hear Factory girl: a great data mock gem to replace fixture. But sometime when your modal have some association with other modals, and that model have other associations, try to write a factory with callback (after build/create) become so hard. But thanks to thoughtbot, factory girl have data association build-in. You can read this post.
After using couple month using Hexo, I found it’s fun and easy to use for logging technology/problem solutions. But the image system still not so great like other blog systems. But it’s 2014 now, there’s a lot of alternate ways to find a free image hosting service like Tumblr.
In my blog, I use tumblr as the image hosting system.