exceptionz

Thoughts on Technology, Methodology and Programming.

Archive for the ‘Development’ Category

Run gem install behind a firewall in Windows

Posted by Marcus Wyatt on 18 March 2008

I’m contracting at a client running a Novell network and wanted to create some small little ruby scripts to automate some tasks for me. But I ran into problems using gem install behind their firewall. I’m getting the following error:

ERROR: While executing gem … (Gem::RemoteSourceException) HTTP Response 407

Here is the steps I followed to get gem install working on my windows xp machine in painstaking detail: 🙂

Firstly we need to set the HTTP_PROXY environment variable. I’ve played around with different options, using uid and pwd and other suggestions, but all I needed was the following:

  1. On the desktop right click the ‘My Computer’ icon and select properties.
  2. Now you can either add the HTTP_PROXY variable to the ‘User’ or the ‘System’ variables by clicking the ‘New’ button.
  3. Within the new system variable dialog, specify ’HTTP_PROXY’ as the variable name and in the value area a url in the following format – http://%5Bproxy_ip%5D:%5Bproxy_port%5D – i.e. http://127.168.1.3:5865

Next we install the Ruby Win32 SSPI which gives ruby the ability to authenticate with ISA natively. We need this library because as far as I understand, it patches the Open-uri library because of some incompatibilities with windows. Anyways, follow the following steps to get it working:

  1. Download rubysspi from the Ruby Win32 SSPI project page(also available as gem install rubysspi but that doesn’t help much, does it?)
  2. Install the gem locally using the following command: gem install [local_path_to_gem]\rubysspi-1.2.3.gem i.e. C:\gems\rubysspi-1.2.3.gem
  3. Now copy the spa.rb file from the gem install directory and paste it in the site-ruby directory. i.e. If ruby is installed in C:\ruby, then the paths should be:
    • origin path – C:\ruby\lib\ruby\gems\1.8\gems\rubysspi-1.2.3\spa.rb
    • destination path – C:\ruby\lib\ruby\site_ruby\spa.rb
  4. Find gem.bat in your ruby bin directory (C:\ruby\bin) and replace the last line (i.e. "%~d0%~p0ruby" -x "%~f0" %*) with the following line – @"ruby" -rspa "c:\ruby\bin\gem" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. Test you can access the remote ruby gems by executing the following command: gem list rails -r
  6. You should see similar output as shown above.

Now we can work again without any issues when trying to install or update gems.

Enjoy!!!

Technorati Tags: , ,

Advertisements

Posted in Development, Rails, Ruby, Software, Tools, XP | 36 Comments »

You can now build the source code in either VS2k5 or VS2k8

Posted by Marcus Wyatt on 11 March 2008

I’ve updated the source code to include some conditional compilation directives to support different Visual Studio IDE versions. So if you are still stuck in VS2005 land, you can now build the source and be able to take advantage of the new features that Owen Evans added.

These include the new attributes (Context, BeforeAll, BeforeEach, AfterAll, AfterEach) and new functionality like Collection.Contains#WithProperty. If you lucky to be using VS2008 you’ll have new functionality that allows you to pass lambda’s. For more information look at http://bgeek.net/2008/02/14/nspecify-rspec-well-closer-anyway/

Owen also added a new library called NSpecify.Framework.Extensions. This gives you some extension methods that you can use to specify your expectations directly on the object under test.

i.e. newDeveloper.Surname.Must().Equal(“Evans”);

Nice hey!

Posted in BDD, Development, OO, Software, TDD, Tools | Tagged: , , | Leave a Comment »

How to solve a domain object problem with Object Orientation.

Posted by Marcus Wyatt on 6 November 2007

Who cares about Domain Rules?

This article shows how you can solve a domain problem, with several different solutions. You’ll find six different solutions where I have explored each solution using exactly the same problem. I’ve always said that there is no wrong way to develop code. What do I mean by that? Well, you could solve a problem in several ways.

read more | digg story

Posted in Development, OO | Tagged: , | Leave a Comment »

Ruby, Rails, Rails Plugin

Posted by Marcus Wyatt on 6 November 2007

Ruby

Rails

Rails Plugin

Technorati Tags: , ,

Powered by ScribeFire.

Posted in Development, Rails, Rails Plugins, Ruby | Leave a Comment »

Ruby, Rails, Rails Plugin, JavaScript, CSS, TextMate

Posted by Marcus Wyatt on 5 November 2007

Ruby

Rails

Rails Plugin

JavaScript & CSS

TextMate

Technorati Tags: , , , , ,

Powered by ScribeFire.

Posted in CSS, Development, JavaScript, Rails, Rails Plugins, Ruby, TextMate | 1 Comment »

