Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
Move Over Timecop…Hello ActiveSupport::Testing::TimeHelpers

Imagine this, you are testing a Rails application with RSpec and you have the need to freeze or travel through time in your specs. Your old trusted friend Timecop has served you well in the past but you’ve heard about this new kid in Rails 4.1, ActiveSupport::Testing::TimeHelpers.

Read more »

LABS
Making sure you implement the ActiveModel interface fully

Rails 3 brings with it ActiveModel.

ActiveModel give you a way to make non-db backed models look like db backed models to your views and controllers. See this post for a good explanation of what using ActiveModel buys you.

ActiveModel gives you a great way to test that your class implements the minimum ActiveModel interface: ActiveModel::Lint::Tests

Check out this gist for the details for using these tests in RSpec:

LABS
RSpec 2 Gotcha with polymorphic_path

A quick gotcha we ran into when using polymorphic path and rspec2 today.

In a controller test we had an assertion:

response.should redirect_to(polymorphic_path(@some_object))

Which resulted in the following error

Failure/Error: Unable to find matching line from backtrace stack level too deep
# ~/.rvm/gems/ruby-1.9.2-p0@gemset/gems/rspec-expectations-2.1.0/lib/rspec/matchers/method_missing.rb:4

It turns out polymorphic path is not available in the controller test (but the usual object_path method is). As to why this throws a stack level too deep and not a method undefined looks like potentially another bug in rspec but the solution seemed to be to do the following in our spec_helper.b for Rails 3:

include Rails.application.routes.url_helpers

For Rails 2.x you'll want to use:

include ActionController::UrlWriter

I've opened an issue for this on github as well https://github.com/rspec/rspec-expectations/issues/issue/46

LABS
Testing Rails3 Generators using Cucumber and Aruba

In an effort to continue my contributions to the open source Ruby/Rails ecosystem, I decided to help the factory_girl_rails team move the Rails3 generators from the rails3-generators project into the factory_girl_rails project.

Like all good Ruby/Rails developers, they asked to make sure that I had tests written around the generators. I thought for a bit on how I was going to do this and then I wandered across the Cucumber feature files in the rspec-rails repo and found my answer.

Rspec-rails (and RSpec2 as well) uses a gem called Aruba to easily write Cucumber features around things that happen from the command line.

If you'd like to check out the result of using Cucumber and Aruba to test Rails3 generators, head over to my fork of the factory_girl_rails gem and check out the features/generators.feature file.

Hopefully the changes will be merged into the official factory_girl_rails repo soon and the generators will live closer to home.

LABS
Using RSpec-rails2 to test Rails3 ApplicationController functionality

The other day I was looking to test some rescue_from functionality in a subclass of ApplicationController and found an easy way to set this up, the controller() method.

Note: Testing of ApplicationController subclasses is a new addition and not available in a released beta of rspec-rails2 as of the writing of this post.