Cucumber: Steps to insert record into the databases

735 views
Skip to first unread message

smita

unread,
May 27, 2009, 5:58:33 AM5/27/09
to Cukes
Hi,

We run the feature created for a form to identify the fields and also
to
add data into the respective fields.

But while running the cucumber features, all the scenario and steps
are
getting passed but the record is not getting inserted into the
application / the database.

We have also wrote the feature as:

Feature: Adding a user
In order to add a user to the organization
As a administrator
I want to create and add new user

Scenario: Create User
Given that I have no users
And I am on the "List of users"
When I follow "New User"
And I fill in "First Name" with "Rebecca"
And I fill in "Second Name" with "Martin"
And I fill in "Title" with "Miss"
And I fill in "Email" with "rebecc...@me.com"
And I fill in "Telephone" with "01617867645"
And I fill in "Mobile" with "01777867645"
And I fill in "Fax" with "01617867640Î"
And I fill in "Address Line 1" with "58"
And I fill in "Address Line 2" with "West Tree rd"
And I fill in "Address Line 3" with "Stockport"
And I fill in "County" with "Cheshire"
And I fill in "Country" with "United Kingdom"
And I fill in "Zip Code" with "sk8 4ty"
And I press "Create"
Then I should have 1 user


And steps as:

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

Given /^that I have no users$/ do
User.delete_all
end

If somebody could help us out, how to execute the steps so that the
data
gets inserted into the database.

Smita.

Ben Lovell

unread,
May 27, 2009, 7:48:38 AM5/27/09
to cu...@googlegroups.com
Can you provide some background? i.e. Are you using rails? See here: http://wiki.github.com/aslakhellesoy/cucumber/get-in-touch

If you're expecting to see data in your database after the scenarios have run then you may be out of luck. This is generally blown away after each scenario. 

If your "Then I should have 1 user" step is passing then something has been inserted. You might want to alter this step however to something more specific i.e. "Then a user named "Miss Rebecca Martin" should exist" with matching step definition to check for the exact inserted user. This will ensure you are seeing the correct results and not leaking state from a previous scenario.

Regards,
Ben

Mike Doel

unread,
May 27, 2009, 7:51:55 AM5/27/09
to cu...@googlegroups.com
On May 27, 2009, at 5:58 AM, smita wrote:

> Scenario: Create User
> Given that I have no users
> And I am on the "List of users"
> When I follow "New User"
> And I fill in "First Name" with "Rebecca"
> And I fill in "Second Name" with "Martin"
> And I fill in "Title" with "Miss"
> And I fill in "Email" with "rebecc...@me.com"
> And I fill in "Telephone" with "01617867645"
> And I fill in "Mobile" with "01777867645"
> And I fill in "Fax" with "01617867640Î"
> And I fill in "Address Line 1" with "58"
> And I fill in "Address Line 2" with "West Tree rd"
> And I fill in "Address Line 3" with "Stockport"
> And I fill in "County" with "Cheshire"
> And I fill in "Country" with "United Kingdom"
> And I fill in "Zip Code" with "sk8 4ty"
> And I press "Create"
> Then I should have 1 user


Is it possible that your User model is failing validation when you try
to create it?

Your log file may help show the underlying problem.

Consider putting a call to debugger in your UsersController's create
method so you can examine the state and see why the record is not
getting called.

Mike

Matt Wynne

unread,
May 27, 2009, 8:35:50 AM5/27/09
to cu...@googlegroups.com

Also consider using create! save! etc everywhere you can so things
don't fail in silent and creepy ways.

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com

Reply all
Reply to author
Forward
0 new messages