Archive | Ruby on Rails RSS feed for this section

How To Use The VCR Gem With Rails And Rspec

21 Oct

So yesterday I spent way too much time trying to make this really cool VCR gem work with my rspec tests. The problem was that most of the tutorials out there were pretty outdated, and things have changed a bit.

The VCR gem is really useful if you have methods that need to make an api request. You don’t want to make api requests during tests, especially if the api has some kind of rate limit (I’m looking at you Twitter!).

So what you could do is create a text file mocking the response you get from the web service you’re making the api to and do the tests that way, or you can use the VCR gem! The VCR gem makes an api request once, and records the response to a cassette, which it then uses in future tests. Clever, no?

Here’s how you set up the VCR gem in your Rails App with Rspec:
Continue reading


RubyMine Review: 5 Features That’ll Get You Hooked

17 Oct

Ever since I first learned Rails, I’ve used TextMate and then Sublime Text as my text editors of choice. They worked fine until I started using RubyMine, a Ruby on Rails IDE, a few weeks ago.  There is no going back. Here are just some of the features I can no longer live without:

Continue reading

When To Optimize For Pleasure

1 Oct

This weekend, I finally got to watch DHH (the guy who started Rails) talk about Rails and Backbone.js in a recent meetup at Manilla that I missed. The talk was almost two hours, but I highly recommend watching all of it. Here it is in case you missed it:

Here are a few takeaways that I absolutely loved:

Continue reading

My Rails New Workflow With Testing

21 Sep

After playing around with Django a few weekends ago, I decided to stick to Rails for my personal projects. This Quora answer sums up pretty well why I’m choosing Rails.

Another reason I love Rails is because I love test driven development, and Rails has testing at it’s core. I started a new project this morning, and wanted to share my workflow for starting a Rails app with all the Testing gems and configurations set up properly:

Continue reading

Here Are A Few Of My Favorite Gems (For Testing ;)

11 Aug

I absolutely LOVE the idea of Test Driven Development (TDD). Write a test, see it turn RED, write the code to make the test pass GREEN, REFACTOR your code, and keep doing it over and over again!

However, if you’ve tried writing tests, especially for Rails, you know how tedious the process could be to set up. I use Rspec for unit tests, Capybara for integration tests, Guard to keep re-running the tests every time I make changes to any files, and Spork  to have the tests run faster. And here are a few of my favorite gems that make developing and testing even more pleasant:
Continue reading

How To Configure Your “$ Rails New” Defaults

7 Aug

If you’ve used Ruby on Rails before, you’re probably familiar with the standard way of generating a new rails project:

$ rails new myAwesomeApp

However, did you know that you can add default options for your rails app? For example, if you want rails to skip test unit (if you’re using rspec instead), skip bundle install, and set your default database to PostgreSQL you can run:

$ rails new myAwesomeApp --skip-test-unit --skip-bundle -d postgresql

If you have specific defaults that you always use, here is a simple to configure the default rails command (“$ rails new myAwesomeApp”) to always include your options:

Continue reading

How To Download And Configure PostgreSQL For Rails On Your Mac

3 Aug

If you’ve played around with Ruby on Rails, you might have noticed that Rails comes with SQLite3 as your test / development database, while Heroku defaults to PostgreSQL in production.

This is not surprising, considering how hard it is to install PostgreSQL compared to SQLite3. However, since you’re not testing / developing in completely the same environment as production, you’re putting yourself in a position for some possibly nasty surprises (in case you can’t tell, I’ve definitely faced these already, even with my small apps!).

Luckily, there is now a simpler way to install and configure PostgreSQL if you haven’t ever downloaded it on your Mac before brought you by Ruby on Rails developer Gavin Morgan:

Continue reading