Skip to content

Instantly share code, notes, and snippets.

@oldfartdeveloper
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldfartdeveloper/bc4ee2ce8978e933424e to your computer and use it in GitHub Desktop.
Save oldfartdeveloper/bc4ee2ce8978e933424e to your computer and use it in GitHub Desktop.
Declarative implementation of Imperative Cucumber-like RSpec

Here's the original:

require 'spec_helper'

feature "A user signing up for a beta invitation" do
  scenario "with valid parameters" do
    visit '/'
    fill_in "Name", with: "John Doe"
    fill_in "Email", with: "jdoe@example.com"
    click_button "Join Now"

    expect(page).to have_content('Thanks for signing up!')
    beta_request = BetaRequest.last
    expect(beta_request.name).to eq 'John Doe'
    expect(beta_request.email).to eq 'jdoe@example.com'
  end
end

Yes, the above is very imperative. It's also in RSpec, so the first thing is the author is already preoccupied w/ implementation instead of what it needs to accomplish. No tables can be used (at least that the stakeholder will want to read), so much is already lost.

Also, I have no justification as to why we're creating the beta invitaions anyways.

As a stakeholder, here's what I would be interested in (as far as I can see in the RSpec):

Feature: Signing up for a beta-invitation
  As a director of engineering
  I want potential users to test and evaluate a new unreleased feature
  So that I can get early feedback on whether the users believe this would be valuable and whether it works.
  
  Scenario: Sign up
    When a potential user visits the site
    Then she sees that she can ask to participate in a beta evaluation.
    When she signs up to apply for a beta evaluation with
      | her email |
      | a password |
    Then she receives an email thanking her for signing up for the beta
    And she is able to log into our site in order to participate in the beta.
    
  Scenario: Participate in Beta
    # Here we "discover" whether the beta is to be downloaded or she has access to a beta site or...

That's what I believe my stakeholder wants, and I would go over this with him and verify (and modify appropriately if necessary).

Note that the first thing I notice is we're missing a step in which she has to click a link in the email we send her to verify that she is really the one that wants to sign up (and that we're not spamming her).

In RSpec, you are too distracted by syntax to accomplish this high level of thinking and requirements. As a result you are likely to spend a lot of time implementing what the stakeholder doesn't want and missing what they really do want.

Oh, and if I want to use this as the basis for a test, I can easily do that because of the power of Ruby.

BUT...

What if I don't care about the stakeholder; I'm just trying to implement a test?

In that case, use Cucumber if you like the way it specifies the problem at a high level; else use some other test tool of your choice. Lots of personal preference allowed here. ;-)

My 2 cents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment