0

I have started writing the following feature within an app designed to manage a cleaning business:

Feature: Creating a new cleaner 
  In order to allow Franchisees to allocate cleaners to jobs they need to be uploaded to the system

  Background:
    Given I am currently logged in to my account
    And I have navigated to the "Cleaners" page
    And I want to add a new cleaner to the database

  Scenario: Add a new cleaner to the system
    Given I have brought up the "Add Cleaner" form
    Then I will need to complete the fields within the following form:

      | first_name     | 
      | last_name      |
      | email          |
      | date_of_birth  |
      | postcode       |
      | mobile         |
      | other_phone    |
      | address_1      |
      | address_2      |
      | work_radius    |
      | **days_available** |
      | notes          |

    When I have entered valid data
    Then I can save to the database
    And I will have added a new cleaner to the system

In addition to welcoming comments on the way I have written the scenarios etc, my main problem is that I can't work out how to simulate selecting from a pre-populated field:

Populating the days_available should allow the franchisee to choose which days of the week, and which hours within those days, that a cleaner will be available for work. This obviously makes it possible to return queries which only show available cleaners for any given day/time of day.

Really hope someone can explain how this is done?

Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46
user3735114
  • 41
  • 1
  • 6

1 Answers1

0

Just a quick comment on the structure of your feature file ... the 'Then' step in your feature should be asserting that something has or has not been done successfully.

Given I have logged into the site
When I add a new Cleaner to the site
Then I should see that the Cleaner has been added successfully

I would recommend using language that can be easily understood. Your scenario doesn't need to be instructions on how to use the site. Excessive navigational steps can make you lose track of the purpose of the scenario.

To answer your question regarding days_available accurately, would require some knowledge of how the site is structured and how the days_available are entered. Are you choosing from select lists, filling in form fields, etc? Also, since you are testing, you could consider setting the data from within your step (ie. hash, array) instead of passing all of the info in via a table.

Just some food for thought. Cheers.

Based on your updated post, I would suggest the following:

The step And I want to add a new cleaner to the database doesn't seem like an actionable step and could be removed. Same for the step When I have entered valid data. If you handle filling out the form in the previous step, you have already entered valid data.

If you need to multiple available days, I would consider making it its own step

And(/^the cleaner is available from (.*?) to (.*?) on (.*?)$/) do |start_time, end_time, day|
  #fill in start time
  #fill in end time
  #select day
end

Background:
    Given I am currently logged in to my account
    And I have navigated to the "Cleaners" page

Scenario:
    And I bring up the "Add Cleaners" form
    And I complete the form with
      | first name | Bob   |
      | last name  | Smith |
      ...
    And the cleaner is available from 0600 to 1800 on W
    When I submit the Add Cleaners form
    Then I should see the new cleaner has been successfully added
Jarod Adair
  • 419
  • 2
  • 8
  • Thanks Jarod, really useful advice, thanks. Re days_available, the functionality I'm looking for would allow the user to pick days upon which a cleaner was willing to work from a drop down selection [M, T, W, T, F, S, S], and then specify the exact times the cleaner could work for each one of these days So for example, due to other work commitments, a cleaner might only be able to work on Mondays from 09.00 - 13.00 and Wednesdays 14.00 - 17.00. Selection of days and times would be made from drop down lists. – user3735114 Sep 03 '14 at 20:52
  • Again, really helped me out thanks. Just to clarify, when you say "If you handle filling out the form in the previous step" you mean that I should define the functionality of the date/time availability field in its own separate scenario? – user3735114 Sep 04 '14 at 08:07
  • If you handle the date/time in its own step, this would give you the ability to re-use the step multiple times within the same scenario. so that you could add a single or multiple available days on the same form. – Jarod Adair Sep 04 '14 at 11:55