More Examples


#1

I have a feature spec that looks like this:

Scenario: The entity common name should be normalized
Given 1 valid entity
And I am on the edit entity page
When I fill in “Common Name” with " ANYThing WronG wITh tHiS? "
And I press “Update”
Then I should see an update success confirmation
And I should see “Anything Wrong With This?”

More Examples:
| initial | after |
| “ALL CAPS” | “All Caps” |
| " Squeeze leading space" | “Squeeze Leading Space” |
| " Compact Internal space" | “Compact Internal Space” |

The first bit passes but for the life of me I cannot figure out what I
am
supposed to do to get the More Examples to work.

I will grant from the outset that testing a string normalization feature
might be done somewhere/someway else but I am learning RSpec/Cucumber
and
for now am taking that single minded approach to testing. On the other
hand, I am not adverse to suggestions on how this might be best handled.

Guidance Please?


*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:removed_email_address@domain.invalid
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3


#2

On 17 Nov 2008, at 20:33, James B. Byrne wrote:

More Examples:
| initial | after |
| “ALL CAPS” | “All Caps” |
| " Squeeze leading space" | “Squeeze Leading Space” |
| " Compact Internal space" | “Compact Internal Space” |

The first bit passes but for the life of me I cannot figure out what
I am
supposed to do to get the More Examples to work.

You’re probably not specifying all the variables you need to.

Until we get the Scenario Outlines feature[1], you have to put a
column in your More Examples table for every capture group in the
regular expressions in your matchers.

The way I usually do this is look at the output in the console from
Cucumber and see where the bits are underlined, and make a column for
each of them.

That can feel a bit silly when most of them don’t vary during your
extra examples, but that’s why we need the Scenario Outline feature.
For the time being it’s still great that we can do this at all.

cheers,
Matt

[1]http://rspec.lighthouseapp.com/projects/16211/tickets/57-scenario-templates-to-allow-for-terse-scenario-tables


#3

Matt W. wrote:

On 17 Nov 2008, at 20:33, James B. Byrne wrote:

More Examples:
| initial | after |
| “ALL CAPS” | “All Caps” |
| " Squeeze leading space" | “Squeeze Leading Space” |
| " Compact Internal space" | “Compact Internal Space” |

The first bit passes but for the life of me I cannot figure out what
I am
supposed to do to get the More Examples to work.

You’re probably not specifying all the variables you need to.

Until we get the Scenario Outlines feature[1], you have to put a
column in your More Examples table for every capture group in the
regular expressions in your matchers.

I took out the check for the success confirmation to simplify things.

I added columns for the field and the action.

The remaining matcher is in webrat_steps:

Then /^I should see “(.*)”$/ do |text|
response.body.should =~ /#{text}/m
end

This is what I see in the console:

Scenario: The entity common name should be normalized

features/manage_entities.feature:41

Given 1 valid entity 

features/step_definitions/entity_steps.rb:25

And I am on the edit entity page 

features/step_definitions/entity_steps.rb:54

When I fill in "Common Name" with "  ANYThing   WronG wITh tHiS? " 

features/step_definitions/webrat_steps.rb:12

And I press "Update" 

features/step_definitions/webrat_steps.rb:4

Then I should see "Anything Wrong With This?" 

features/step_definitions/webrat_steps.rb:36

|field        |input                        |action  |display 

|
|“Common Name”|“ALL CAPS” |“Update”|“All Caps”
|/usr/lib/ruby/gems/1.8/gems/cucumber-0.1.9/bin/…/lib/cucumber/formatters/pretty_formatter.rb:212:in
`print_row’: You have a nil object when you didn’t expect it!
(NoMethodError)

do I misunderstand what you tried to tell me?


#4

Pau C. wrote:

James B. wrote:

This is what I see in the console:
The underlining didn’t come through in you post, so that doesn’t help
us.

If you post your step matchers, then we can tell you what your columns
need to be. Essentially, for every (.*) in your step matchers, you need
a column. And they have to be in the order they are in the story.

Thank you. I was diverted from dealing with this for a bit but have
since resolved the matter using your advice.


#5

James B. wrote:

This is what I see in the console:
The underlining didn’t come through in you post, so that doesn’t help
us.

If you post your step matchers, then we can tell you what your columns
need to be. Essentially, for every (.*) in your step matchers, you need
a column. And they have to be in the order they are in the story.

Here is an example:

Scenario: The entity common name should be normalized
Given I am on the edit entity page
When I fill in “Common Name” with " ANYThing WronG wITh tHiS? "
And I press “Update”
Then I should see “Anything Wrong With This?”

More Examples:
| page | field | initial
| Button | after |
| the edit entity page | Common Name | “ALL CAPS”
| Update | “All Caps” |
| the edit entity page | Common Name | " Squeeze leading space"
| Update | “Squeeze Leading Space” |
| the edit entity page | Common Name | " Compact Internal space"
| Update | “Compact Internal Space” |

Given /^I am on the “(.)"$/ do |page|
When /^I fill in "(.
)” with “(.)"$/ do |field, value|
When /^I press "(.
)”$/ do |button|
Then /^I should see “(.*)”$/ do |text|

You also need to be careful about ". I’m not sure if the way you are
using those will include " in the string.