No prob. I know of at least one Ruby company that is using it, I don’t
know about any IronRuby users, but I hope there are some 
JD
From: [email protected]
[mailto:[email protected]] On Behalf Of Mohammad A.
Sent: Thursday, September 24, 2009 2:27 PM
To: [email protected]
Subject: Re: [Ironruby-core] Is there a But keyword in Cucumber?
Thanks JD!!
It never occurred to me that I can store the number in a @n_number
variable and use it later. Here is the version that is working
perfectly:
I will be interested to know if people are actually using Cucumber in
their companies to write acceptance tests.
Given /I have a negative number/ do
end
When “I pass the negative $n_number to the prime service” do |n_number|
@n_number = n_number.to_i
end
Then /the service should throw exception/ do
lambda
{@primeService.IsPrime(@n_number)}.shouldmailto:[email protected](@n_number)}.should
raise_error
end
On Thu, Sep 24, 2009 at 2:08 PM, Jim D.
<[email protected]mailto:[email protected]> wrote:
You are missing the lambda keyword. I would also just store the number
at that point, and perform the operation in the Then step.
When “I pass the negative $n_number to the prime service” do |n_number|
@n_number = n_number
end
Then /the service should throw exception/ do
lambda
{@primeService.IsPrime(@n_number.to_i)}.shouldmailto:[email protected](@n_number.to_i)}.should
raise_error
end
JD
From:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Mohammad A.
Sent: Thursday, September 24, 2009 1:58 PM
To: [email protected]mailto:[email protected]
Subject: Re: [Ironruby-core] Is there a But keyword in Cucumber?
I am having trouble in where to throw the exception. The exception will
be thrown in “When” and not “Then” as shown below:
Scenario Outline: Throw exception if the number is negative
Given I have a negative number
When I pass the negative <n_number> to the prime service
Then the service should throw exception
Steps:
Given /I have a negative number/ do
end
When “I pass the negative $n_number to the prime service” do |n_number|
lambda
{@primeService.IsPrime(n_number.to_i)}.shouldmailto:[email protected](n_number.to_i)}.should
raise_error
end
Then /the service should throw exception/ do
end
The above throws the following exception:
C:\Projects\ILoveIronRuby\ILoveIronRuby\testing>icucumber
features/primeservice.
feature --guess --no-color
odd number list for Hash (SyntaxError)
C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTE
D\Builtins\KernelOps.cs:1341:in `require’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/rb_support/r
b_language.rb:101:in `load_code_file’
custom_require.rb:30:in `require’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/rb_support/r
b_language.rb:46:in `step_definitions_for’
polyglot.rb:69:in `require’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/step_mother.
rb:118:in `load_code_file’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/step_mother.
rb:110:in `load_code_files’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/step_mother.
rb:109:in `load_code_files’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/cli/main.rb:
48:in `execute!’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/…/lib/cucumber/cli/main.rb:
23:in `execute’
C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTE
D\Extensions\IListOps.cs:810:in `each’
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.101/bin/cucumber:9
c:/ruby/bin/cucumber:19
C:\DevTools\IronRuby\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTE
D\Builtins\KernelOps.cs:1326:in `load’
C:\Projects\ILoveIronRuby\ILoveIronRuby\testing>
On Thu, Sep 24, 2009 at 1:37 PM, Jim D.
<[email protected]mailto:[email protected]> wrote:
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 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:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Mohammad A.
Sent: Thursday, September 24, 2009 1:30 PM
To: [email protected]mailto:[email protected]
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 to the prime service
Then the service should display 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 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 D.
<[email protected]mailto:[email protected]> 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:
[email protected]mailto:[email protected]
[mailto:[email protected]mailto:[email protected]]
On Behalf Of Mohammad A.
Sent: Thursday, September 24, 2009 1:07 PM
To: [email protected]mailto:[email protected]
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 to the prime service
Then the service should display 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 A.
MVP (Microsoft Valuable Professional)
www.highoncoding.comhttp://www.highoncoding.com
www.azamsharp.comhttp://www.azamsharp.com
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
–
Mohammad A.
MVP (Microsoft Valuable Professional)
www.highoncoding.comhttp://www.highoncoding.com
www.azamsharp.comhttp://www.azamsharp.com
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
–
Mohammad A.
MVP (Microsoft Valuable Professional)
www.highoncoding.comhttp://www.highoncoding.com
www.azamsharp.comhttp://www.azamsharp.com
Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
–
Mohammad A.
MVP (Microsoft Valuable Professional)
www.highoncoding.comhttp://www.highoncoding.com
www.azamsharp.comhttp://www.azamsharp.com