Wednesday, September 30, 2009

Ruby cucumber Part3

Hi all,
I am very sorry for the delay of my 3rd post because these days are i am very busy. i hope to do it as soon as possible. Most probably today afternoon i can do it.
Cheers,
jeewantha.

Sunday, September 27, 2009

Cucumber and Ruby on Rails (Part 2) My learning materials

Create a project and do testing using cucumber.

Project name “product”

Requirement

  1. The user can see the available products.

When the user come to the page he should be able to see all the available products with description like

Title: Ruby on Rails

Description: Model, view, controller architecture

Image Url: ror.jpg

Price: 21

  1. He should be able to add new products.

  2. He should be able to show the products.

  3. He should be able to edit products.

  4. He should be able to validate products details when adding new products.

Error massages should be display when there is a wrong with adding data like

Price should be number

Title cant be blank etc.

  1. When Edit product the validation also should be done.

  2. He should be able to navigate any places by clicking links.

  3. He should be able to delete products.

Product table contents

Title = String

Description = String

Image Url = String

Price = Decimal



Lets start developing the project.

  1. Install cucumber

sudo gem1.8 install cucumber

  1. The plugins’ dependencies must be installed separately:

gem install term-ansicolor treetop diff-lcs nokogiri

  1. Lets start developing our project

Open a terminal then type

rails -d mysql product

cd product

rake db:create:all

rake db:migrate

  1. Now lets try to create cucumber

ruby script/generate cucumber

  1. Then run

Cucumber features

  1. Then u can see as follows







  1. Now you are ready to work with cucumber

  2. lets see that in next post.





Saturday, September 26, 2009

Cucumber and Ruby on Rails (Part 1)



I write this post to exchange my experienced with you about Cucumber and ruby and rails.

What is cucumber?
Actually when i heard this word i get a funny and i get a picture as follows.

After that i searched web and i try to find tutorials for learning this myself. when i was finding about cucumber i got idea about as follows.


After that i started finding and do various type of tutorials and try to get basics of cucumber. But it was very difficult to me learn this because there are not much tutorials for that i found 2 tutorials and by refering them i got basic idea and i think to share my knowledge with others so that is why this kind of blog post is come out. I think this will for the begginers to get an idea.

Now lets see what is the cucumber in ruby on rais and in other post how to start to test a project using cucumber.

Cucumber (Behavioral Driven Development ) is used for testing the behavior of a code. the programmers says that cucumber is used for accepting testing. Any way this is used for behaviral testing.

Reads plain texts….
Texts are written as scenarios
Scenarios interact with the code
Check the Codes are correct

Cucumber 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.

Lets see the simple senario and discuss about it.

Scenario: Listing & showing products
Given I have products titled Java, description Platform Independent, Image url java.jpg, Price 20
When I go to the list of Products
Then I should see "Java"
And I should see "Platform Independent"
And I should see "java.jpg"
And I should see "20"

As u can see the the senario is describe in palain text. here the Given, When, Then and And are the key words which is used by the cucumber. how the cucumber work with this type of plain text for that it uses the regular expressions. See the folowing regular expression (Don't wory that much about that we'll see them leter in detail)

Given /^I have products titled (.+), description (.+), Image url (.+), Price (.+)$/ do
|title,description,image_url,price|
Product.create!(:title => title, :description => description, :image_url => image_url, :price => price)
end

This describes the first step of the above senario. we do not much trouble with regular expressions. Becuse when we generate cucumber we get predefine regular expressions in webrat_steps.rb file.

Now I think u have basic idea about cucumber. In next posts lets see step by step to create a project and testing project using cucumber.

Thursday, September 24, 2009

Working with Ruby on Rails Cucumber From the Beginning(Part I)


Create a project and do testing using cucumber.

Project name “product”


Requirement

  1. The user can see the available products.

When the user come to the page he should be able to see all the available products with description like

Title: Ruby on Rails

Description: Model, view, controller architecture

Image Url: ror.jpg

Price: 21

  1. He should be able to add new products.

  2. He should be able to show the products.

  3. He should be able to edit products.

  4. He should be able to validate products details when adding new products.

Error massages should be display when there is a wrong with adding data like

Price should be number

Title cant be blank etc.


  1. When Edit product the validation also should be done.

  2. He should be able to navigate any places by clicking links.

  3. He should be able to delete products.

Product table contents

Title = String

Description = String

Image Url = String

Price = Decimal


Lets start developing the project.


  1. Install cucumber

sudo gem1.8 install cucumber


  1. The plugins’ dependencies must be installed separately:

gem install term-ansicolor treetop diff-lcs nokogiri



  1. Lets start developing our project

Open a terminal then type

rails -d mysql product

cd product

rake db:create:all

rake db:migrate




  1. Now lets try to create cucumber

ruby script/generate cucumber


  1. Then run

Rake Features Or Cucumber features


  1. Then u can see as follows



  1. Now you are ready to work with cucumber

  2. lets see that in next post.