rubycoloredglasses


I'm Jason, a web applications developer in the Denver, Colorado area.


  1. When Testing Seems Pointless

    I remember when I was first exposed to the concept of test driven development (TDD), it seemed like you were writing a test that did the same thing as the function itself. This really left me perplexed as to why everyone was raving about it’s value.

    Take for instance the following method:

    class SomeClass
      def self.todays_date
        Time.now.strftime("%Y-%m-%d")
      end
    end
    

  2. Using Rspec to Test Controllers

    Here are some tips that will help you with Controller tests in Rspec.

    Common Response Methods

    # Get HTTP response code with message. Example: "302 Found"
    response.status
    
    # Get HTTP response code. Example: 200
    response.response_code
    
    # Get response body
    response.body
    
    # Get location header, used with redirects
    response.location
    

  3. Good Guy Greg

    Edits your code, updates your Rspecs


  4. Using Rails 2.3.8

    I’m working on a project that is stuck on Rails 2.3.8 due to the size and complexity of the codebase. Upgrading it would be a nightmare. I recently ran into an issue with the database_cleaner gem, which isn’t rolling back transactional queries properly. I’m not sure if the issue is with the gem, or perhaps some configuration with the system (ActiveRecord) which is causing the issue. Because of this, I’m wanting to create a dummy Rails 2.3.8 application so that I can reproduce the issue on a fresh, simple, vanilla Rails application.

    I created a new ‘rails238’ directory and switched to it, then created a new gemset via RVM.


  5. Rspec Executable Not Found

    I’m working on an older Rails 2.3.8 application that is way too complicated and without tests to make it worth upgrading to Rails 3 or higher. Because of this we must use RSpec-Rails 1.3.4, with RSpec 1.3.2.

    I was just trying to run a single test from the command line like so:

    $ bundle exec rspec spec/models/post.rb
    
    bundler: command not found: rspec
    
    Install missing gem executables with `bundle install`
    

  6. Changing the Default Text Editor

    Certain command line utilities drop into an external text editor program to accept certain types of input. For instance, when using the command ‘crontab -e’ to edit your cron table, your default text editor program will be opened up with the current cron table configuration. The same also applies to the Git versioning system when using the interactive rebase mode. This helps the program avoid supporting it’s own text editor, and allows the user to specify their preferred text editor.

    To specify the default text editor, simply edit or place the following definition inside of the .bash_profile file in your home directory. This example uses ‘/usr/local/bin/mate -w’ to specify that the Textmate editor be used. You may configure this value to reflect the path for Vim, Nano, or any other text editor you wish to use.


  7. Metaclass

    I ran into an instance of meta programming in Ruby today, in the Exceptional Ruby book I’m reading for work. It seems that the theme this week is “you don’t know Ruby as well as you could”.

    I might be wrong in my understanding here, but this is what I understand thus far:

    Ruby stores methods for an object in it’s class, not the object itself. Objects only really store their attributes/variables in memory. However there exists some unseen entity known as the metaclass which belongs to each object, and it can possibly store methods which belong to that object, but not necessarily to that objects class.


  8. Using Super with Ruby class methods

    One of the awesome things about Ruby is that you can over-ride methods you define, or even over-write methods that are built into Ruby.

    This may not be unique with Ruby, but you can also over-ride super class methods in your defined subclass and use ‘super’ to execute the logic defined in the super class version of that method.


  9. Ruby Coloured Glasses

    I’m sorry Taryn. My friend just pointed your site out to me. I swear it was a coincidence. I like your background by the way.


  10. Duplicate associated records when using FactoryGirl

    When I decided to start using tests as part of my development practice, I had the choice of using the default fixture system, or using one of the recommended fixture alternatives, also known as factories. I decided upon using FactoryGirl given it’s popular mention on the web, and one of the projects at work was using it.

    I had read much about the horrors if using fixtures, with the most memorable opinion of them being that they were ‘brittle’. This, and many other complaints, caused me to skip using fixtures and jump directly to using FactoryGirl.