Links to My Posts

Labels

Blogumulus by Roy Tanck and Amanda Fazani
free counters

How many in online

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

I think you get a good knowledge from my past posts. OK now lets see to test adding new products. Before that lets see what is happening when new product is adding.

1)He should be in the List of Product page as follows.



2)Now what he do . He clicks the New Products Link. Now he can see the following page.



3)Now he fill the fields as
Title = Ruby On Rails
Description = Model View Control Architecture
Image url= ror.jpg
Price=22

4)Now he clicks Create button and he can see following page.



5)He can see “Product was successfully created” and he can see “Ruby On Rails”, “Model View Control Architecture”, “ror.jpg” and “22”.

6)Now lets see how we can test it using Cucumber Testing.

7)Create a new file called “create_product.feature” in product/features folder and paste this scenario.

Scenario: Create Valid Product

Given I have no products

And I am on the list of Products

When I follow "New Product"

And I fill in "Title" with "Ruby On Rails"

And I fill in "Description" with "Model View Control Architecture"

And I fill in "Image Url" with "ror.jpg"

And I fill in "Price" with "22"

And I press "Create"

Then I should see "Product was successfully created."

And I should see "Ruby On Rails"

And I should see "Model View Control Architecture"

And I should see "ror.jpg"

And I should see "22"

And I should have 1 product



8)This scenario check all the steps which I shown above. Check them your self. Now go to the "Product_steps.rb"page in features/step_definition folder and paste following codes.

Given /^I have no products$/ do
Product.delete_all
end

Then /^I should have ([0-9]+) product$/ do |count|
Product.count.should == count.to_i
end


9)Now we have 2 feature files as list_of_product.feature and create_product.feature
10)when we run cucumber features all the features files are run. If we want to run only one file we can run cucumber features/(file name)
eg:- cucumber features/ create_product.feature

11)Run the cucumber features/ create_product.feature and you can see following.



12)It says all the steps are passed. Now you can test to verify actually this scenario works with the code for that we can change some codes in scenario and check running cucumber features.

13)I give it to you as a home work. Check what happening when the scenario change and run cucumber features.

14)Lets see in the next post how this scenario can be written in simple way.

1 comments:

ජීවන්ත තාරක (Jeewantha Tharaka Kodikara) said...

Hi all,
I think this posts are very helpful to you all. So I need your valuable comments on this posts. If not fill the answers to the question which i asked in the right hand side below to my profile.
Thanks
Best regards,
Jeewantha.