What Is the Path to Learn Bdd on Ruby on Rails

What is the Path to Learn BDD on Ruby On Rails?

RSpec specific; I keep these links for reference (might be advance for beginners). But just wanna share it with you. (Some of it probably already outdated but I think still worth a read)

Rspec Link Fest - links to other references

RSpec in Controllers:
Testing your Application Controller with rSpec

Testing Controllers with rspec

Using Rspec on Controllers

RSpec in Models:
stub_model by Dave Chelimsky

Do we really need Controller and View tests? - some discussion

RSpec in Views:

RSpec testing views for escaped HTML

Rspec Stories (now Cucumber):

Understanding RSpec Stories - a Tutorial

Rspec on Windows:

RSpec, autotest and Snarl on Windows - dunno if this still relevant

p/s: Some are from 2007, I'm not sure if the stuffs are outdated or not, but these are the some of my references used to learn RSpec. Hope it helps

how can I can get good (or just ok) at BDD for Rails using RSpec?

As a beginner I learned (still learning) rspec by looking at other people's rspecs. Find a large project(eg. https://github.com/diaspora/diaspora) with and see how other people approached the rspec .

To find everything at a single place, below given link is quite helpful :

http://kerryb.github.com/iprug-rspec-presentation/

Cucumber and scaffolding

The scaffold serves as a good starting point whilst you are getting to know the TDD/BDD cycle. I found that when I first read the RSpec Book that it was confusing with what to use when and why ! Then along came the Cucumber Book which helps a little more since it takes you through the steps a little slower (although the book is still in beta, but a fantastic resource).

One other great resource that helped was a blog post by Sarah Mei called "Outside-in BDD: How?". What is nice about this post is the discussion of the flow and style that you use as a developer. This was useful since it puts some context around the style of doing BDD and not just a re-hash of a basic example.

Of course there is the usual debate that 'real programmers' shouldn't use the scaffold. That may be true for a large scale, production application. The reality is that we all have to learn and start somewhere and Rails is no exception; it's a large framework and once you add in RSpec + Cucumber the breadth and depth grows very fast.

Real example on how to do TDD/BDD with Rspec and Cucumber

I highly recommend you the Rspec book which is exactly what you are looking for :

It explains how to use Rspec and Cucumber together with a simple 2 loops process : The outer big loop is a Test - Code - Refactor process you do with cucumber and each step is made of multiple iteration of a Test - Code - Refactor process you do with Rspec.

That books explains at the same time how and when to use each of the two tools.

If you want a broader vision of TDD-BDD, I also suggest you the GOOS book which is more language/tool agnostic and more process oriented.

Ruby on Rails: Cucumber custom definitions for paths.rb

Sure,

Cucumber uses the steps in web_steps.rb to make the call to the mapping. It looks like:

When /^(?:|I )go to (.+)$/ do |page_name|
visit path_to(page_name)
end

Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
with_scope(selector) do
if page.respond_to? :should
page.should have_content(text)
else
assert page.has_content?(text)
end
end
end

So, I would write the following step that redirect to the standard web_steps ...

#step_definitions/my_steps.rb

When /^(?:|I )constantly visiting (.+)$/ do |page_name|
When %{I go to #{page_name}}
end

Then /^(?:|I )have to observe text "([^"]*)" do |text|
Then %{I should see "#{text}"}
end

Hope this helps.

How to learn/teach Gherkin for Cucumber

What I did with the business analysts in our company was to teach them the structure by giving them the keywords: Given, When, Then, And for Scenarios and In order to, As a and I want to for Features.

Then I gave them a simple example and told them to write down their own features as they thought they should be written. Surprisingly enough the structure was self explanatory and the features they wrote became a great start.

The only big problem was that they had contained to much logic in each scenario step. I solved that by iteratively asking "why?" which in most cases revealed the core functionality they were after and we re-wrote the scenarios accordantly.

By giving them the guidelines and letting them write the features themselves they got their hands dirty and were forced to think about what they wrote. Today they have a much better understanding and the "why?" iterations are not that common anymore.

Ofcourse you need to have the business analysts and the developers to work closely together and the features the analysts write should only act as a start. Remember that the Cucumber features are just a common language between the analysts and the developers. They still need to sit together often to be able to speak with each other :)

Book/Tutorial for TDD/BDD in ruby?

With the books mentioned above peepcode screencast on cucumber and rspec is also good.

Links
cucumber and rspec



Related Topics



Leave a reply



Submit