The Fixer said over 6 years ago permalink Comment? (4)
Tagged: testing

Fixture Scenarios

Tom Preston-Werner has a plugin called FixtureScenarios, which solves
all of my objections about the abomination known as fixtures.

Description

Download

The Hacker said over 5 years ago permalink Comment? (0)
Tagged: ruby rails functional testing

A Window Into Functional Tests

So like any ruby blooded human, I create functional tests for my rails applications. However, things don’t always go as planned; a redirect instead of a success, but where to?, the assigns is right, but the flash was wrong, etc.

Sometimes you just need a way to peek at what you get back. If you enjoy gouging your eyes out you can do a puts @response or @response.body

A slightly better alternative is to spit the body to a file and preview it in firefox.

    tmpfile = File.new(tmpname = 'tmp/test_page.html', "w")
    tmpfile.puts @response.body
    tmpfile.close
    `firefox #{tmpname}`

Put this after any get, post, etc, and you will get a decent html output of your view (sans stylesheets and valid links) Although nothing is stopping you from outputting to public, running script/server, and viewing it from there.

  • If your dealing with redirects, don’t forget about follow_redirect!
  • If your crossing controllers, use integration tests =)

It’s not the be all end all of solutions, but it helps for a quick glimpse while fixing tests.
Hope it helps!

The Decider said over 3 years ago permalink Comment? (0)
Tagged: testing shoulda

Run individual shoulda tests

When you run tests of just one model or controller you usually do something like:

ruby test/unit/evaluation_test.rb

If you want to target just one test you can use the -n option

ruby test/unit/evaluation_test.rb -n test_return_pending_evaluatees_from_composite_group

For shoulda users if you want to target just one test the -n option can also take regular expressions.

ruby test/unit/evaluation_test.rb -v -n "/have many/"

The -v lists the test name before every test, aka verbose mode.