<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Mariusz Cieśla</title>
  <subtitle>UI Design and Front-End Development</subtitle>
  <id>http://mariusz.cc/</id>
  <link href="http://mariusz.cc/"/>
  <link href="http://mariusz.cc/feed.xml" rel="self"/>
  <updated>2012-01-14T00:00:00+01:00</updated>
  <author>
    <name>Mariusz Cieśla</name>
  </author>
  <entry>
    <title>Automated UI testing with Jasmine and Zombie</title>
    <link rel="alternate" href="/articles/2012/01/ui-testing-with-zombie.html"/>
    <id>/articles/2012/01/ui-testing-with-zombie.html</id>
    <published>2012-01-14T00:00:00+01:00</published>
    <updated>2012-01-14T00:00:00+01:00</updated>
    <author>
      <name>Mariusz Cieśla</name>
    </author>
    <summary type="html">&lt;p&gt;On my quest to be more able on the developer side of things, as well as my recently developed love to Node.js, I recently was looking for a good way to automate at least part of the user interface testing on a secret after-hours project. I don&amp;#39;t need anything fancier than simple &amp;quot;It works if there&amp;#39;s a button on the screen&amp;quot;, but I expect to have quite a few of small cases when the project grows. Looking through the tools I could use, I finally settled with &lt;a href="http://zombie.labnotes.org"&gt;Zombie&lt;/a&gt; as a headless browser and &lt;a href="http://pivotal.github.com/jasmine/"&gt;Jasmine&lt;/a&gt; as a way to describe test cases (I tried &lt;a href="http://vowsjs.org/"&gt;Vows&lt;/a&gt; as well and I might actually go with it, but my first spike was done using Jasmine), which is pretty useful, since you can use Jasmine or Vows for server-side Node.js tests as well.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;On my quest to be more able on the developer side of things, as well as my recently developed love to Node.js, I recently was looking for a good way to automate at least part of the user interface testing on a secret after-hours project. I don&amp;#39;t need anything fancier than simple &amp;quot;It works if there&amp;#39;s a button on the screen&amp;quot;, but I expect to have quite a few of small cases when the project grows. Looking through the tools I could use, I finally settled with &lt;a href="http://zombie.labnotes.org"&gt;Zombie&lt;/a&gt; as a headless browser and &lt;a href="http://pivotal.github.com/jasmine/"&gt;Jasmine&lt;/a&gt; as a way to describe test cases (I tried &lt;a href="http://vowsjs.org/"&gt;Vows&lt;/a&gt; as well and I might actually go with it, but my first spike was done using Jasmine), which is pretty useful, since you can use Jasmine or Vows for server-side Node.js tests as well.&lt;/p&gt;

&lt;h2&gt;Tools&lt;/h2&gt;

&lt;p&gt;To start doing automated UI testing using only JavaScript - or in my case CoffeeScript, which I find easier to maintain, but harder to debug at this point - you will need a certain set of tools, which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Node.js&lt;/strong&gt; - durr. Obviously. You can &lt;a href="http://nodejs.org/"&gt;get Node.js here&lt;/a&gt; or, if you&amp;#39;re using Mac OS X and Homebrew, simply &lt;code&gt;brew install node&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NPM&lt;/strong&gt; - the Node package manager, soon to be built in the Node core, making this step obsolete. For now, unless you&amp;#39;re from the future, you&amp;#39;ll need to run &lt;code&gt;curl http:&amp;#47;&amp;#47;npmjs.org&amp;#47;install.sh | sh&lt;/code&gt; to install NPM.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jasmine and Zombie&lt;/strong&gt; - with NPM, you simply run &lt;code&gt;npm install jasmine jasmine-node zombie&lt;/code&gt; and it should work.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Should.js&lt;/strong&gt; - if you find Jasmine matchers awkward, like I do, Should is an optional but useful step that makes them more humane.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Writing your first test&lt;/h2&gt;

&lt;p&gt;Assuming you&amp;#39;re all set up, it&amp;#39;s time to write your first test. In this example I will just use simple app that gets generated by &lt;a href="http://expressjs.com/"&gt;Express&lt;/a&gt;. Install Express with npm just like the tools above (&lt;code&gt;npm install express&lt;/code&gt;) and generate a simple app using &lt;code&gt;express zombie-test&lt;/code&gt;. This will create a directory named &lt;code&gt;zombie-test&lt;/code&gt; with a basic placeholder app running on Express.&lt;/p&gt;

&lt;p&gt;To create your first test using Jasmine, you need to create a directory named &lt;code&gt;spec&lt;/code&gt; inside your application directory that will hold all your tests. Inside that, create a simple test file - &lt;code&gt;front_page_spec.coffee&lt;/code&gt;. Pro tip: for Jasmine to actually take your files into consideration, they need to have the word &lt;code&gt;spec&lt;/code&gt; somewhere in the filename.&lt;/p&gt;

&lt;p&gt;Our test will check if document loads, the title of the page is &amp;quot;Express&amp;quot; and if the welcome paragraph says &amp;quot;Welcome to Express&amp;quot;, which it should. The test looks as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;describe &amp;quot;Front page&amp;quot;, -&amp;gt;
    should = require(&amp;quot;should&amp;quot;)
    zombie = require(&amp;quot;zombie&amp;quot;)
    browser = new zombie.Browser()

    url = &amp;quot;http:&amp;#47;&amp;#47;localhost:3000&amp;quot;

    # callback function
    whenLoaded = (callback) -&amp;gt;
        browser.visit url, (e, browser, status) -&amp;gt;
            callback.call()
        jasmine.asyncSpecWait()

    # should open properly
    it &amp;quot;should open&amp;quot;, -&amp;gt;
        whenLoaded -&amp;gt;
            browser.success.should.be.true
            jasmine.asyncSpecDone()

    # should have title set to &amp;quot;Express&amp;quot;
    it &amp;quot;should have title set to \&amp;quot;Express\&amp;quot;&amp;quot;, -&amp;gt;
        whenLoaded -&amp;gt;
            browser.text(&amp;quot;title&amp;quot;).should.be.ok
            browser.text(&amp;quot;title&amp;quot;).should.equal(&amp;quot;Express&amp;quot;)
            jasmine.asyncSpecDone()

    # should have a welcome paragraph
    it &amp;quot;should have a welcome paragraph&amp;quot;, -&amp;gt;
        whenLoaded -&amp;gt;
            browser.text(&amp;quot;body &amp;gt; p&amp;quot;).should.be.ok
            browser.text(&amp;quot;body &amp;gt; p&amp;quot;).should.equal(&amp;quot;Welcome to Express&amp;quot;)
            jasmine.asyncSpecDone()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#39;s it. I think code is pretty self explanatory, except maybe the callback function which is used to hold test from running until Zombie&amp;#39;s &lt;code&gt;browser.visit&lt;/code&gt; is complete. &lt;/p&gt;

&lt;p&gt;If you need any more help, I recommend you going through docs for &lt;a href="http://zombie.labnotes.org/api"&gt;Zombie&lt;/a&gt;, &lt;a href="https://github.com/pivotal/jasmine/wiki"&gt;Jasmine&lt;/a&gt; and &lt;a href="https://github.com/visionmedia/should.js/tree/"&gt;Should&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Hello, Middleman!</title>
    <link rel="alternate" href="/articles/2011/12/hello-middleman.html"/>
    <id>/articles/2011/12/hello-middleman.html</id>
    <published>2011-12-10T00:00:00+01:00</published>
    <updated>2011-12-10T00:00:00+01:00</updated>
    <author>
      <name>Mariusz Cieśla</name>
    </author>
    <summary type="html">&lt;p&gt;So, finally I managed to release something more interesting than just a
&lt;a href="http://blog.mariusz.cc"&gt;Tumblr&lt;/a&gt;. If you followed me before, you probably
know that I&amp;#39;ve been using Wordpress for ages and absolutely hated it,
mostly due to all the maintenance required if you want to keep everything
tidy and clean. Also, since I&amp;#39;ve been working with Ruby on Rails and similar
technologies since 2008, I really hated the spaghetti-code mess of Wordpress
templates. I tried several content management systems since then, but I never
really settled with any because there was always something that was pissing
me off.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;So, finally I managed to release something more interesting than just a
&lt;a href="http://blog.mariusz.cc"&gt;Tumblr&lt;/a&gt;. If you followed me before, you probably
know that I&amp;#39;ve been using Wordpress for ages and absolutely hated it,
mostly due to all the maintenance required if you want to keep everything
tidy and clean. Also, since I&amp;#39;ve been working with Ruby on Rails and similar
technologies since 2008, I really hated the spaghetti-code mess of Wordpress
templates. I tried several content management systems since then, but I never
really settled with any because there was always something that was pissing
me off.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Finally, I&amp;#39;ve decided to go for something written in Ruby and started 
looking into other alternatives for blogging, namely
&lt;a href="http://nestacms.com"&gt;Nesta&lt;/a&gt; and - really low level - &lt;a href="https://github.com/mojombo/jekyll"&gt;Jekyll&lt;/a&gt;
and &lt;a href="http://middlemanapp.com"&gt;Middleman&lt;/a&gt;. Meanwhile, I maintained
a &lt;a href="http://blog.mariusz.cc"&gt;Tumblr&lt;/a&gt; as my default, go-to blog. &lt;/p&gt;

&lt;p&gt;I haven&amp;#39;t really shared what&amp;#39;s happening with my website since then, but I
finally settled with Middleman as my blogging choice, for several reasons
that I&amp;#39;d like to sum up in this post.&lt;/p&gt;

&lt;h2&gt;Learning new stuff&lt;/h2&gt;

&lt;p&gt;First reason why I even decided to look into non-CMS alternatives for blogging
was simple - I love to hack around and learn new stuff and freedom given to
you by &amp;quot;engines&amp;quot; like Nesta, Jekyll or Middleman is just amazing - if you
want your templates to be &lt;a href="http://haml-lang.com"&gt;Haml&lt;/a&gt;, you just install
a Ruby gem and add one line to the setup. If you want your stylesheets to be
&lt;a href="http://sass-lang.com"&gt;Sass&lt;/a&gt; - same thing. Love that.&lt;/p&gt;

&lt;p&gt;I finally settled with Middleman because it&amp;#39;s dead simple. There&amp;#39;s nothing
there except one &lt;code&gt;config.rb&lt;/code&gt; file and a &lt;code&gt;Gemfile&lt;/code&gt; for Ruby gems that your
blog requires. You can do everything from the text editor level, which is
really awesome if you like simplicity.&lt;/p&gt;

&lt;h2&gt;Pure blogging fun&lt;/h2&gt;

&lt;p&gt;Another thing that I love in those minimalistic blogging solution is the fact
that they leave you with nothing but template engine of your choice and 
text files for writing posts. There&amp;#39;s no database, no WYSIWYG editors, nothing
like that. That means you can write your posts on the go in any text editor (or
&lt;a href="http://iawriter.com"&gt;Writer&lt;/a&gt;, like I do) and then save it as a Markdown file.
When it comes to control over your files, there&amp;#39;s only one level
below, and that&amp;#39;s writing your blog &lt;a href="http://yaronschoen.com"&gt;in pure HTML&lt;/a&gt;, but
I personally love Markdown and wouldn&amp;#39;t replace it with HTML.&lt;/p&gt;

&lt;h2&gt;Unlimited power&lt;/h2&gt;

&lt;p&gt;Since you&amp;#39;re writing your blog in Markdown into text files without database,
good idea is to keep your files in a repository, just like you would keep your
code. While that might be a bit tedious for a non-developer (even though I know
at least two people who have absolutely no tech background and they are
blogging with a git-based solution just fine), but gives you power of
a full-fledged version control system behind your blog. That means merging,
branching, reverting and all the awesomeness that comes with it. As I said
before, if you like fiddling around with your tools and you&amp;#39;re a developer (so
you know how to go about a version control system anyway), it&amp;#39;s a perfect
combination.&lt;/p&gt;

&lt;p&gt;Wrapping up, I highly recommend switching to a simple, non-CMS solution if
you&amp;#39;re a developer. If you&amp;#39;re not a developer, but you like to learn new stuff,
I recommend it as well. If you need any help or inspiration, you can find the
source of this very blog &lt;a href="http://github.com/mariusz"&gt;on my Github&lt;/a&gt; and all the
docs you need to get you up and running &lt;a href="http://middlemanapp.com/"&gt;at the Middleman website&lt;/a&gt;.
If you have any specific questions or tips regarding my code, feel free to
&lt;a href="http://twitter.com/dotmariusz"&gt;reach me on Twitter&lt;/a&gt; as this blog doesn&amp;#39;t
have any comment system and it might happen that it won&amp;#39;t, since I think 
everything these days can be done via Twitter.&lt;/p&gt;

&lt;p&gt;Happy hacking! &lt;/p&gt;
</content>
  </entry>
</feed>

