FitNesse Search & Replace

Uncle Bob announced today the release of FitNesse 20100303. Please grab it from the FitNesse download page. Since I added a new function which I thought over the course of nearly the whole last year and which is not yet finished, let me try to introduce the idea I have with it.

The present

The feature I’m talking about is not very complex nor is it complicated. It’s a feature I was missing over the course of the last two years while working with FitNesse. It’s a simple regular expression based search & replace functionality. Well, thus far there has been a the possibility to do search & replace on the shell-level with regular tools like sed and others. So, what’s new about this? Well, at work we use perforce for revision control. Some while back I wrote a PerforceCmSystem for FitNesse to deal with opening files for writing, for add and for delete. Thereby we can store the FitNesse pages in our revision control system with real ease. Now, I get back to the need for a search & replace function inside FitNesse itself. On the shell we would need to check out each page to change, make the change, then check the changes back in. With search & replace I can now simply hit a button on a page after filling in stuff in two text fields, and then submit the changes made to the pages by FitNesse itself. Version control is done by FitNesse, as well as the change necessary. Great thing!

How does it work?

First of all consider the function to be experimental. There are no checks for consistency between the regular expression and the replacements. This made the implementation really easy, and there already some changes waiting for the next release to implement. That said, you will find two new text boxes on the refactoring page. In the first box you can enter regular expressions according to the description from the Java API documentation. You may use grouping enclosed with (), etc. On the second box you can insert a replacement, maybe referencing groups from the pattern in the first box. So, let’s walk through an example. Say, I have got some test pages, where Peter is used as the standard user. Now, for equality reasons, I would like to change Peter to Petra. Then I enter Peter in the first box, and Petra in the second one, hit the search & replace button, and watch the result popping up.

There is one thing you have to keep in mind. Search & replace works on the page hierarchy level. This means that any page below the page where the refactoring button was pressed, search & replace will work on. On any level above that nothing will be changed. So, you have to be aware where you start your replacements.

The future

There a two main streams for the future on FitNesse and refactorings. First, search & replace needs further evaluation and needs to grow. Uncle Bob suggested to include a two page flow, where I get all the results from the search on a second page and can choose among the replacements I would like to have – or as it is today, to replace all. This is already planned on pivotal tracker, and I would be happy to learn something new while implementing this.

Second thing I see coming is a refactoring for the tables inside FitNesse. With the underlying classes it’s very easy to write a custom refactoring for FitNesse that exchanges for example two columns from a table. For the following table:

a b c
asdf qwer yxcv

I might provide to exchange column a and c, resulting in the following table:

c b a
yxcv qwer asdf

So, I would be happy on feedback on this feature and the future of refactoring in tools like FitNesse. The column replacer would be a neat feature, but I hope it’s just the beginning of a refactoring tool for wiki-pages. So, please leave me a comment what you think about it, or how you think search & replace might be used as well.

  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Twitter
  • LinkedIn
  • Google Bookmarks

3 thoughts on “FitNesse Search & Replace”

  1. Markus, are you aware of ReFit ( Have a look at it and tell me if you think it would make sense to integrate (the valuable parts of) it into FitNesse. The fundamental difference to your approach is that ReFit builds a domain model of FitNesse pages, refactors the domain model first and commits the changes to the file system in a second step.

    1. That’s interesting, Johannes. The idea with the domain model is very interesting. I have to think a bit over this, but I already see some ways to incorporate it into FitNesse itself. I’ll take a closer look into ReFit before working further on the refactorings. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *