One thing I’ve always liked about TDD is the ease with which it guides you through development. Given an outside-in approach, one failing test will lead you into another, and as you develop you dive deeper. Each time you make a new set of tests pass you step back to the earlier context and continue until you’ve driven out your story one test at a time.
Read more »
- Tuesday Brown Bag: Yehuda
Yehuda Katz will be giving a brown bag on Tuesday at 12:30.
- assert_template Matching: RSpec's template matcher uses a reg ex, which is loose enough to cause some false positives.
will pass cause both of these to pass:
should render_template "_foo_bar.haml" should render_template "_bar.haml"
The best solution presented was to explicitly say what you expect not to be rendered(should_not render_template "_bar.haml"). There has been some activity on Github recently around ActionController's assert_template method, but none addressing this exact problem(1 example: https://github.com/rails/rails/pull/3879/files). The regex is complicated by the fact that it has to match ambiguous partials rendered with specific paths(should render_template "_bar.haml" needs to match render "foo/_bar.haml").
Let It Be: If you declare a "let!" variable at the top of a file, and redeclare that variable with a "let" statement in a nested context, the variable will not be lazily loaded. RSpec evaluates it as a "let!".
Binary Tempfiles: There is no way to open a new Tempfile in binary mode; you must open it first and then call foo.binmode.
Airbrake was acquired by Exceptional http://techcrunch.com/2012/02/07/exceptional-acquires-error-tracking-application-airbrake/
Auto compiling SASS, pre-3.0: Adam used 'compass watch' and Foreman to automate the regeneration of stylesheets in development. This prevents him from having to wait for the sass to recompile on the first request he makes after modifying stylesheets. https://github.com/ddollar/foreman
Should receive, in any order: Ian & Suman were attempting to write an RSpec 1.3 spec that asserted a method was called with an array that included the correct elements; however, the order of the elements within the array was not important. Seems there is no array_including equivalent to hash_including. The solution they came to was to use the block style expectation as defined here: https://www.relishapp.com/rspec/rspec-mocks/docs/argument-matchers
foo.should_receive(:bar) do |arg1| arg1.should =~ [3,1,2] end
Anyone know of a built-in matcher for arrays similar to hash_including?
Artifice test pollution: The Lees ran into an issue where every fifth selenium test was failing. They tracked it down to using Artifice to stub responses in their tests. Since Webdriver communicates with the browser through http requests the stubbed Artifice responses were being received by Webdriver, causing unexpected behavior. Be careful stubbing with Artifice or you may accidentally stub all localhost requests.
Devise stretches: Todd found that you can speed up your test suite by turning down Devise's level of password encryption in your testing environment. He got a 10% bump by including the following code in spec_helper:
Devise.setup do |config| config.stretches = 1 end
For more tips on cutting down your test suite's run time: http://www.rubyinside.com/careful-cutting-to-get-faster-rspec-runs-with-rails-5207.html
- Malloc/Seg Faults in 1.9.2: A few developers have been running into Malloc/Seg Fault errors recently. The cause is yet to be determined.
cycle(even, odd): Jonathan pointed out a method in rails that allows you to apply classes to the even and odd numbered indexes of collections, allowing you to easily apply zebra striping patterns to a collection. Peter mentioned the alternative CSS pseudo-selector "nth-child," which does the same thing with CSS and properly recalculates in the case where you remove an element with AJAX. Unfortunately, nth-child does not work with IE so if you have to support IE, use cycles, otherwise use nth-child.
will_paginate 3.0: Ian mentioned that version 3 of the will_paginate gem was recently released. It now uses scopes, bringing it up to speed with Kaminari, another popular pagination gem.
home_run hates ActiveSupport: JT and Micah pointed out that if you're adding a duration to a DateTime using home_run, like "DateTime.now + 1.day," it doesn't play well with ActiveSupport. It assumes that the number on the right is supposed to be days, which it converts to seconds 86,400 and then changes to days again(86,400 days). The '+' operator has been fixed in edge rails, but not yet back ported. They pointed out that although it doesn't read well, using #since on any instance of DateTime will act how you would hope the '+' operator would.
Sauce Labs requires Heroku: JT reported a problem he noticed where Sauce Labs tries to hit a Heroku instance. If you don't have an instance set up on Heroku, the sauce gem hangs.
EC2 Downtime: Amazon EC2 experienced some downtime last night.
NYC.rb presentation Tuesday at 7. The talk is titled, "Why doing things wrong is the right thing to do." and will be given by Jon Distad as a preview of the talk he'll give at the Ruby Hoedown.
We welcome Micah, a new Pivotal developer, to New York this week. Micah hails from Nevada City, CA.
NYC.rb presentation Tuesday at 7. The talk is titled, "Why doing things wrong is the right thing to do." and will be hosted by Jon Distad.