Links for 1 November 2007 (Rails, JavaScript, HTML, Photoshop, CSS, Microformats, Macs, Freelancing)

Posted by Marcus Wyatt on 1 November 2007

Rails

JavaScript

HTML

Photoshop

CSS

Microformats

Macs

Freelancing

Technorati Tags: , , , , , , ,

Powered by ScribeFire.

Posted in CSS, Development, JavaScript, RoR, Software | 2 Comments »

Introduce Behavior-Driven Development without much resistance…

Posted by Marcus Wyatt on 17 September 2007

Within the .NET community the idea of test-driven development is starting to become common knowledge. This doesn’t necessarily mean that it is practiced. I believe that although many people find the idea of TDD very easy to grok, they find the implementation of TDD very hard and many revert back to their old ways of working soon after trying TDD.

So why is TDD so hard?

I don’t think that it is only one aspect that makes TDD hard, but a culmination of many factors together. Firstly, you should have a good understanding of OO. You need to understand how to de-couple your objects. How to isolate the class under test by mocking or stubbing the external dependencies. If you are one of those developers that write huge methods with multiple lines of code, then I’m afraid you are not going to be able to practice TDD.

There is also old habits. It is hard to kick old habits, like I can profess when I stopped smoking a couple of years ago. But with perseverance you can loose those old habits.

The other problem is of course the vocabulary you use during a TDD session. All the words you work with has their grounding in validation. i.e. Test, TestFixture, Assert, etc. This makes it quite hard to focus your attention on what you are really doing, specifying the functionality (behavior) of the object. It’s quite simple to see that if I talk about writing a test for the Order object and I assert that the order should be filled, that the language I use isn’t very helpful in making me think about the behavior of the Order. But if I’m writing a specification for the order to specify that an order can be filled, then suddenly my language doesn’t create a barrier.

So what do you mean by ‘introduce BDD without much resistance’?

Wel, in .NET you have the ability to alias and that ability is what I’m using to create an easy why to change the nomenclature of your code. Here is a example of what I’m talking about:

 

    3 using NSpecify.Framework;

    4

    5 using Rhino.Mocks;

    6

    7 using SetupResources = NUnit.Framework.SetUpAttribute;

    8 using DestroyResources = NUnit.Framework.TearDownAttribute;

    9 using Functionality = NUnit.Framework.TestFixtureAttribute;

   10 using Specification = NUnit.Framework.TestAttribute;

   11

   12 [Functionality(Description=“Describe the functionality of the order domain object.”)]

   13 public class OrderFunctionality

   14 {

   15     private MockRepository mockery;

   16     private IWarehouse warehouse;

   17

   18     [SetupResources]

   19     public void BeforeSpecificationExecute()

   20     {

   21         mockery = new MockRepository();

   22

   23         // setup the warehouse mock

   24         warehouse = mockery.CreateMock<IWarehouse>();

   25     }

   26

   27     [DestroyResources]

   28     public void AfterSpecificationExecuted()

   29     {

   30         mockery.VerifyAll();

   31     }

   32

   33     [Specification(Description=“Should not be able to fulfill order.”)]

   34     public void ShouldNotBeAbleToFulfillOrder()

   35     {

   36         string product = “Harry Potter and the Deathly Hollows”;

   37

   38         Order order = new Order(product, 50);

   39

   40         mockery.Record();

   41

   42         Expect.Call(warehouse.GetInventory(product)).Return(10);

   43

   44         mockery.ReplayAll();

   45

   46         order.Fill(warehouse);

   47

   48         Specify.That(order.IsFilled).Must.Equals(false);

   49     }

   50     [Specification(Description = “Should be able to fulfill order successful.”)]

   51     public void ShouldBeAbleToFulfillOrder()

   52     {

   53         string product = “Harry Potter and the Order of the Phoenix”;

   54

   55         Order order = new Order(product, 50);

   56

   57         mockery.Record();

   58

   59         Expect.Call(warehouse.GetInventory(product)).Return(61);

   60

   61         mockery.ReplayAll();

   62

   63         order.Fill(warehouse);

   64

   65         Specify.That(order.IsFilled).Must.Equals(false);

   66     }

   67 }

As you can see from reading the code snippet above, by using aliasing we are able to change the language we use. The cool thing about aliasing the NUnit attributes, is that your current build script or the tools you use to run your tests would still work effortlessly. But, now we are reading and thinking in terms of specifications and not tests. Cool Hey!

If you are wondering how I’m able to write Specify.That then you should check out NSpecify.

Technorati Tags: ,

Powered by ScribeFire.

Posted in BDD, Development, OO, TDD | 1 Comment »

