in

 

AgileJoe

Answering all world issues with, "...it depends..."

February 2008 - Posts

  • Using Context as an example group in rSpec

    If you try to do the following in rSpec you will receive a (nil:NilClass) error on the inner context in the 'before' statement when it tries to use @user.

    describe User do
    
        before(:each) do
            @user = User.new
        end
    
        context "(adding assigned role)" do
            before(:each) do
                @user.assign_role("Manager")
            end
    
            specify "should be in any roles assigned to it" do
                @user.should be_in_role("Manager")
            end
           
            specify "should not be in any role not assigned to it" do
                @user.should_not be_in_role("unassigned role")
            end
        end
       
        context "(adding assigned group)" do
    
        end
    end

    This perplexed me because the rDoc indicates that [context] method is an alias for [describe] method. Turns out there are two different places where describe is defined. One in main (the outermost layer) and one inside an ExampleGroup. The one in the example group isn't aliased.

    So to solve that for the short term in your own code you can do this in your spec_helper.rb file:

    module Spec::Example::ExampleGroupMethods
     alias :context :describe
    end

    In your spec file add the following to the header assuming the spec_helper.rb is in the same directory:

    require File.dirname(__FILE__) + '/spec_helper'

    Now everything should work out great!  BDD sweetness!  Here is the final user_spec.rb

    require 'user'
    require File.dirname(__FILE__) + '/spec_helper'
    
    describe User do
        
        before(:each) do
            @user = User.new
        end
    
        context "(adding assigned role)" do
            before(:each) do
                @user.assign_role("Manager")
            end
    
            specify do
                @user.should be_in_role("Manager")
            end
            
            specify do 
                @user.should_not be_in_role("unassigned role")
            end
        end 
        
        describe "(adding assigned group)" do
        end 
    end

     

    Happy coding!

    Posted Feb 27 2008, 04:22 PM by Joe Ocampo with 2 comment(s)
    Filed under: ,
  • !!!!Please update your LOSTECHIES RSS FEED!!!!

    We have recently updated our main feed to feedburner.  Everyone please update your RSS readers to point too.

    http://feeds.feedburner.com/lostechies

    Thank you, you may now continue with your regularly scheduled reading.

  • Updates to NBehave

    What happened to NSpec?

    I am not sure if all of you know but the NBehave project consolidated with the NSpec project a while back, since then we have been pretty silent about what we are doing because we wanted to give the community something they could simply drop in and not be to evasive in its implementation. Meaning we didn’t want you to have to learn how to use yet another runner.

    What we decided is that NSpec did a lot of cool things but at its heart was an assertion engine. We contemplated if we really wanted to go down the path of creating a whole new assertion engine. This is where Andrew Stopford’s and Jeff Brown’s MbUnit 3.0 Gallio engine come in.

     

    “The Gallio platform is an open, extensible, and neutral system that provides a common object model, runtime services and tools (such as test runners) that may be leveraged by any number of test frameworks. In this vision of the world, MbUnit v3 itself is simply another test framework plugin with the same status as any other.”

    NBehave will utilize the Gallio extensible test framework and employ as many of the BDD idioms as we can manage to squeeze in.

    This will enable us to offer:

    • To use any of the 7 current Gallio test runners, including console, GUI, MSBuild, NAnt, PowerShell, ReSharper and TD.Net plus any new ones that are developed.
    • CCNet integration and most anything else that's built around Gallio
    • NBehave with Gallio as a bundle.

    Pretty cool right? Well as you can imagine this has been ongoing trial an error but the good part is we are working with the Gallio dudes to get something out there.

    So does that mean I have to wait to use BDD then? No…

    We wanted to give you all something now.

    One of the more important constructs of BDD is that we are now specifying how our code should behave under a governed context. Whether that context is story governed or system governed is particular to the situation that is eliciting the invocation. Laymen response it is not just about stories and acceptance testing.

    BDD is about creating a reentrant code base that can be understood by development teams working together to create great software. You should be able to perform a cursory glance at you specifications and understand intentions and expected behavior. The difficult part is that this is going to require the same type of self discipline that TDD fostered.

    So how do you take advantage of this now?

    Well the current repository on Google Code has several features that we think the community can take advantage of now. Thanks go out to David Laribee and JP Boodhoo for the help with the base spec fixture.

    Here is a list of some of the features we have completed and are working towards.

    • · NUnitSpecBase – Done
    • · MbUnitSpecBase - Done
    • · NUnit assertion extensions - Done
    • · MbUnit assertion extensions - Done
    • · Automocking Container - Done
    • · Create MSTest assertion extensions (April 1st)
    • · Create xUnit assertion extensions (April 1st)
    • · TestDriven.NET integration (April 1st)
    • · XML output for stories (April 1st)
    • · XSLT for XML story runner output (April 1st)

    So how do I use these new features?

    • 1. Download the latest trunk from Google Code or wait till April 1st for the official build
    • 2. Execute the go.bat
    • 3. Now create a new project and reference the following dll’s from the build folder (this is assuming you are using NUnit)
      • a. Castle.Core
      • b. Castle.DynamicProxy
      • c. Castle.DynamicProxy2
      • d. Castle.MicroKernal
      • e. Castle.Windsor
      • f. NBehave.Spec.Framework
      • g. NBehave.Spec.NUnit
      • h. NUnit.Framework
      • i. Rhino.Mocks
      • j. …The kitchen sink!

    As you can see there are a lot of dependencies but for the most part they are everything you would need to have the optimal BDD experience.

    At this point I am really jealous of Gem! :-)

    Here is how you would setup a basic specification fixture.

    Pseudo DSL:

    these specs are concerning this [Type]
        when this [type] is in this [context]
            then [specify] that it [should behave] this way

    The first thing is to setup the using aliases.

    using Context = NUnit.Framework.TestFixtureAttribute;
    using Specification = NUnit.Framework.TestAttribute;
    using Concerning = NUnit.Framework.CategoryAttribute;
    

    Then use the namespace to define the concerning type:

    namespace MathFlash.Core.EquationGenerator_Specs

    In the case above the specs in this file are going to be concerning EquationGenerator_Specs.

    Now let’s define our first context.

    [Context, Concerning("EquationGenerator")]
    public class When_initializing_the_EquationGenerator_with_one_and_five : NUnitSpecBase

    As you can see we have defined a class decorated with a Context attribute and a Concerning attribute. We have also inherited from the NUnitSpecBase. The name of the class is defining the context that will govern the expected behavior that we will assert on later.

    Next we will define our first specification.

    [Specification]
    public void Should_generate_equations_where_the_left_hand_side_is_greater_than_or_equal_to_the_lower_bound()
    

    So you have defined a context and specified expected behavior. What is so important about the NUnitSpecBase. Well for one it abstracts the use of the automocking container (I will have a post on that in the next couple of days). It also has several new method conventions that have their roots in rSpec.

    protected override void Before_each_spec()

    This method will be called before_each_spec similar to the SetUpAttribute.

    protected override void After_each_spec()

    This method will be called after_each_spec similar to the TearDownAttribute.

    Last but not least are the NUnit extension methods. You have two options. You can use the standard CamelCase notation or you can use to more readable underscore notation. For example:

    equation.LeftHandSide.ShouldBeGreaterThanOrEqualTo(_lowerBound);

    or

    equation.LeftHandSide.should_be_greater_than_or_equal_to(_lowerBound);

    Why did we give you both? Because we just couldn’t decide on which one to use just yet. I am sure in the end we will decide on one but for now you will have both options. If anything it gets you ready for rSpec once IronRuby is baked!

    This is only the beginning. We have a lot more planned for future releases and Gallio will open the door for even more exciting possibilities.

    For reference here are all the specs.

    using System.Collections.Generic;
    using MathFlash.Core.Domain;
    using NBehave.Spec.NUnit;
    using Context = NUnit.Framework.TestFixtureAttribute;
    using Specification = NUnit.Framework.TestAttribute;
    
    namespace MathFlash.Core.EquationGenerator_Specs
    {
        [Context]
        public class When_initializing_the_EquationGenerator_with_one_and_five : NUnitSpecBase
        {
            private EquationGenerator _generator;
            private int _lowerBound = 1;
            private int _upperBound = 5;
    
            protected override void Before_each_spec()
            {
                _generator = new EquationGenerator(_lowerBound, _upperBound);
            }
    
            [Specification]
            public void Should_generate_equations_where_the_left_hand_side_is_greater_than_or_equal_to_the_lower_bound()
            {
                foreach (var equation in _generator.GenerateEquations())
                {
                    equation.LeftHandSide.should_be_greater_than_or_equal_to(_lowerBound);
                }
            }
    
            [Specification]
            public void Should_generate_equations_where_the_left_hand_side_is_less_than_or_equal_to_the_upper_bound()
            {
                foreach (var equation in _generator.GenerateEquations())
                {
                    equation.LeftHandSide.should_be_less_than_or_equal_to(_upperBound);
                }
            }
    
            [Specification]
            public void Should_generate_equations_where_the_right_hand_side_is_greater_than_or_equal_to_the_lower_bound()
            {
                foreach (var equation in _generator.GenerateEquations())
                {
                    equation.RightHandSide.should_be_greater_than_or_equal_to(_lowerBound);
                }
            }
    
            [Specification]
            public void Should_generate_equations_where_the_right_hand_side_is_less_than_or_equal_to_the_upper_bound()
            {
                foreach (var equation in _generator.GenerateEquations())
                {
                    equation.RightHandSide.should_be_less_than_or_equal_to(_upperBound);
                }
            }
    
            [Specification]
            public void Should_generate_twenty_five_equations()
            {
                var equations = _generator.GenerateEquations();
    
                equations.Count.should_equal(25);
            }
        }
    }
  • LosTechies welcomes Eric Hexter!!!!

    What more could be said about the MVCContrib coordinator extraordinaire, Eric Hexter!

    How is that for a build up?  :-)

    Many welcomes to Eric Hexter for joining us here at LosTechies.

    We are pleased to have him on board and know his passion will help other developers to find answers to questions or figure out new technologies as all the LosTechies bloggers strive to do.

    Welcome Eric!

  • Found a new APM Tool

    Out browsing some mailing list today and came across this really nice Agile Project Management tool, Acunote.

    What is Acunote...

    Acunote is an Agile project management tool.
    It is built on the innovative lightweight Scrum process and is focused on the day-to-day steps needed to achieve the goal.

    They did a really nice job, reminds me of BaseCamp. It supports SVN, Code Inspection on check in and best of all it is free for a team of 5 developers. It also can import the list of bugs from Bugzilla, Mantis, Trac and JIRA.

    Let me put this out there that I haven't used this product on a project yet.  I am just letting you know my initial impression.  Anyone else used it yet?

  • Consultant Frustration Coefficient

    Talking to Joey B this evening about creating a tool that would measure how frustrated you may become with wanting to mentor a team on Agile development practices. I am calling this the Consultant Frustration Coefficient.

    What you would do is hand out a short questionnaire that would ask varying questions to assess the client’s value system and the staff’s literacy level as it relates to development pragmatic practices.

    The result would look something like this:

    • Code: Staff shows a firm understanding of claiming to know OOP however certain frequencies indicate that staff view OOP as COBOL syntax with many function libs. Caution should be taken.
    • Design Patterns: Staff shows understanding of design patterns relating to UML documentation. All indicators are pointing towards an automated code creation and wizard driven setup culture. Caution should be taken.
    • TDD: Staff understands what Unit Testing is but does not understand why they should write test that QA should be writing. They do not want to use open source libraries. Critical deal breaker here! Extreme Caution!
    • Paired Programming: Staff indicators show extreme frustration with one another and would rather work alone in their cubicles on development task. Caution should be taken.
    • CI: Management indicators show reluctance to increased time spent outside of coding and server setup. Good luck getting it passed management. Staff may show resistance. Caution should be taken.
    • Agile: Staff has the probability of buying into it but management value system does not lend itself to embracing agile. Caution, you may be wasting your time.

    CFC Rating: This project will pose extreme challenges and frustration for you. But it looks like all of your other opportunities right now so go with it!

    Any other categories that we should collect? :-)

    Posted Feb 03 2008, 10:44 PM by Joe Ocampo with 6 comment(s)
    Filed under:
Copyright Los Techies 2007. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems