<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://aflatter.de/</id>
  <title>aflatter.de</title>
  <updated>2010-06-21T22:00:00Z</updated>
  <link href="http://aflatter.de/" rel="alternate"/>
  <link href="http://aflatter.de/feed.xml" rel="self"/>
  <author>
    <name>Alexander Flatter</name>
    <uri>http://aflatter.de</uri>
  </author>
  <entry>
    <id>tag:aflatter.de,2010-06-22:/2010/06/testing-headers-and-ssl-with-cucumber-and-capybara/</id>
    <title type="html">Testing custom headers and ssl with Cucumber and Capybara</title>
    <published>2010-06-21T22:00:00Z</published>
    <updated>2010-06-21T22:00:00Z</updated>
    <link href="http://aflatter.de/2010/06/testing-headers-and-ssl-with-cucumber-and-capybara/" rel="alternate"/>
    <content type="html">&lt;p&gt;Today I ran into yet another issue where a little hack is required to get the job done. I was testing our application and came to a point where ssl is required. In plain old webrat you could do:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;header &amp;quot;HTTPS&amp;quot;, &amp;quot;on&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Even simpler, when using &lt;code&gt;Rack::Test&lt;/code&gt; directly, you can just use the third parameter of your favorite request method to pass additional stuff:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;get :index, {}, { :https =&amp;gt; 'on' }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you try to test for custom headers with capybara, you will run into trouble. There is simply no method to get access to the request environment, so things become a little more difficult. The following solution will work only if you use the &lt;code&gt;:rack_test&lt;/code&gt; driver. Any other drivers do not support setting headers. Simply put the following code into &lt;code&gt;features/support/headers_hack.rb&lt;/code&gt; which will automatically be loaded by cucumber.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;module RackTestMixin

  def self.included(mod)
    mod.class_eval do
      # This is where we save additional entries.
      def hacked_env
        @hacked_env ||= {}
      end
      
      # Alias the original method for further use.
      alias_method  :original_env, :env

      # Override the method to merge additional headers.
      # Plus this implicitly makes it public.
      def env
        original_env.merge(hacked_env)
      end
    end
  end

end

Capybara::Driver::RackTest.send :include, RackTestMixin

module HeadersHackHelper
  
  def add_headers(headers)
    page.driver.hacked_env.merge!(headers)
  end

end

World(HeadersHackHelper)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It will give you access to an additional attribute of the driver, &lt;code&gt;#hacked_env&lt;/code&gt;. Use this hash to set additional entries as you like. Some examples:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# To test ssl
Given /^I use ssl$/ do
  add_headers('HTTPS', 'on')
end

# To set the remote ip
Given /^my IP is (\d{1,3}\.){3}\d{1,3}$/ do |ip|
  add_headers('REMOTE_ADDR', ip)
end

# If you check for user agent
Given /^my user agent is &amp;quot;(.+)&amp;quot;$/ do |agent|
  add_headers('User-Agent', agent)
end
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <id>tag:aflatter.de,2010-05-27:/2010/05/github-pages-and-nanoc/</id>
    <title type="html">Github Pages and nanoc</title>
    <published>2010-05-26T22:00:00Z</published>
    <updated>2010-05-26T22:00:00Z</updated>
    <link href="http://aflatter.de/2010/05/github-pages-and-nanoc/" rel="alternate"/>
    <content type="html">&lt;p&gt;I just found out that my old shabby weblog running Wordpress has been exploited by some spam bots. &lt;a href="http://blog.sucuri.net/2010/04/details-on-network-solutions-wordpress.html"&gt;This&lt;/a&gt; &lt;a href="http://blog.sucuri.net/2010/05/new-attack-today-against-wordpress.html"&gt;is&lt;/a&gt; &lt;a href="http://blog.sucuri.net/2010/04/mass-infection-of-wordpress-blogs-at.html"&gt;not&lt;/a&gt; &lt;a href="http://blog.sucuri.net/2009/08/wordpress-283-remote-admin-reset.html"&gt;unusual&lt;/a&gt; - no matter if the blog is maintained or not.