Ruby in Steel Goodness

Posted by Marcus Wyatt on 20 June 2007

I’ve had a play with Ruby in Steel for Visual Studio 2005 when Sapphire Steel released the first Developer edition about a year ago. The first version on my system was clunky and painfully slow. The Ruby intellisense was slow and overall the experience was not great.

Well, why would you tell this to me know?

Because, earlier this week my eye caught a post about Visual Ruby in my aggregator. So I browsed over to the post and then got reminded about Ruby in Steel. So I decided to give it another try. Wow, what an improvement.

The debugging features are just brilliant. So seamless, you would think you’re working within a language like C#.

The intellisense is crisp and rdoc information is displayed where available:

image

The following Intellisense features for Ruby source files are implemented:

  • Member Completion Lists
  • Keyword Completion Lists
  • Variable Completion Lists
  • Quick Info Tooltips
  • Parameter Info Tooltips

You also have the Snippets features of visual studio for template functionality.

image

Another cool feature is the Ruby Explorer which is a class browsing tool which can be used to view an alphabetical outline of Ruby classes and methods.

image

All in all I’m really impressed by the progress the tool made since the version 1.0 release a couple of months ago. I’m seriously considering maybe to invest in a license for the tool. But I think they should seriously consider the freelance developer out there. When ReSharper announced their personal license I was really excited about the move and yes, I did buy a personal license. Hopefully the Sapphire Steel guys would consider something similar…

If you are a  .NET developer for food and a budding RoR developer for fun and don’t have that flash MacBook Pro yet. Then maybe Ruby in Steel is just what you’d need.

del.icio.us Tags: , , ,

Posted in Development, RoR, Software | Leave a Comment »

Resharper 3.0 Member Re-Ordering Settings

Posted by Marcus Wyatt on 10 June 2007

In ReSharper 3.0 you now have the ability to specify how the Reformat action (Shortcut: Ctrl+Alt+F) should order the members within your code file.

image

The re-ordering feature is very nice if you want to adhere to a coding standard. e.g. Castle Project Coding Standards. Below is a breakdown of how ReSharper 3.0 would structure your code if you use the Re-order settings file:

  1. Every section is sorted by Access i.e. public, protected, internal, private
  2. Sections from top to bottom:
    1. Delegates
    2. Enums
    3. Constants
    4. Static & Readonly Fields
    5. Fields
    6. Constructors (Static then Instance)
    7. Destructors
    8. Instance Indexers (Sorted by Abstract, Virtual, Override)
    9. Instance Properties (Sorted by Abstract, Virtual, Override)
    10. Instance Methods (Sorted by Abstract, Virtual, Override)
    11. Event Handling Methods
    12. Events Declarations
    13. Operators
    14. Interface Implementations
    15. Class Indexers (Sorted by Abstract, Virtual, Override)
    16. Class Properties (Sorted by Abstract, Virtual, Override)
    17. Class Methods (Sorted by Abstract, Virtual, Override)
    18. All other members
    19. Nested Types

I thought the ReSharper 3.0 & Castle community might find the re-order settings file I created helpful. 

To add the settings you should open the Type Member Layout section of the ReSharper 3.0 beta options screen:

image

And then Copy the following XML into the Custom Patterns box:

<?xml version="1.0" encoding="utf-8" ?>
<Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns">

  <!--Do not reorder COM interfaces-->
  <Pattern>
    <Match>
      <And Weight="100">
        <Kind Is="interface"/>
        <HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/>
      </And>
    </Match>
  </Pattern>

  <!--Special formatting of NUnit test fixture-->
  <Pattern RemoveAllRegions="true">
    <Match>
      <And Weight="100">
        <Kind Is="class"/>
        <HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/>
      </And>
    </Match>

    <!--Setup/Teardow-->
    <Entry>
      <Match>
        <And>
          <Kind Is="method"/>
          <Or>
            <HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/>
            <HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/>
            <HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/>
            <HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/>
          </Or>
        </And>
      </Match>
      <Group Region="Setup/Teardown"/>
    </Entry>

    <!--All other members-->
    <Entry/>

    <!--Test methods-->
    <Entry>
      <Match>
        <And Weight="100">
          <Kind Is="method"/>
          <HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/>
        </And>
      </Match>
      <Sort>
        <Name/>
      </Sort>
    </Entry>
  </Pattern>

  <!--Default pattern-->
  <Pattern RemoveAllRegions="true">

    <!--delegate-->
    <Entry>
      <Match>
        <And Weight="100">
          <Access Is="public"/>
          <Kind Is="delegate"/>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Delegates"/>
    </Entry>

    <!--enums-->
    <Entry>
      <Match>
        <Kind Is="enum"/>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Enums"/>
    </Entry>

    <!--constants-->
    <Entry>
      <Match>
        <Kind Is="constant"/>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Constants"/>
    </Entry>

    <!--static and readonly fields-->
    <Entry>
      <Match>
        <And>
          <Kind Is="field"/>
          <Or>
            <Static/>
            <Readonly/>
          </Or>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Readonly &amp; Static Fields"/>
    </Entry>

    <!--fields-->
    <Entry>
      <Match>
        <Kind Is="field"/>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Fields"/>
    </Entry>

    <!--Constructors. Place static one first-->
    <Entry>
      <Match>
        <Kind Is="constructor"/>
      </Match>
      <Sort>
        <Static/>
        <Access Order="public protected internal private" />
      </Sort>
      <Group Region="C'tors"/>
    </Entry>

    <!--Destructors. Place static one first-->
    <Entry>
      <Match>
        <Kind Is="destructor"/>
      </Match>
      <Sort>
        <Static/>
        <Access Order="public protected internal private" />
      </Sort>
      <Group Region="Destructors"/>
    </Entry>

    <!--Instance indexers-->
    <Entry>
      <Match>
        <And>
          <Kind Is="indexer"/>
          <Not>
            <Static/>
          </Not>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Instance Indexers"/>
    </Entry>

    <!--instance properties-->
    <Entry>
      <Match>
        <And>
          <Kind Is="property"/>
          <Not>
            <Static/>
          </Not>
          <Not>
            <Kind Is="indexer"/>
          </Not>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Instance Properties"/>
    </Entry>

    <!--Methods-->
    <Entry>
      <Match>
        <And>
          <Kind Is="method"/>
          <Not>
            <Static/>
          </Not>
          <Not>
            <HandlesEvent />
          </Not>
          <Not>
            <Kind Is="destructor"/>
          </Not>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Instance Methods"/>
    </Entry>

    <!--Event Handling-->
    <Entry>
      <Match>
        <HandlesEvent />
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Event Handling"/>
    </Entry>

    <!-- event -->
    <Entry>
      <Match>
        <Kind Is="event"/>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Event Declarations"/>
    </Entry>

    <!-- operator -->
    <Entry>
      <Match>
        <Kind Is="operator"/>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Name/>
      </Sort>
      <Group Region="Operators"/>
    </Entry>

    <!--interface implementations-->
    <Entry>
      <Match>
        <And Weight="100">
          <Kind Is="member"/>
          <ImplementsInterface/>
        </And>
      </Match>
      <Sort>
        <ImplementsInterface Immediate="true"/>
      </Sort>
      <Group>
        <ImplementsInterface Immediate="true" Region="${ImplementsInterface} Members"/>
      </Group>
    </Entry>

    <!--Class indexers-->
    <Entry>
      <Match>
        <And>
          <Kind Is="indexer"/>
          <Static/>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Class Indexers"/>
    </Entry>

    <!--Class properties-->
    <Entry>
      <Match>
        <And>
          <Kind Is="property"/>
          <Static/>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Class Properties"/>
    </Entry>

    <!--Class Methods-->
    <Entry>
      <Match>
        <And>
          <Kind Is="method"/>
          <Static/>
        </And>
      </Match>
      <Sort>
        <Access Order="public protected internal private" />
        <Abstract/>
        <Virtual/>
        <Override/>
        <Name/>
      </Sort>
      <Group Region="Class Methods"/>
    </Entry>

    <!--all other members-->
    <Entry/>

    <!--nested types-->
    <Entry>
      <Match>
        <Kind Is="type"/>
      </Match>
      <Sort>
        <Name/>
      </Sort>
      <Group>
        <Name Region="Nested type: ${Name}"/>
      </Group>
    </Entry>
  </Pattern>

</Patterns>

Enjoy!

del.icio.us Tags: , ,

Posted in Development, Refactoring, Software | 8 Comments »

Inversion of Control tutorial

Posted by Marcus Wyatt on 2 May 2007

I’ve found these great tutorials on IoC written by Alex Henderson.

Part 1 – Simple configuration
Part 2 – Array Configuration
Part 3 – Dictionary configuration
Part 4 – Switching configurations
Part 5 – Configuration parameters
Part 6 – Switching between lifestyles
Part 7 – Switching implementations
Part 8 – Referencing implementations by key
Part 9 – Constructor Injection
Part 10 – Setter Injection
Part 11 – Factories
Part 12 – Decorators
Part 13 – Injecting Service Arrays
Part 14 – Startable Facility

Great job!

Technorati Tags: ,

Powered by ScribeFire.

Posted in Development, OO, Software | 1 Comment »