giant robots smashing into other giant robots

Written by thoughtbot

hrward

Ruby Science: How to Eliminate Feature Envy and Comments

Ruby Science

Since launching Ruby Science we’ve written and released five new chapters. If you’ve previously purchased the book, you can log into GitHub to download the latest version.

Here’s what we’ve added:

Code smells

  • Comments
  • Feature Envy

Solutions

  • Introduce Explaining Variable
  • Introduce Form Object
  • Move Method

The book is a work in progress, and we’ve now got around 60 pages of content. The purchase also includes an example application and support for any Ruby, Rails, and Refactoring questions you have. You can get access now for an early purchase price of $39. This will increase to $49 on January 31, 2013.

Download a free sample of Ruby Science today.

Episode #30: Giant Year-End Extravaganza

In this special episode to kick off 2013, Ben Orenstein is joined by Chad Pytel, the CEO of thoughtbot, to take a look back at some of the things thoughtbot did in 2012. They then answer a bunch of listener questions.

Episode #27: Fabulous new mistakes

In this podcast episode, Ben Orenstein is joined by Joe Ferris, CTO of thoughtbot. Inspired by a question on Law of Demeter from listener Nathan Long, Joe and Ben (hopefully) answer Nathan’s question, and then go on to discuss how the Law of Demeter is a form of duplication, how it effects testing, and how to better architect your report, your view, or your entire system to better obey the Law of Demeter. They also touch upon Rails’ try method, how the pain of testing helps guide the code you write, where the Law of Demeter doesn’t apply, how people don’t refactor their tests, how to productively refactor your tests and avoid wasting time rewriting things, and much more.

dancroak

Faster tests: sign in through the back door

One way to make tests faster is to avoid loading and submitting the sign in form during the setup phase.

This back door inserts Rack middleware into a Rails app that uses Clearance:

# config/environments/test.rb
class ClearanceBackDoor
  def initialize(app)
    @app = app
  end

  def call(env)
    @env = env
    sign_in_through_the_back_door
    @app.call(@env)
  end

  private

  def sign_in_through_the_back_door
    if user_id = params['as']
      user = User.find(user_id)
      @env[:clearance].sign_in(user)
    end
  end

  def params
    Rack::Utils.parse_query(@env['QUERY_STRING'])
  end
end

MyRailsApp::Application.configure do
  # ...
  config.middleware.use ClearanceBackDoor
  # ...
end

Then, include a user in an as parameter in integration tests:

visit root_path(as: user)

It works for any URL:

visit new_feedback_path(as: giver)

This is similar to Mislav’s approach except the Rack middleware works with Rails routing constraints.

On one project using this technique, the total test suite time was reduced 23%.

Written by .

cpytel

Take an online Test-Driven Rails Workshop with thoughtbot

We’ve just opened registration for our new online Test-Driven Rails workshop, which starts Monday, November 26th, 2012.

The course is taught by Josh Clayton, the maintainer of FactoryGirl, shoulda contributor, and experienced Rails developer. Over the course of a month you will code two Rails applications alongside Josh, working directly with him to learn TDD or improving your TDD practice. This isn’t just a series of videos; it’s an online workshop where you work directly with Josh getting one-on-one and group support.

Because the workshop takes place over the course of an entire month, it strikes a nice balance between making a ton of progress and working at a pace that will work around your schedule. There will also be additional time throughout the week to explore the nooks and crannies of TDD, helped along by Josh and the rest of the thoughtbot team.

Furthermore, when you take an online workshop with thoughtbot, it doesn’t just stop after the initial month. You get ongoing support for any testing questions you may have in the future, from Josh and the rest of the thoughtbot team.

We’d love to have you take this course. You can sign up now and the course begins Monday, November 26th, 2012.