May72012

Running Git in Visual Studio 2010

More and more developers using Visual Studio are starting to embrace the command line after many years of trying to get away from it. Git has got many developers “re-learning” how to use the terminal and most are enjoying it. Recently a friend was saying that the only part he hates about Git is that sometimes he needs to have multiple terminals open, with multiple Visual Studio 2010 instances for different projects and sometimes he got slightly confused as to which terminal he was supposed to be operating.

Nuget:

Nuget is package manager for .Net similar to RubyGems for Ruby. Nuget runs using Powershell which means that we can install PoshGit into the Nuget Powershell profile. This is all exceptionally easy!

Steps to install:

  1. Make sure that Git is installed and that the “git” command is available from the console.
  2. Clone the PoshGit repo from GitHub to your machine (“git clone https://github.com/dahlbyk/posh-git.git”)
  3. Install Nuget if you haven’t already
  4. Open VS2010
  5. Click View -> Other Windows -> Package Manager Console
  6. Navigate to where you cloned the PoshGit repo (e.g. “cd C:\GitHubRepos\posh-git”)
  7. type “.\install.ps1
  8. Reload your Nuget Powershell profile by typing “. $PROFILE

Now you can load any of your solutions, pop open the Package Manager Console and type your git commands in there, instead of working in a separate terminal.

November112011

Introduction to the Jasmine Testing Framework - Part 1

This is the first post in an ongoing series of blogposts I will be writing about the Jasmine testing framework for javascript.

The Jasmine javascript testing framework is a beautifully developed framework that is very “English” based in its approach. Once your tests are written they read like documentation you would generally write for an application. The major benefit of this is that when you revisit code or hand it off to a colleague it is easy to pickup where you left off and its easy to get to understand what your code is doing.

This introduction to Jasmine will *not* cover any basics of TDD/BDD, if you are new to testing I highly suggest grabbing Roy Osherove’s book on Unit Testing.

Where to download and setup the Jasmine Framework:

  1. Jasmine on gitHub
  2. Once you clone the repo there will be a SpecRunner.html file, this is where you will reference your Source files and Tests and will see the results.
  3. In the HEAD tag of the SpecRunner.html file you find the jasmine-html.js script file, after this script you should list all the source files you would like to test and then the tests for those source files.

Getting Started:

Lets create a basic object:

function Customer() {
  this.customerName = '';
};

Save this file as customer.js and link this file in your SpecRunner.html just after the jasmine framework file mentioned in the introduction. Now we will create our first test for our object. Create a new .js file called customer_specs.js and enter the following:

describe("Customer Object Tests", function(){
  var customerTest = new Customer();
  
  it("should contain a customerName object", function(){
    expect(customerTest.customerName).toBeDefined();
  });
};

Once you have saved your changes and linked the customer_spec.js file after the customer.js file in the SpecRunner.html file, load the .html file in your browser of choice. Here you can see that the tests are grouped by the “describe” blocks used by Jasmine. You can nest multiple “describe” blocks to keep your tests organised.

Looking at the test itself lets break it down:

  1. All tests make use of the it() function. This takes 2 arguments
  2. Argument 1 is a string, and this string describes the test. In the case above, we want to ensure that the customer object should contain a customerName object.
  3. The second argument is a function call that contains the code to perform the test.
  4. In most testing frameworks your test would end with an “assert” in some format. The “assert” in the Jasmine framework is the “expect” function. A callback is passed into the “expect” function.
  5. A matcher is then applied to the result of the “expect”.
  6. In this case with are using the “toBeDefined” matcher that will ensure that the callback passed to the expect is defined.

Other basic matches for standard values include:

expect(x).toEqual(y); compares objects or primitives x and y and passes if they are equivalent

expect(x).toBe(y); compares objects or primitives x and y and passes if they are the same object

expect(x).toMatch(pattern); compares x to string or regular expression pattern and passes if they match

expect(x).toBeDefined(); passes if x is not undefined

expect(x).toBeUndefined(); passes if x is undefined

expect(x).toBeNull(); passes if x is null

expect(x).toBeTruthy(); passes if x evaluates to true

expect(x).toBeFalsy(); passes if x evaluates to false

expect(x).toContain(y); passes if array or string x contains y

expect(x).toBeLessThan(y); passes if x is less than y

expect(x).toBeGreaterThan(y); passes if x is greater than y

expect(fn).toThrow(e); passes if function fn throws exception e when executed

Should you want to invert any of these matchers you simply prefix the matcher with “.not”. Instead of calling expect(x).toEqual(‘xyz’), you would call expect(x).not.toEqual(‘xyz’);

Finishing off:

This is just a very basic intro to the Jasmine framework. Next up I will discuss writing custom matchers. Below are some links you may want to check out including the files from a demo I recently gave.

Links:

  1. Jasmine Documentation
  2. Demo Files from a talk I gave recently
June92011

Learn to read Documentation

Since joining my current company I have learnt arguably the most important lesson of my career. I have learnt how to read documentation, this sounds so obvious but it’s something I see so many developers not doing.

Read More

May12011

So why Tumblr? What happened to a custom blog engine?

So for the last 2-3 months I have been working on a customer blog engine powered by Ruby, Rails and MongoDB. 2-3 Months is a long time to work on something so exceptionally basic.

The Problem:

I work with web based technologies all day at work and the idea of coming home to work on more web based technologies is actually just plain boring. The second part of the problem is that I have been focussing on the final product. I have been focussing on all the features that I want to implement. The third part of my problem is that I have virtually zero design skills. I cannot stand working on a web application that doesn’t look good and so motivation levels have been low.

The Possible Solution:

Overcoming the first part of the problem is all down to just knuckling down and actually getting to work. The bigger part of my solution is to break down everything into minute details. Over the last few days I have been on leave I have continuous revised this list breaking down the last to the smallest possible set of units of work. Each evening I will only focus on a single CSS issue and a single “feature” issue.

So why tumblr?

Tumblr is a temporary solution in which I can start blogging again. Once my custom solution is up and running I can simply import my posts from Tumblr into the new engine. Currently I do not have a set time frame since I no longer want to feel constrained by this project. The project should be fun and should be motivating me to learn more about Ruby and Rails and so I will return to having fun instead of pressuring myself.

January142011
November192010
“Sometimes a task doesn’t require your enthusiasm, it requires you to shut your mouth and do your job.” StevenMcD
November172010
“No one will ever be satisfied with what you do, with time they will expect more from you. This seems to be human nature, this also seems to be severely flawed” StevenMcD
11AM

Ruby on Rails developers - Joke

Just inside the gates of heaven, St. Peter sits at a desk checking people in. 

Peter: “Welcome to heaven. Programming language?” 

The man at the front of the line says, “Smalltalk.” 

Glancing at his clipboard, Peter says, “Room 33. Be very quiet as you 
pass Room Six.” 

The process repeats itself with the next person in line: 

Peter: “Welcome to heaven. Programming language?” 

Person #2: “Common Lisp.” 

Peter: “Room 17. Be very quiet as you pass Room Six.” 

The next person moves to the front of the line with a look of 
curiosity on her face. 

Peter: “Welcome to heaven. Programming language?” 

Person #3: “Python.” 

Peter: “Room 54. Be very quiet as you pass Room Six.” 

Person #3: “Why do you keep telling us to be quiet as we pass Room Six?” 

Peter: “Because the Ruby on Rails People are in Room Six, and they 
think they’re the only ones here.” 

humor 

June72010

Pitch Perfect. Even Simon is amazed by this little girl. Pure innocence.

music 

May252010
R.I.P Paul Gray. May the metal go with you, where ever you go.

R.I.P Paul Gray. May the metal go with you, where ever you go.

← Older entries Page 1 of 2