To deal with this whole mess, I finally abandoned Wordpress in favor of &lt;a href="http://nanoc.stoneship.org"&gt;nanoc&lt;/a&gt; and &lt;a href="http://pages.github.com"&gt;Github pages&lt;/a&gt;. This is how I set up my repository:&lt;/p&gt;

&lt;p&gt;Github pages will serve your site from the &lt;code&gt;master&lt;/code&gt; branch, so we will use the &lt;code&gt;nanoc&lt;/code&gt; output for our initial commit. Compile your site with &lt;code&gt;nanoc3 co&lt;/code&gt; and move the &lt;code&gt;output&lt;/code&gt; directory outside of your site directory. Change to the directory, initialize a new git repository with &lt;code&gt;git init .&lt;/code&gt; and add the github remote with &lt;code&gt;git remote add origin git@github.com:username/username.github.com.git&lt;/code&gt;. Now stage all the files with &lt;code&gt;git add .&lt;/code&gt; and commit them with &lt;code&gt;git commit -m 'Initial commit'&lt;/code&gt;. All the steps listed again:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nanoc3 co
mv output ..
cd ../output
git init .
git remote add origin git@github.com:username/username.github.com.git
git add .
git commit -m 'Initial commit'
git push origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is not new to you, I know. :)&lt;/p&gt;

&lt;p&gt;But of course you do want to keep your source in the repository too, so here are the steps to achieve that (found on the &lt;a href="http://pages.github.com"&gt;pages documentation&lt;/a&gt;):
Create a new root branch (named &lt;code&gt;source&lt;/code&gt; in my case) and remove your old index. &lt;code&gt;git clean&lt;/code&gt; removes all untracked files - which every file is because you just removed the index.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git symbolic-ref HEAD refs/heads/source
rm .git/index
git clean -fdx
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can add your site to the repository and push it to the source branch.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cp -R /path/to/your/site/ .
git add .
git commit -m 'Initial commit of source'
git push origin source
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;rsquo;s it.&lt;/p&gt;

&lt;p&gt;To deploy, you can now issue the following commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rm -rf output
git checkout source
nanoc3 co
git checkout master
cp -R output/* .
git add .
git commit -a -m 'I did something cool to my site'
git push origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;git commit -a&lt;/code&gt; adds all files that are untracked and removes files that are not present in the working tree, so you don&amp;rsquo;t have to worry about abandoned files.&lt;/p&gt;

&lt;p&gt;To automate this process, I use the following bash script:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/bin/bash

rm -rf output
git checkout source
nanoc3 co
git checkout master
cp -R output/* .
git add .
git commit -a -m &amp;quot;Updated site on `date`&amp;quot;
git push origin master
git checkout source
&lt;/code&gt;&lt;/pre&gt;

</content>
  </entry>
  <entry>
    <id>tag:aflatter.de,2009-07-22:/2009/07/cheating-facebooks-biotronic-app/</id>
    <title type="html">Cheating Facebook's Biotronic App</title>
    <published>2009-07-21T22:00:00Z</published>
    <updated>2009-07-21T22:00:00Z</updated>
    <link href="http://aflatter.de/2009/07/cheating-facebooks-biotronic-app/" rel="alternate"/>
    <content type="html">&lt;p&gt;Okay, so this is crazy. There&amp;rsquo;s this nice little game called Biotronic on Facebook:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A puzzle game that features colorful biotechnology. Easy mouse controls, exploding combos and beautiful animations. Challenge yourself and your friends in this exciting game.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I sometimes played that and achieved a score of about 35k. I already thought about hacking the game via image processing etc. - and being curious, I just used google.&lt;/p&gt;

&lt;p&gt;And guess what? Yes, some guy already did that. It&amp;rsquo;s cross platform and all kind of stuff and open source:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gitorious.org/web-automation/biocheat"&gt;http://gitorious.org/web-automation/biocheat&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;
Interesting project!
&lt;br /&gt;&lt;/p&gt;
</content>
  </entry>
</feed>
