The idea that Steak had about acceptance tests is great. You don’t necessarily have to use a solution like Cucumber to write acceptance test for your application. You could just as easily use rspec or another testing suite instead. Being the riot fan that I am, I wanted to have something similiar for the Riot community so that we too can write beautiful acceptance tests.
Melee is to Riot what Steak is to Rspec. It’s a minimalist approach to acceptance testing. It keeps close to how you write tests but give you a simple DSL to give you that ‘acceptance test’ feel. For a side to side comparison, this is what a melee test looks like:
feature %Q{
To write better software
as a ruby developer and a riot user
I need to write me some acceptance test
} do
background { "that i'm no different than setup" }
scenario "With some background, it should really be no different than a setup" do
topic =~ /setup/
end
given(:a_string) { "yay for acceptance test" }
scenario "With some string that I have, it should ensure that the string" do
a_string
end.matches %r{acceptance} # Takes the same macros
end
The same test in plain riot would be:
context %Q{
To write better software
as a ruby developer and a riot user
I need to write me some acceptance test
} do
setup { "that i'm no different than setup" }
asserts "With some background, it should really be no different than a setup" do
topic =~ /setup/
end
helper(:a_string) { "yay for acceptance test" }
asserts "With some string that I have, it should ensure that the string" do
a_string
end.matches %r{acceptance} # Takes the same macros
end
Ok, that’s fine and dandy, but what about actual integration with Capybara? Good question. Despite that capybara comes with easy integration with rspec, there is an easy workaround provided to allow you to use it in any test suite.
We’ll use the auto-generated test_config.rb from padrino as a guide.
All you need to do is require and include like so:
## test_config.rb
# ...
require 'capybara/dsl' # require the Capybara DSL
class Riot::Situation
include Rack::Test::Methods
include Capybara
# ...
end
Now, you can use capybara like you would. Here’s an example:
require File.expand_path('../../../test_config', __FILE__)
feature %{
When I access the link pages
I should see a form
that allows me to shorten urls
} do
background do
Capybara.app = Shortener
visit '/links/new'
end
scenario "With the links page, I should see a text field" do
find_field('Url').visible?
end
scenario "With the links page, I should be able to submit a url" do
fill_in 'Url', :with => 'http://www.google.com'
click_button 'Submit'
current_path
end.matches %r{links\/show}
end
There we have it. Riot now has acceptance tests ready to use with a library like Capybara. To see some demostration of melee/capybara intergration, you can check out a Padrino URL shortener demo I made to demonstrate some of the features of both padrino and riot.
happy Testing, and Happy Father’s Day!
A while back, I wanted to dabble into rack middleware and the best way was to create one myself. Without getting too indepth, Rack middlewares act as the cascading stylesheets for applications. You stack middlewares on top of your rack compatible application. As requests come in, each middleware runs its process and passes it to the next layer until it reaches the main application.
Recaptcha is a CAPTCHA verification service that operates by pulling scanned text for users to verify a human operator. In most use cases, CAPTCHA verification is used to check comments, posts, or even account creation.
There are libraries out that they handle RECAPTCHA verification. However, they are limited only to Rails apps. At the time of creation of rack-recaptcha, I needed a library that I could use with other rack compatible frameworks such as Sinatra and Padrino. Rack seemed like a good solution to ensure agnosticism among rack compatible apps.
Adding a RECAPTCHA solution is two parts:
With middlewares, the verification request can be processed in the middleware and pass its results back to the application. If the request coming in doesn’t require RECAPTCHA, the request is immediately passed down the stack.
This keeps the library lean. No extra code for integration with Rails, Merb, Sinatra, Padrino or whatever framework you use.
If you want to check out the library, its on github or install it with:
$ gem install rack-recaptcha
That’s all for now. thanks for reading!
I generally think and research alot on religion, philosophy and other random niche topics. These thoughts I formulate I either keep to myself or end up talking to a few close friends of mine such as Nathan. But after talking to Michele, she’s convinced me to share my thoughts online about what it is that I come up with and to at the very least keep a record.
If the term Parallel Universe or String Theory mean anything to you, or you have just seen the movie The One, then this post might be of some interest to you.
The basic premise of Parallel Universes and all the surrounding theories is that For each choice or decision that we are capable of taking in our life, each of those paths diverge into their own possible universe. So, if you had decided to take a left turn instead of a right, there would exist a world in which that you had taken the right instead. Staying true to the movie “The One”, there would exists worlds where you would have picked a completely different lifestyle and occupational choice. There would exist thousands, if not, an infinite amount of worlds that would depict your different you.
If a decision is what is needed to create an alternate reality, then what we have in this world is already in itself, an alternate reality. Consider that if you and I at the very core are made up of building blocks of cells, DNA, and atoms, and with our specific amount of chance and choices that has happened in this world, we really are nothing more than alternate realities of what those components COULD have been. In essence, You and I are merely alternate versions of what we could have been. If nature had taken a different turn, I may have ended in your place, with your features, and perhaps even with the parents and environment that you had. Likewise, you or another could have equally been part of the genetic makeup of another creature, or perhaps even a plant. The decision that were made on a micro level are what lead to the macro decisions that ended up creating who we are, where we exists, and how we end up interacting.
What this lead me down was to a quote that I actually heard once before, and had a profound effect on my life.
“Eternity isn’t some later time. Eternity isn’t a long time. Eternity has nothing to do with time. Eternity is that dimension of here and now which thinking and time cuts out. This is it. And if you don’t get it here, you won’t get it anywhere. And the experience of eternity right here and now is the function of life” - Joseph Campbell
Eternity is our experience. It’s the experience that we are having as we go through the walk of life. In connection with alternate realities, these trial and simulations of each possible choice in our life add to the value of the experience. It’s creating this concept of Eternity. Each one of us I feel is at its very core, connected to each other. Science has shown it. As we live alternate possibilities of what could happen in life, there exists a Unity amongst all of us. We together are co-creating this experience. United we weave together the parallel and crossing strands of chance into this detailed and multi-facted tapestry we call life, the experience we call Eternity.
I figure it’s about time to start writing in my tumblr. So let’s talk about terminitor. Terminitor is an automation library written in ruby that allows for a clean and easy way to automate your usual terminal commands and setup. So let’s start with a typical scenario: You start up a project, want to open up a console, run the server, and maybe even run some test automation. It might look something like this:
terminal tab 1
$ cd /my_project
$ rvm use ree@my_project_gemset
$ watchr test.watchr
terminal tab 2
$ cd /my_project
$ rvm use ree@my_project_gemset
$ padrino start -h 0.0.0.0 -p 4567
terminal tab 3
$ cd /my_project
$ rvm use ree@my_project_gemset
$ padrino console
terminal tab 4
$ cd /my_project
$ rvm use ree@my_project_gemset
$ gitx
and so on. Things start to get really redudant. That’s where terminitor comes in. Taking what we have up there, we can reduce this down into a nice DSL:
# ~/.terminitor/my_project.rb
before "cd /my_project", "rvm use ree@my_project_gemset"
tab "watchr test.watchr"
tab "padrino start -h 0.0.0.0 -p 4567"
tab "padrino console"
tab "gitx"
Now that’s a bit better. Now instead of doing your usual command circuit training, you can instead jump right to the end of it:
$ terminitor start my_project
For those of you that get a bit more fancy with your Mac OSX Terminal, Terminitor allows you to go a step further with customizing your windows, like say using the “Grass” setting:
tab :name => "my green tab", :settings => "Grass" do
run "uptime"
end
Lazy to find the settings, window sizes that you have setup for your windows? Let Terminitor get it for you:
$ terminitor edit my_lazy_project --capture
This will grab the settings for your windows and tabs, leaving you only the commands to fill out for each tab/window! Not too shabby.
Currently, Terminitor has support for Mac OS X Terminal and KDE Konsole. However, that doesn’t mean that your flavor of choice can’t be supported. Terminitor makes it simple to extend!
If you want to check out more of the other features terminitor provides, I suggest checking it out on github.
“I’ve seen things you people wouldn’t believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser Gate. All those moments will be lost in time like tears in rain. … Time to die.”
That’s a classic.
So I really wanted to just finish up my redo of my site. but instead i’ve decided to just start over here in tumblr land. I’ll admit, this is pretty cool, never really though of using tumblr as a blogging engine. I’ve been feeling that as a developer, i should just make it all myself, but eh, why reinvent the wheel? So i ended up stumbling on something pretty cool and nifty. Namely, this nice little gem called tumblr-rb:
$ gem install tumblr-rb
Nice little ruby library and cli from munsch. It looks like it needs a bit of updating though, as it doesn’t recognize the ‘answer’ post type. I’ll probably fork it sometime later this week and make the additions necessary. In the mean time, it seems I have quite a bit of work today not to mention that the other open source libraries that i’m a part of have a few issues that need to be address. Man, wouldn’t it be nice if you could just work for open source? A life that would be. Ok, that’s it for now. later!