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

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 5/11/2011

Ask for Help

“How can you resize the browser window from a Capybara test before visiting the page under test?”

Interesting Things

Tommy had a suggestion for testing scopes in Rails controller tests.

Here is an example of the type of test that he does not enjoy writing:

it "scopes products to active and available" do
    not_active = Factory(:product, :active => false)
    not_available = Factory(:product, :available => false)
    active_available = Factory(:product, :active => true, :available => true)
    get :index
    assigns(:products).should_not include(not_active)
    assigns(:products).should_not include(not_available)
    assigns(:products).should include(active_available)

Here is a nice way that he found to write the same test:

it "scopes products to active and available" do
    get :index
    assigns(:products).should == assigns(:products).active
    assigns(:products).should == assigns(:products).available

The only question is what to do with pagination? A work-around is for the controller to do:

def index
  @products_scope =
  @products = @products_scope.paginate(:per_page => blah blah blah)

  1. Jeff Dean says:

    You can resize the window like so:

    Before(‘@javascript’) do
    page.evaluate_script %Q{(function(){ resizeTo( (window.screen.availWidth – 100), (window.screen.availHeight – 100) ) })()}

  2. George Blazer says:

    that’s great, how would you test a scope that only does :include, and has no conditions?

    just curious

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *