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>
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
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