Mike Gehard's blog
If you haven't looked at OmniAuth for authentication with sites like Google, Github and Facebook, then you should take a look. It is pretty killer.
This morning we needed to write a Cucumber scenario to test that a user could log into the system using Google Apps.
We did a quick spike on getting OminAuth integrated, which was a super simple process, and poked around in the browser to make sure it was working OK.
Thanks to Jose Valim for providing some guidance, via the Devise test suite, on how to get this all up and running.
The basics can be found in this Gist:
I put that code in /features/support/omniauth.rb and then all I need to do is label any scenarios that need to deal with login with an @omniauth_test tag and we are all set.
As our features count grows, I could see us doing this before/after all Cucumber scenarios.
Note: You need to be using 0.2.0.beta5 of OmniAuth to get this to work. Earlier versions don't have the testing functionality built in.
Also Note: This same functionality can be used in good, old RSpec integration tests or Steak tests as well.
If you are looking for a ruby gem to interact with S3, you may want to choose the S3 gem over the AWS::S3 gem.
The S3 gem seems to be under active development while the AWS::S3 gem gem seems to have gotten a little stale.
I mistakenly chose the AWS::S3 gem gem based on the number of downloads on rubygems.org but it was missing the ability to copy from one S3 bucket to another without having to move the files through my local machine. That will teach me for not reading the source code...
So I've been doing a bunch of BDD development these days using Cucumber as a starting point.
While working with client, the question came up about how they could share step definitions across multiple teams of developers.
I then remembered that the Aruba gem is just that, a collection of Cucumber step definitions.
So if you are looking for a way to start packaging up those step definitions that you have used on multiple projects and are tired of copying across projects, check out how the Aruba gem does it and go from there.
Thanks to the Cucumber and Aruba folks for sharing some very useful technology that allows us all to raise the bar when it comes to delivering quality software.
In an effort to continue my contributions to the open source Ruby/Rails ecosystem, I decided to help the factory_girl_rails team move the Rails3 generators from the rails3-generators project into the factory_girl_rails project.
Like all good Ruby/Rails developers, they asked to make sure that I had tests written around the generators. I thought for a bit on how I was going to do this and then I wandered across the Cucumber feature files in the rspec-rails repo and found my answer.
Rspec-rails (and RSpec2 as well) uses a gem called Aruba to easily write Cucumber features around things that happen from the command line.
If you'd like to check out the result of using Cucumber and Aruba to test Rails3 generators, head over to my fork of the factory_girl_rails gem and check out the features/generators.feature file.
Hopefully the changes will be merged into the official factory_girl_rails repo soon and the generators will live closer to home.
Did you know that you can call map() and each() on a Ruby string? Do you know how they behave? I hope I'm not the only one that thought they understood it but was proven mistaken.
What would you expect the following code to do?
"hello".map{|char| "Char#{char}" }
I thought it would return me an array with a bunch of "Char" where x is each letter in "hello". Nope...it returns:
["Charhello"]
What would you expect the following code to do?
"hello".each{|char| puts "Char#{char}"}
Yeah I thought it would write out a bunch of puts statements "Char" where x is each letter in "hello". Nope it prints:
Charhello
Ok so maybe my thoughts on strings being enumerable were a little off...I've been wrong before and will probably be wrong again.
What really threw me for a loop was that I can access the characters in a string by index:
"hello"[1]
returns
101
which is the ASCII representation of "e".
So what is the moral of this story? Sometimes things aren't as the seem at first glance. And sometimes you need to step back, fire up irb and see what really is happening.
Update: Thanks all for the responses below.
