To check for an exception: you need to get it into the form lambda { expr 
}.should raise_error ErrorType where expr is your test expression, and 
ErrorType is the type of the error you expect. In this case, you might need to 
have the second feature read "When I pass the negative number <number> to the 
prime service" so that you can parse it differently and just store the number, 
then in the Then step for that negative number, you can do lambda { 
@primeService.IsPrime(number.to_i) }.should raise_error Exception

Does that help?
JD

From: ironruby-core-boun...@rubyforge.org 
[mailto:ironruby-core-boun...@rubyforge.org] On Behalf Of Mohammad Azam
Sent: Thursday, September 24, 2009 1:30 PM
To: ironruby-core@rubyforge.org
Subject: Re: [Ironruby-core] Is there a But keyword in Cucumber?

Actually I also thought of that and I did separated them in multiple scenarios. 
Now, I am having trouble writing the step.

Here is the feature file:


Feature: Prime Service

As a crazy person I need to know whether a number is prime or not

Scenario Outline: Find if the number if prime or not
Given I have a number
When I pass the <number> to the prime service
Then the service should display <result> indicating whether input is prime or 
not

Examples:

| number| result|
|  1  | false |
|  2  | true |
|  3  | true |
|  4  | false |

Scenario Outline: Throw exception if the number is negative
Given I have a negative number
When I pass the <number> to the prime service
Then the service should return false

Examples:

| number|
|  -1  |
|  -2  |
|  -3  |
|  -4  |


And here are the steps:

require 'rubygems'
require 'spec/expectations'

require File.expand_path("bin/Debug/BusinessObjects.dll")

include BusinessObjects

Before do

@primeService = PrimeService.new

end

Given /I have a number/ do

end

When "I pass the $number to the prime service" do |number|

@result = @primeService.IsPrime(number.to_i)

end

Then /the service should display (.*) indicating whether input is prime or not/ 
do |result|

@result.to_s.should == result

end

Given /I have a negative number/ do

end

When "I pass the $number to the prime service" do |number|

@result = @primeService.IsPrime(number.to_i)

end

Then /the service should return (.*)/ do |result|

@result.to_s.should == result

end


Also, not sure how to check for exception right now!




On Thu, Sep 24, 2009 at 1:10 PM, Jim Deville 
<jdevi...@microsoft.com<mailto:jdevi...@microsoft.com>> wrote:

You should probably split that into 2 scenarios. One for finding prime or not, 
and one for throwing if the number is negative.



There might be an else construct, but I would argue that if you need an 
else/but, then you have 2 behaviors in a single scenario.



JD



From: 
ironruby-core-boun...@rubyforge.org<mailto:ironruby-core-boun...@rubyforge.org> 
[mailto:ironruby-core-boun...@rubyforge.org<mailto:ironruby-core-boun...@rubyforge.org>]
 On Behalf Of Mohammad Azam
Sent: Thursday, September 24, 2009 1:07 PM
To: ironruby-core@rubyforge.org<mailto:ironruby-core@rubyforge.org>
Subject: [Ironruby-core] Is there a But keyword in Cucumber?



I am using Cucumber and now I need to use a But keyword (if there is any)



Scenario Outline: Find if the number if prime or not

Given I have a number

When I pass the <number> to the prime service

Then the service should display <result> indicating whether input is prime or 
not

But if the number is negative

Then the prime service should throw an exception



But it shows up as "Then" and not "But". Is there anything related to "But" in 
Cucumber.



--
Mohammad Azam
MVP (Microsoft Valuable Professional)
www.highoncoding.com<http://www.highoncoding.com>
www.azamsharp.com<http://www.azamsharp.com>

_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org<mailto:Ironruby-core@rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core



--
Mohammad Azam
MVP (Microsoft Valuable Professional)
www.highoncoding.com<http://www.highoncoding.com>
www.azamsharp.com<http://www.azamsharp.com>
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to