20 articles on Cucumber and a free beverage recipe!
595 comments Latest by Fuzzy Socks Mon, 06 Sep 2010 07:42:39 GMT
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)
Spec Your Views
84 comments Latest by Timberland Classic Boots Mon, 06 Sep 2010 11:49:23 GMT
I meant to work on this post… oh about 7 months ago.
Way back in January (7 months ago), Jamis Buck posted an article titled, Testing your views, which gave a few tips on using Test::Unit to, as the title suggests, test your views.
While, I’m not going to rewrite everything that Jamis wrote, I’d like to show you how to test these views with RSpec. (you might take a moment to quickly read his post…)
In this example, I’m going to show you how we’re able to write specs for the following RHTML, which you’ll notice matches the code that he wrote tests for.
<% if @user.administrator? %>
Hi <%= @user.name %>! You appear to be an administrator.
<%= link_to "Click here", admin_url, :id => "admin_link" %>
to see the admin stuff!
<% end %>
Jamis writes, “The only really significant thing you ought to be testing here is that the admin link only shows up for administrators. “
So, let’s do just that, but with RSpec.
I’m not sure how Jamis is handling his view tests, but we’re going to approach our view specs, much like we approach our controller specs, with the use of mocks and stubs, because we really don’t need to spec any of our models at this level in the application.
Tip: Write specifications for your models… in your model specs not in your controller or view specs.
The first thing that we’re going to do is setup a custom spec helper, because for something like an mocked user, will probably get reused in other areas of the user interface. Spec helpers are essentially modules that you can include in your RSpec descriptions (the block that starts with describe) and reuse.
In this spec helper, I’m going to include two methods, to mock the User model and stub out any of the methods that are necessary for spec’n this view.
module MockUserHelper
def mock_normal_user
user = mock(User)
user.stub!(:administrator?).and_return(false) # <--- NOT an admin
user.stub!(:name).and_return('David Chelimsky')
return user
end
def mock_admin_user
user = mock(User)
user.stub!(:administrator?).and_return(true) # <--- IS an admin
user.stub!(:name).and_return('Aslak Hellesoy')
return user
end
end
In the mock_normal_user method, we’re constructing a mock object and stubbing out the methods that we see are being called in the RHTML code. In mock_admin_user, we’re basically doing the same thing, but just stubbing the administrator? method to return true for this mock user.
By stubbing these methods, we’ll be able to send a non-ActiveRecord object to the view and have it render without knowing the difference. For example, the if @user.administrator? condition will return true or false, depending on how we stubbed it.
For more information on mocks and stubs, read here.
Now that we have our spec helper, let’s go ahead and dive into a few specifications for the view.
describe "index page" do
include MockUserHelper
it "should render an admin link for an admin user" do
assigns[:user] = mock_admin_user
render 'index'
response.should have_tag('a#admin_link')
end
it "should not render an admin link for a normal, non-admin user" do
assigns[:user] = mock_normal_user
render 'index'
response.should_not have_tag('a#admin_link')
end
end
Please note: This code example is only longer than the one shown by Jamis because he didn’t include how he setup all his user sessions/objects. ;-)
When these specs are run, we can see the following results.

Pretty output courtesy of RSpec + TextMate bundle
Great, we’ve been able to write specifications for our Rails views without a lot of pain. Stay tuned for more posts on this topic as I continue writing about how Designers and Developers can work together, in harmony. (see my last post on this topic)
For more information on adopting RSpec, please visit the RSpec project homepage.
Embracing Failure, part 1
16 comments Latest by uggs outlet Mon, 02 Aug 2010 01:07:04 GMT
I’m currently reading To Engineer is Human, by Henry Petroski and found the following applicable to software development and managing client and customer expectations.
“As much as it is human to make mistakes, it is also human to want to avoid them. Murphy’s Law, holding that anything that can go wrong will, is not a law of nature but a joke. All the light bulbs that last until we tire of the lamp, all the shoelaces that outlast their shoes, all the automobiles that give trouble-free service until they are traded in have the last laugh on Murphy. Just as he will not outlive his law, so nothing manufactured can be or is expected to last forever. Once we recognize this elementary fact, the possibility of a machine or a building being as near to perfect for its designed lifetime as its creators may strive to be for theirs is not only a realistic goal but also a reasonable expectation for consumers. It is only when we set ourselves such an unrealistic goal as buying a shoelace that will never break, inventing a perpetual motion machine, or building a vehicle that will never break down that we appear to be fools and not rational beings.”
I’m sure that most of us are guilty of having high expectations for products that we purchased. (why does my ipod screen scratch so easily when in my pocket?) We also set high expectations for the code that we develop, which is why we (hopefully) continue to refine our process. We’re bound to time and budget constraints, which often prevent us from testing every imaginable edge case. Given our constraints, problems are almost always going to arise. It’s no wonder that we see Test-Driven Development as an important part of a healthy development process. We want to catch our failures as early as possible.
Our clients often have high expectations and it’s almost always very reasonable. That’s not to say that some clients will not have highly irrational expectations. It’s our job to manage these expectations as best as possible.
Do we mislead our clients by convincing them that our TDD/BDD process is going to prevent any bugs from creeping from the woodwork after the development cycle is finished?
“I thought that we paid you to fully test the code?”
Really… is that even possible? Can we predict (and test) every possible interaction within an application? Highly unlikely.
What we can do is plan for and embrace failure. We can help our clients understand that almost every application needs to be maintained after it’s initial development cycle. Bugs are inevitable and there needs to be a clear process for handling them.
Perhaps I’m abusing the bug fixing process by calling it a failure… but I’ve also found that yes… many bugs are due to failure. Whether that be a failure to specify application behavior, a failure to understand the project goals, a failure in communication, ...or maybe a failure in our software architecture. We’re constantly failing.. and it’s okay!
IT’S OKAY TO FAIL! (some of the time…)
“No one wants to learn by mistakes, but we cannot learn enough from successes to go beyond the state of the art. Contrary to their popular characterization as intellectual conservatives, engineers are really among the avant-garde. They are constantly seeking to employ new concepts to reduce the weigh and thus the cost of their structures, and they are constantly striving to do more with less so the resulting structure represents an efficient use of materials. The engineer always believes he is trying something without error, but the truth of the matter is that each new structure can be a new trial. In the meantime the layman, whose spokesman is often a poet or writer, can be threatened by both the failures and the successes. Such is the nature not only of science and engineering, but of all human endeavors.”
As we’re creating these virtual structures… are we really taking the time to reflect on our failures? This is why some teams adopt practices like iteration retrospectives and post-mortems.
I’ll end this with a few questions, which I hope that you’ll share your experiences about…
- In what ways is your team embracing the failures of your development projects?
- How do you help manage your clients expectations… so that they too can plan for and embrace failure? Isn’t their new business venture on the web… likely to experience some failure?
We have so much to learn…
Be Careful that you don't Stub your Big Toe
60 comments Latest by Christian Louboutin Sat, 04 Sep 2010 06:08:40 GMT
In a project that I’m currently working on, we’re handling recurring payments for subscribers. I’ve decided to play with a different payment service API on this project (TrustCommerce), which supposedly has one of the easier systems to handle recurring payments as well as one-time charges to the same credit cards. They store all the credit card data so that our delivered product to the client is CISP-compliant.
I came across the TrustCommerce Subscription plugin for Rails, which does just everything that I need to do in this first product release… as well as things that aren’t requirements just yet.
Well, I got my test account from TrustCommerce and was working on some RSpecs to test my new subscription and noticed that it was failing. After some snooping around the error responses, I realized that… test accounts don’t give you the ability to test the Citadel features of TrustCommerce. It’ll be another week or so before finish getting our account setup, so what am I to do? I really want to finish writing these specs and move on to the other portions that are dependent upon this working.
Suppose that you were going to perform something like this in an AR callback.
class BillingDetail < ActiveRecord::Base
# validations
before_create :store_credit_card_data_with_trust_commerce
private
def store_credit_card_data_with_trust_commerce
# some of this is still test data... prettyu much copied from the README
# TODO: refactor... but keep me out of controllers!
response = TrustCommerceGateway::Subscription.create(
:cc => self.credit_card_number,
:exp => '0412',
:name => self.customer_name,
:amount => 1,
:cycle => '1y',
:demo => 'y'
)
if response['status'] == 'approved'
self.billing_id = response['billingid']
else
# handle failure
end
end
end
Enter Mock Objects
Since I am unable to succesfully use the TrustCommerceGateway::Subscription.create method until I get our real account, I needed a simple way to emulate the interaction with the web service.
This can be done by using a Mock object, which RSpec provides for you.
TrustCommerceGateway::Subscription.stub!(:create).and_return( {expected response} )
Let’s look at the following spec file (much of it removed to protect the innocent).
module ValidBillingDetail
def valid_attributes
{ # a hash of valid key/values for this model }
end
def approved_trust_commerce_subscription
{ 'status' => 'approved', 'billingid' => '1093423' }
end
end
context "A new billing detail" do
include ValidBillingDetail
setup do
TrustCommerceGateway::Subscription.stub!(:create).and_return( approved_trust_commerce_subscription )
end
# bunch of other specs
specify "should store new billing info with 3rd party API and store the billingid" do
@billing_detail = BillingDetail.create( valid_attributes )
@billing_detail.billing_id.should_not_be nil
end
end
You’ll notice a few things. First, you’ll see that I’ve stubbed the create method and when it is called in the method in my model, it’ll return the hash that I’ve specified.
TrustCommerceGateway::Subscription.stub!(:create).and_return( approved_trust_commerce_subscription )
In the spec, you will see that I am checking that that the .billing_id.should_not_be nil. If you look back in the method in the model above, you will notice that an approved subscription returns a billing_id, which is set when the transaction is successful.
This is working out great for me and because the documentation is fairly easy to follow, I’m going to be able to mock much of the behavior that I’ll be using in the application, without needing to even connect to their API.
If you’re using RSpec, I highly encourage you to read more about mocks objects.
Testing Cookies in Ruby on Rails
27 comments Latest by Timberland Classic Boots Mon, 06 Sep 2010 11:40:44 GMT
Over the weekend, Brian Ford released a useful plugin for testing your Ruby on Rails applications called, assert_cookie.
Brian likes his cookies…
“I love cookies. There are, of course, tons of varieties and I’m no connoisseur but I love the soft chocolate chip right out of the oven, hot and gooey. But, if you’re like me, you don’t want your Rails code to be gooey.” -Brian Ford
To use assert_cookie, follow these steps.
- Install via,
script/plugin install http://svn.planetargon.org/rails/plugins/assert_cookie - Fill your tests with some cookies
- Test your cookies!
assert_cookie :pass,
:value => lambda { |value| UUID.parse(value).valid? }
assert_cookie :yellow, :value => ['sunny', 'days']
assert_cookie :delight, :value => 'yum'
assert_cookie :secret, :path => lambda { |path| path =~ /secret/ },
:secure => trueFor more information on other plugins and tools that PLANET ARGON is releasing under open source licenses, visit www.planetargon.org.
Also, be sure to subscribe to Brian Ford’s feed as he says he’ll be announcing more plugins and tips soon. :-)
Have Fun!
Continuous Integration == Communication
33 comments Latest by wangjiming Tue, 31 Aug 2010 07:16:15 GMT
Martin Fowler has updated his Continuous Integration article.
One of the points that I appreciated reading about in this article was that when you’re working in a team, the ability to keep consistent communication. This is vital to the success of the project, just like all forms of quality communication is important during the lifespan of a project.
“Continuous Integration is all about communication, so you want to ensure that everyone can easily see the state of the system and the changes that have been made to it.”
Another point reminded me of something I recently posted about1, which was that you should always keep your project releasable… at all times.
“To help make this work, anyone involved with a software project should be able to get the latest executable and be able to run it: for demonstrations, exploratory testing, or just to see what changed this week.”
Test. Before. You. Commit.
Fowler also mentions Ruby on Rails in regards to automating deployment practices yourself. :-)
In any event, read the article.
Older posts: 1 2





