Testing controllers using cucumber

Hello,
Is there any way to test controllers using cucumber.
I was doing it with rspec but since cucumber’s description is good how
can i proceed testing it with cucumber?
For e.g.
I have a scenario of user creation like
Feature: User Scenarios

Scenario: Successfull creation of user
Given a new user
When the user fill all the mandatory details
Then that user should get created
And success message should get displayed and email should be sent
for activation

In step definition:
Given /^a new user$/ do
end

When /^the user fill all the mandatory details$/ do
end

When /^that user should get created$/ do
end

Then /^success message should get displayed and email should be sent for
activation$/ do
end

In this how i need to call the users controller and in that create
method.
Also i searched in the net but didn’t found any examples for cucumber
testing controllers.
Please suggest

On 29 Jan 2010, at 11:53, Amit K. wrote:

Hello,
Is there any way to test controllers using cucumber.
I was doing it with rspec but since cucumber’s description is good how
can i proceed testing it with cucumber?

Hi Amit. There’s a Cucumber specific mailing list at
http://groups.google.com/group/cukes?pli=1, which is a better place to
ask Cucumbetr questions.

With Cucumber, you don’t tend to test controllers directly, instead
you’re testing the whole app, much like Rails’ own Integration Tests.

For e.g.
I have a scenario of user creation like
Feature: User Scenarios

Scenario: Successfull creation of user
Given a new user
When the user fill all the mandatory details
Then that user should get created
And success message should get displayed and email should be sent
for activation

So, your example might be implemented like this:

Given /^I’m on the new user page$/ do
visit new_user_path
end

When /^I fill all the mandatory details$/ do
fill_in(“name”, :with =>“Joe”)
end

Then /^that user should get created$/ do
User.find_by_name(“Joe”).should_not be_nil
end

In this how i need to call the users controller and in that create
method.
Also i searched in the net but didn’t found any examples for cucumber
testing controllers.

There are lots of examples on the Cucumber site http://cukes.info/

HTH

Matt


Matt P. | Design & Code
| http://www.reprocessed.org/

Oh ok.
From your code it seems that we are checking the whole app as you
mentioned.
I have tested controllers using rspec.
So i am not getting which is better to use.
Since with Rspec we test the objects and here using cucumber(good for
writing scenarios and understanding)we are testing the GUI part(using
webrat).
So which is good to use and more effective

On Feb 1, 2010, at 1:30 AM, Amit K. wrote:

Oh ok.

From your code it seems that we are checking the whole app as you
mentioned.
I have tested controllers using rspec.
So i am not getting which is better to use.
Since with Rspec we test the objects and here using cucumber(good for
writing scenarios and understanding)we are testing the GUI part(using
webrat).
So which is good to use and more effective

From my perspective, and this is just opinion, it depends on how granular you want your test and how fast it has to run. If you want to test the whole stack, then Cuke is great and it will exercise the controller. However, it does it more in the way a user might and can miss some edge cases. However, if you have a set of very specific behaviors like how a controller should respond to various mime types or what exceptions might be raised in certain circumstances, it might be better done using rSpec. Also, typically, a given rSpec test is faster because it doesn’t have to load the whole Rails stack and you can mock or stub irrelevant parts.

Just my $.02.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs