Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Standup 5/11/2011

Ryan Richard
Wednesday, May 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:

<code>
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)
end
</code>

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

<code>
it "scopes products to active and available" do
    get :index
    assigns(:products).should == assigns(:products).active
    assigns(:products).should == assigns(:products).available
end
</code>

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

<code>
def index
  @products_scope = Product.active.available
  @products = @products_scope.paginate(:per_page => blah blah blah)
end
</code>
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

2 Comments

  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) ) })()}
    end

    May 15, 2011 at 11:54 pm

  2. George Blazer says:

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

    just curious

    May 22, 2011 at 10:24 pm

Add New Comment Cancel reply

Your email address will not be published.

Ryan Richard

Ryan Richard
San Francisco

Recent Posts

  • Standup 9/8/11
  • Embedding VideoViews in your UI: Caution!
  • Standup 5/9/2011
Subscribe to Ryan's Feed

Author Topics

agile (6)
android (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >