20 articles on Cucumber and a free beverage recipe! »
Created at: 10.04.2009 06:22, source: Robby on Rails, tagged: Ruby on Rails ruby programming ruby rspec cucumber testing tdd bdd links recipe water
Cucumber has been getting quite a bit of attention in the community and with the new RSpec Book on nearing publication, I predict that by this time next year, it’ll become a household word like boanthropy.
What is Cucumber?
The Cucumber project describes itself as a suite that, “lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid – all rolled into one format.“
One of the great things about Cucumber is that it can be used to test applications in any language. I haven’t been able to track down a lot of articles of how people are using it with other languages, so please comment if you’re aware of some.
In any event, I’ve been collecting and reading resources from a variety of Cucumber aficionados and thought I’d share some links with you. To round it out, I asked on twitter for some others so that I could hit twenty. :-)
- What’s in a Story?, Dan North
- Telling a good story – Rspec stories from the trenches, Joseph Wilk
- Beginning with Cucumber, Ryan Bates (Railscasts)
- Using RSpec, Cucumber and User stories to build our internal systems, Rahoul Baruah
- Cucumber: The Latest in Ruby Testing, Ruby Inside
- Using Cucumber for Acceptance Testing, Noel Rappin
- Behavior Driven Development with Cucumber, Brandon Keepers (presentation/slides)
- Testing capistrano recipes with cucumber, Jeff Dean
- Using Cucumber to Integrate Distributed Systems and Test Messaging, Ben Mabey
- Tutorial: How to install/setup Cucumber, Alan Mitchell
- Testing outbound emails with Cucumber, Dr. Nic Willians
- Proper Cucumber Sintatra Driving, Chris Strom
- On getting started using Cucumber for .NET
- DRY up your Cucumber Steps, Matt Wynne
- Cucumber, Celerity, & FireWatir, Aidy Lewis (presentation/video)
- Cucumber step definition tip: Stubbing time, Bryan Helmkamp
- Story Driven Development Recipes with Cucumber, Sebastien Auvray
- Testing Facebook with Cucumber, Brandon Keepers
- Testing with the help of machinist, forgery, cucumber, webrat and rspec, Etienne van Tonder
- Integration testing SSL with Cucumber
- Continuous Integration Blueprints: How to Build an Army of Killer Robots With Hudson and Cucumber
So.. there you have it. Please post comments with links to any useful articles not mentioned and I’ll try to keep the list updated.
Also, be sure to check out the list of tutorials and related blog posts on the cucumber wiki (github).
FREE RECIPE: Cucumber Water
And now…for the reason you are all here! If you like cucumbers (eating them)... I would highly recommend heading to your local farmers market and purchasing some cucumbers. Aside from being healthy to eat… they can help make a tasty beverage.
Then do the following…
- Chop several slices of a cucumber
- Fill a pitcher with cold water and ice
- Toss in slices of cucumber
- Stir and leave in fridge for a while
- Take out of fridge, pour into cup…
- Drink… hack… and enjoy
Be sure to check out, How to Make Cucumber Water on wikihow for details.
Happy Hacking!
Related Posts (by me)
- RSpec: It Should Behave Like
- Spec Your Views
- Audit Your Rails Development Team
- Is BDD kinkier than TDD?
more »
db fixtures replacement solution step by step »
Created at: 07.09.2008 19:06, source: Rails on the Run - Home, tagged: datamapper factory_girl fixtures merb rspec rspec spec testing
Like most people who started with Rails a while back, I first loved Rails fixtures and ended up hating them (slow, a pain to maintain etc...).
I went through different experiments, trying different existing libs, writing my own solutions etc... I wasn't quite satisfied until I found factory_girl from thoughtbot.
You might not feel the need for a decent fixtures solution if you do a lot of mocking/stubbing, but I recently came back from my "mock everything you can outside of models" approach and I'm getting closer to the mock roles, not objects approach. So, I'm loosing my model/controller testing separation but I'm gaining by not having to maintain "dumb mocks" which don't always represent the real API behind. I mean, how many times did I change a Model, messing up my app but all my specs were still passing. Anyway, that's a long discussion, which will be covered by wycats during merbcamp
So here is a simple example of how I use factory girl in a Merb + DataMapper app. (you can do the same in a Rails app, there is nothing specific to Merb in factory_girl).
I. create an empty app, set the ORM etc...
II. git pull and install factorygirl from http://github.com/thoughtbot/factorygirl/tree/master. Or install thoughtbot-factory_girl gem using GitHub gem server.
III. create a spec/factories.rb file. (You might prefer to create a folder called spec/factories and add a factory per model)
IV. modify spec_helper.rb and add the following
1 2 3 |
require 'factory_girl' require File.dirname(__FILE__) + '/factories' |
- V. write some specs against a Client model
- VI. Create the Model
- VII. create a factory
IIX. run your specs

IX. fix the model (note that I set
dependencies "dm-validations"in my init.rb)
X. run the specs

XI. add more specs
As you can see, Factory.build(:client) only creates a new instance of the Object, while Factory(:client) creates, saves and loads the instance.
- XII. get them to pass
Factory Girl makes fixtures simple and clean. Here is another example for creating associations:
Factory Girl also supports sequencing, check out FG read me
In conclusion, Factory Girl is a mature and solid factory solution which will take you less than 15 minutes to get used to. It will offer you loads of flexibility and less frustration than good old yaml fixtures. You can also use it with existing fixtures if you want to start using it in an existing app.
more »
db fixtures replacement solution step by step »
Created at: 07.09.2008 19:06, source: Rails on the Run - Home, tagged: datamapper factory_girl fixtures merb rspec rspec spec testing
Like most people who started with Rails a while back, I first loved Rails fixtures and ended up hating them (slow, a pain to maintain etc...).
I went through different experiments, trying different existing libs, writing my own solutions etc... I wasn't quite satisfied until I found factory_girl from thoughtbot.
You might not feel the need for a decent fixtures solution if you do a lot of mocking/stubbing, but I recently came back from my "mock everything you can outside of models" approach and I'm getting closer to the mock roles, not objects approach. So, I'm loosing my model/controller testing separation but I'm gaining by not having to maintain "dumb mocks" which don't always represent the real API behind. I mean, how many times did I change a Model, messing up my app but all my specs were still passing. Anyway, that's a long discussion, which will be covered by wycats during merbcamp
So here is a simple example of how I use factory girl in a Merb + DataMapper app. (you can do the same in a Rails app, there is nothing specific to Merb in factory_girl).
I. create an empty app, set the ORM etc...
II. git pull and install factorygirl from http://github.com/thoughtbot/factorygirl/tree/master. Or install thoughtbot-factory_girl gem using GitHub gem server.
III. create a spec/factories.rb file. (You might prefer to create a folder called spec/factories and add a factory per model)
IV. modify spec_helper.rb and add the following
1 2 3 |
require 'factory_girl' require File.dirname(__FILE__) + '/factories' |
- V. write some specs against a Client model
- VI. Create the Model
- VII. create a factory
IIX. run your specs

IX. fix the model (note that I set
dependencies "dm-validations"in my init.rb)
X. run the specs

XI. add more specs
As you can see, Factory.build(:client) only creates a new instance of the Object, while Factory(:client) creates, saves and loads the instance.
- XII. get them to pass
Factory Girl makes fixtures simple and clean. Here is another example for creating associations:
Factory Girl also supports sequencing, check out FG read me
In conclusion, Factory Girl is a mature and solid factory solution which will take you less than 15 minutes to get used to. It will offer you loads of flexibility and less frustration than good old yaml fixtures. You can also use it with existing fixtures if you want to start using it in an existing app.
more »
Misc tips and tricks »
Created at: 30.01.2008 10:00, source: Rails on the Run - Home, tagged: autotest bdd bdd integration rspec rspec testing zentest
I haven't posted for quite a long time. The thing is I moved to a new place and I'm really busy on working clients + setting up my new office + dealing with way too much paperwork.
Anyway, enough excuses, here are few tips that I believe will be useful to some of you:
ZenTest Autotest
I love autotest, but you might have noticed that sometimes (especially on big projects), ZenTest might start using more CPU than expected. On my machine, that results in the fan going off and annoying the crap out of me.
The solution is quite simple, exclude all folders you don't need to monitor. To do that, update ZenTest to version 3.8.X
sudo gem update ZenTest
(older version had a different syntax)
Now, edit your .autotest that should be located in ~/.autotest (if it doesn't exist, create it).
Finally add the following code:
1 2 3 4 |
Autotest.add_hook :initialize do |at| %w{.svn .hg .git vendor}.each {|exception| at.add_exception(exception)} end |
I personally freeze rails in vendor and I autotest is way happier when it doesn't have to monitor some extra files. (note that we also exclude folders such as .git or .svn) (you can also include files etc... read more there)
RSpec
RSpec is certainly my favorite Ruby tool and I'm glad to say that most of my SD.rb friends finally got convinced!
Now, few people complained to me about spec failures outputting the full stack such as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
The Sessions controller should fail since it's a test' FAILED expected true, got false test_app-git/trunk/vendor/plugins/rspec/lib/spec/expectations.rb:52:in `fail_with' test_app-git/trunk/vendor/plugins/rspec/lib/spec/expectations/handler.rb:21:in `handle_matcher' test_app-git/trunk/vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb:34:in `should' ./spec/controllers/sessions_controller_spec.rb:25: test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_methods.rb:78:in `instance_eval' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_methods.rb:78:in `run_with_description_capturing' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_methods.rb:19:in `execute' /opt/local/lib/ruby/1.8/timeout.rb:48:in `timeout' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_methods.rb:16:in `execute' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:288:in `execute_examples' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:287:in `each' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:287:in `execute_examples' test_app-git/trunk/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:121:in `run' test_app-git/trunk/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:22:in `run' test_app-git/trunk/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in `each' test_app-git/trunk/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:21:in `run' test_app-git/trunk/vendor/plugins/rspec/lib/spec/runner/options.rb:89:in `run_examples' test_app-git/trunk/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' script/spec:4: Finished in 6.035147 seconds 400 examples, 1 failure |
We can really easily change that, open you spec.opts file located in your spec folder.
it probably looks like that:
1 2 3 4 5 6 7 8 |
--colour --format progress --loadby mtime --reverse --backtrace |
Get rid of "--backtrace" and your new failure should look like:
1 2 3 4 5 6 7 8 9 10 11 |
1) 'The Sessions controller The Sessions controller should fail since it's a test' FAILED expected false, got true ./spec/controllers/sessions_controller_spec.rb:25: script/spec:4: Finished in 0.269956 seconds 15 examples, 1 failure |
Other stuff you may find interesting (in no particular order):
- spec converter
- Rails Cell
- Git to manage and deploy a Rails app
- contacts (retrieve user's contacts from yahoo, gmail etc..)
- Hashrocket
- one of the best Rails book of the moment
- err's new baby
- caboose conf 08
- git hub
- SWX Ruby (or how to get Rails to talk with Flash even faster)
- Ruby Reddit
more »
RSpec on Rails Matchers plugin »
Created at: 04.01.2008 05:46, source: Rails on the Run - Home, tagged: matchers rspec rspec test testing
RSpec is an awesome testing framework. On top of being the first Ruby BDD framework the core team is doing a great job in enhancing our testing experience and therefore the quality of our code.
This time, I don't want to introduce to the latest changes but instead showing you what Josh Knowles, Bryan Helmkamp and myself came up with.
RSpec on Rails matchers plugin + TextMate Bundle
Matchers are some sort of helpers that will help you cleaning up your tests. We simply came up with a collection of matchers that we think will make your like easier.
We divided the matchers in 3 categories:
Associations
Verify that the association has been defined. (doesn't verify that the association works!)
Usage examples:
1 2 3 4 5 6 7 8 |
@post.should have_many(:comments)
@comment.should belong_to(:post)
@user.should have_one(:social_security_number)
@project.should have_and_belong_to_many(:categories)
|
Validations
Verify that a validation has been defined. (doesn't test the validation itself)
1 2 3 4 5 6 7 8 9 10 |
object.should validate_presence_of(:attribute)
object.should validate_confirmation_of(:attribute)
object.should validate_uniqueness_of(:attribute)
object.should validate_length_of(:attribute, :between => 5..10)
object.should validate_length_of(:attribute, :is => 5)
|
Views
My personal favorite matchers, you can now do stuff like:
1 2 3 4 5 6 7 8 9 10 11 12 |
it "should render new form" do
render "/users/new.html.erb"
response.should have_form_posting_to(users_path) do
with_text_field_for(:user_name)
with_text_area_for(:user_address)
with_text_field_for(:user_login)
with_text_field_for(:user_email)
with_submit_button
end
end
|
Check the readme for more information and details on the added matchers. I personally recommend you try the TextMate Bundle on top of being a perfect tool for lazy devs, it also lists all the available matchers and is an excellent way of learning.
We just released our first release yesterday, this is not a final version and we will keep on improving the code. If you have suggestions and patches feel free to open a ticket there.
more »
