My submission for Ruby Challenge #3: Short Circuit
rubylearning.com/blog/2009/10/30/rpcfn-short-circuit-3/
-
100% RSpec test coverage
-
Works in both Ruby 1.8 and 1.9
| Scenario: login with valid credentials | |
| Given I am on the login page | |
| When I fill in "Email" with "[email protected]" | |
| And I fill in "Password" with "test123pass" | |
| And I press "Login" | |
| Then I should be on the users home page | |
| And I should see "Login successful" |
| package org.vm.web; | |
| import java.util.*; | |
| /** | |
| * @author thuss | |
| */ | |
| public class CollectionStuff { | |
| private Map<String, String> redirects = new HashMap<String, String>() {{ |
| #!/bin/bash -e | |
| # | |
| # This script clones or fetches the latest updates from selected repo's and then tar's them up | |
| # | |
| CHECKOUT_DIR=$HOME/backups/checkouts | |
| BACKUP_DIR=$HOME/backups/tarballs | |
| LOG=/tmp/github-daily-backups.log | |
| REPOS="vm-main vm-cdn vm-operations-chef vm-iphone vm-contrib" | |
| function clone_or_fetch { |
| require File.dirname(__FILE__) + '/spec_helper.rb' | |
| describe ArrivalCalculator do | |
| include ArrivalCalculator | |
| it "should throw an exception on unexpected values" do | |
| lambda { average_time_of_day(["26:41am", "6:51am"]) }.should raise_error(ArgumentError) | |
| end | |
| it "should handle a single time" do |
| require 'time' | |
| module ArrivalCalculator | |
| TWELVE_HOURS = 12 * 60 * 60 | |
| TWENTY_FOUR_HOURS = 24 * 60 * 60 | |
| # Average time of day expects array such as ['11:00am', '1:00pm'] => '12:00pm' | |
| def average_time_of_day(times) | |
| times_in_seconds = times.map do | time | | |
| raise ArgumentError, "Unexpected format " + time unless time.strip =~ /^[01]?\d:\d\d(am|pm)$/ |