Forum: RSpec Learning Cucumber

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2008-11-13 18:53
(Received via mailing list)
Here is the scenario:

  Scenario: Create a new entity row
    Given I am on the new entity page
    When I fill in a textbox labelled "Common Name" with "My New Entity"
    And I fill in a textbox labelled "Full Legal Name:" with "My New
Enitity is a CORP"
    And I select from a listbox labelled "Legal Form:" the value "CORP"
    And I press "Create"
    Then I should see "Entity was successfully created."

Now, the suggestions that cucumber makes about missing step definitions
are very useful, but I am not yet at the point where I understand enough
of this to proceed. For the moment I need to sort out the relationship
of
cucumber with webrat.

In the case above, what I see when I run rake features is this:

Scenario: Create a new entity row   # features/manage_entities.feature:7
  Given I am on the new entity page # features/steps/entity_steps.rb:1
  When I fill in a textbox labelled \
    "Common Name" with "My New Entity" #
features/steps/entity_steps.rb:5
    And I fill in a textbox labelled \
      "Full Legal Name:" with "My New Enitity is a CORP"  \
      # features/steps/entity_steps.rb:8
    And I select from a listbox labelled \
      "Legal Form:" the value "CORP"  #
features/steps/entity_steps.rb:11
    And I press "Create"              #
features/steps/common_webrat.rb:4
  Then I should see \
    "Entity was successfully created." #
features/steps/common_webrat.rb:36

expected: /Entity was successfully created./m,
           got: "<!-- application.html.erb -->\r\n<!DOCTYPE html PUBLIC
\


So, evidently I need some other specification to check the validity of
the
action with respect to the web page displayed.  Can some one give me a
hint as to what "I should see "X" should actually say?  Should this be a
regex?  In other worlds should the outcome be specified as:

   Then I should see "*Entity was successfully created*"


Unfortunately, I have many, many more questions, but I will try to feed
them in slowly.

Regards,

--
***          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
James B. (Guest)
on 2008-11-13 19:06
(Received via mailing list)
On Thu, November 13, 2008 11:51, James B. Byrne wrote:

> So, evidently I need some other specification to check the validity of the
> action with respect to the web page displayed.  Can some one give me a
> hint as to what "I should see "X" should actually say?  Should this be a
> regex?  In other worlds should the outcome be specified as:
>
>    Then I should see "*Entity was successfully created*"
>
>

Actually, I have discovered that what I need to do is to create some
steps
to move the data passed by the When clauses into the form variables and
thus get the expected result instead of an error.


--
***          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
Andrew P. (Guest)
on 2008-11-14 08:55
(Received via mailing list)
What you're doing here is writing imperative features. Writing
declarative features might be a better alternative. Instead of

 Given I am on the new entity page
   When I fill in a textbox labelled "Common Name" with "My New Entity"
   And I fill in a textbox labelled "Full Legal Name:" with "My New
Enitity is a CORP"
   And I select from a listbox labelled "Legal Form:" the value "CORP"
   And I press "Create"
   Then I should see "Entity was successfully created."

You could consider

Given I am on the new entity page
 When I correctly fill in the new entity form
 Then I should see a confirmation

Then the feature has much less technical stuff in it that

1) Hide the intent
2) Make the story brittle to cosmetic changes, in particular to small
rewordings of error messages and confirmations

A side effect of this is you need much less regex magic to match your
expressions.

HTH

Andrew


2008/11/13 James B. Byrne <removed_email_address@domain.invalid>:
James B. (Guest)
on 2008-11-14 21:04
Andrew P. wrote:
> What you're doing here is writing imperative features. Writing
> declarative features might be a better alternative. Instead of
...
>
> Given I am on the new entity page
>  When I correctly fill in the new entity form
>  Then I should see a confirmation
>
> Then the feature has much less technical stuff in it that
>
> 1) Hide the intent
> 2) Make the story brittle to cosmetic changes, in particular to small
> rewordings of error messages and confirmations
>
> A side effect of this is you need much less regex magic to match your
> expressions.
>

This advice does help. Thank you.

Is there a way to mix webrat and hard coded steps?  In other words, if I
have this in my steps file.

Given /I am on the new entity page/ do
  visits "/entities/new"
end

When /I fill out the form correctly/ do
  fills_in("Common Name", :with => "My Common Name")
  fills_in("Legal Name", :with => "My Legal Name")
  Entity.entity_legal_name = "CORP" # does not work
end

Is this possible?

How do I set the attribute "entity_legal_form" to "CORP" for that
entity?  I cannot figure out how to reference that entity instance.
Andrew P. (Guest)
on 2008-11-15 03:35
(Received via mailing list)
Generally you can do whatever you want in step as its a ruby file. The
thing to do is use a debugger statement to stop in the step (make sure
there is a line after debugger) and then explore.

In your step the Entity you are referring to is probably a class not a
variable

HTH

Andrew

2008/11/14 James B. <removed_email_address@domain.invalid>:
This topic is locked and can not be replied to.