RSpec Tips

Posted by Vincent Woo Tue, 15 Apr 2008 21:53:00 GMT

Since I’ve been following Jamis Buck’s advice to limit the brittleness of view tests, development has been much more productive. Test the things that matter most else you’ll end up with diminishing returns and the week passed by without any productive work done.

I’m taking one step further and I’ve decided not to write RSpec view specifications.

I will still continue to occasionally test important view elements. It just isn’t worth the extra baggage of writing and maintaining another set of specs for every single view. I’m feeling the pain there and I’m taking steps to eliminating it.

But it is also painful to sprinkle “integrate_views” syntactic vinegar throughout controller specifications. I don’t want to do without that since I would still get notified of template errors. Unfortunately, this is not the recommended behavior and not much was written on the subject.

Peter Marklund has a solution but it didn’t work for me. Maybe because RSpec was updated since his blog post was written but it is more likely that I’m missing something obvious. However, I dug around the plugin and was happy to discover a simple method override that worked. Add to spec_helper.rb:

module Spec
  module Rails
    module Example
      class ControllerExampleGroup
        module ControllerInstanceMethods
          def integrate_views?
            true
          end
        end
      end
    end
  end
end

btw, while browsing the RSpec mailing list, I came across a post that explains a way to slightly speed up test runs.

Posted in  | Tags , , ,  | no comments | no trackbacks

Rake task runs both Test::Unit and RSpec tests

Posted by Vincent Woo Sat, 19 Jan 2008 03:04:00 GMT

I’m in the middle of converting tests from Test::Unit to RSpec in an older Rails project. So far so good although I’m sure that would change as I dive into more complicated test cases. Still, I’m hoping the pain is worth it for the multiple contexts and lessened fixture reliance.

A nifty feature that I accidentally stumbled upon is that the default rake task would run the test in both test and spec directories. It’s not like I have to exclusively choose one or the other.

That opens up lots of test conversion options. I could convert the tests all at once or a little at a time. Or I could forget about conversion completely and merely write new tests in RSpec.

It’s little surprises like this that brightens up my workday.

UPDATE (FEB8,08): RSpec tests won’t run unless all Test::Unit tests passes.

Posted in  | Tags , , , ,  | no comments | no trackbacks

Rails String Core Extensions Cheatsheet

Posted by Vincent Woo Mon, 16 Jul 2007 22:43:00 GMT

PNG PDF



References
/CoreExtensions/String/Access.html
/CoreExtensions/String/Conversions.html
/CoreExtensions/String/Inflections.html
/CoreExtensions/String/Iterators.html
/CoreExtensions/String/StartsEndsWith.html
/CoreExtensions/String/Unicode.html
/CoreExtensions/Time/Conversions.html
Changing default date format in Rails @ Ruby Forum
Rails Rubyisms Advent @ errtheblog.com

Posted in ,  | Tags , , , , ,  | 1 comment | no trackbacks

Simply Restful Cheatsheet

Posted by Vincent Woo Sat, 19 Aug 2006 22:27:00 GMT

It was recently incorporated into Rails proper so it seemed like a good time to dive into the Simply Restful functionality. Not much documentation exists for it but many blogs have already posted tutorials.

The results of the past day or two’s tinkering distilled into a single 8.5 X 11 sheet:

.png .pdf


References
Ryan’s Scraps (1)
Ryan’s Scraps (2)
scottraymondnet
Riding Rails
Meta|ateM
anthonyeden.com

Posted in  | Tags , , , ,  | no comments | no trackbacks