Running Thoughts

Tim Bauer's webcast summaries/insights

Testing Rails Applications

Watched Noel Rappin talk at WindyCityRails 2009 regarding testing last month.

image0017

image0062

· Why it caught my eye

I am curious on Test Driven Development and in Rails specifically.

· Would I recommend you watch it?:

Perhaps. If you are a Rails developer. He focuses primarily on the ways to test different aspects of a Rails system. However, it was hard to track as he was moving so quickly from example to example and at times the code samples were not in the screen.

· Most Notable Point:

No one thing. Just a nice overview providing samples of how to test the aspects in a ruby stack.

· When should you fast forward?

If you are in … you are in on this one. There was no high/low.

Hope it helps. A lot of it went beyond my pay grade in the testing arena but its nice to know the macro areas he covers in case I need to zoom to those specific parts.

As always, for those amused here are my raw notes …

*** START OF RAW SCRIBBLE TAKEN WHILE RUNNING ***

……..○ Noel Rappin http://twitter.com/noelrap

…………….VP of Ruby Practice for Pathfinder Development and the author of Professional Ruby on Rails

……..○ WindyCityRails 2009

……..○ http://vimeo.com/6703197

……..

……..○ 0:5.353 – Intro

…………….§ How to test things that are not easy to test

…………….§ Changes should be driven by failed tests

……………………□ Not view, not refactoring

…………….§ Test close to code – controllers w/ controllers, etc

…………….§ Test features – not code

…………….§ Don’t test rails framework

……..○ 3:32.823 – Framework for testing

…………….§ Rspec vs. shoulda

……………………□ Very similar now

…………….§ New to testing – Use default (fixtures, test unit)

……..○ 3:32.823 – Model testing

…………….§ How to test associations

……………………□ Nva –

……………………□ Drive testing from actual feature

…………….§ Don’t do associations as blocks

……..○ 3:32.823 – Named Scopes

…………….§ Find functionality that is composable .. Basically methods

……………………□ Don’t test name scope is passing sql expected

…………….§ Test that it finds objects correctly (does / doesn’t find)

…………….§ Assert_same_elements

……………………□ Works but brittle (if universe of users changes)

……………………□ Better should_have_named_scope macro … positive and negative testing

…………………………..® Code example of the macro (need slides … originally in rspec)

……..○ Rails validations

…………….§ 12:13.682 – always test reg expr

……..○ 13:31.835 – Filters

…………….§ Manage access control – test from functional view

……..○ 15:9.997 – Testing Views

…………….§ Test. Test in such a way that the UI designer changing things doesn’t breaks test.

…………….§ Test for semantic structure level (DOM ID, CSS classes (marker classes to show data row))

…………….§ Assert_select works well

…………….§ Validate view on paper 1st

…………….§ Test for negative conditions is KEY. i.e. Admins have delete button … normal users don’t.

……..○ 18:32.335 – Test for Negative

…………….§ Assert_select … look for DOM ID of X

……………………□ Specify count … 1 or more … or zero … test for zero

……………………□ Psuedo classes … search list element that dom id <> X

……………………□ Specify arbitrary html attribute … validate things are in the form (source of image file, href of <A> etc … don’t tie to UI)

……………………□ ? Syntax … rails finders / sql statement … place holder for list

……………………□ Assert_select can be done in block

…………………………..® Ie sort behavior … use this structure to get view in order and validate order

……..○ 23:19.190 – Helpers

…………….§ Put complex logic from view here (good/bad)

…………….§ Auto generated in 2.3

…………….§ Block helpers

……………………□ Prior to 2.2 hard to test now easy

…………………………..® Assert not logged in

…………….§ 26:18.924 – Testing to output stream … concat

……………………□ Concat is not last call in helper sometimes … get output_buffer (all text to erb_out)

…………….§ Search_select

……………………□ Looks for instance variable response

……..○ 28:25.261 – Email

…………….§ Another kind of view … test structure (sent, values)

…………….§ Assert_select_email … testing sent, not sent … email spec for cucumber allows simulate open of email by target, click on link, etc

……..○ 30:4.191 – Social Networking

…………….§ Testing UserA / UserB changing on events from one another

…………….§ Hard to test (controller tests assume 1 session)

…………….§ Rails integration test – Open session method … works well

……..○ 31:37.880 – Ajax

…………….§ Hard to test

…………….§ Assert_select_rjs … does some stuff good … for rails stuff

…………….§ Blue ridge / screw.unit … just started using … javascript test like Rspec

……………………□ Packages so integrated w/ Rake

……………………□ Screw.unit … tests browser on launch

……..○ 33:46.729 – External Sites

…………….§ Use mock objects to encapsulate sites called

…………….§ Test failure response

……..○ 34:38.160 – Rake Tasks

…………….§ Encapsulate in ruby code (class/method) and test the method

…………….§ Invoke rake task programmatically

……..○ 35:25.222 – Dates and Time

…………….§ Time literals don’t work

…………….§ RESTful auth – intermittent timing error

…………….§ Gem called Timecop … freeze and manipulate time …

……………………□ Put in startup … and teardown

……………………□ Allows you to keep time equal for all test

……………………□ Messes up rake test times … small issue

……..○ 37:8.957 – File Uploads

…………….§ Fixture_file_upload method

……..○ 37:32.106 – Rack / Rails Metal

…………….§ Not a lot of experience here

…………….§ Rails Metal – bypasses rails router for speed

…………….§ Use rack::test … to test

……..○ 38:12.508 – Legacy App

…………….§ No tests (definition of legacy)

…………….§ Black box tests ..

…………….§ use mock objects

……………………□ Isolation

…………….§ Seam – change app that doesn’t current code

……..○ 39:50.347 – Wrap up

…………….§ Look for the tools (a lot exist) in rails environment

……..○ 41:7.876 – Q&A

…………….§ Functional (customer view) versus backend

……………………□ Example of error testing w/ model testing is key

……………………□ Model tests are more key … ditch cucumber if pinched for time

…………….§ Testing when render partial

……………………□ Mock test to verify partial (limited logic in view partial)

October 20, 2009 Posted by | 2-Perhaps (what floats your boat?) | , | 1 Comment