Skip to content

Instantly share code, notes, and snippets.

@patrickclery
Last active April 30, 2020 13:34
Show Gist options
  • Save patrickclery/cee1d113e2d86b59b45b1ed04c696c9c to your computer and use it in GitHub Desktop.
Save patrickclery/cee1d113e2d86b59b45b1ed04c696c9c to your computer and use it in GitHub Desktop.
Behavior-Driven Development Workflow on Github

TL;DR

(Everything you need to know about Behavior Driven Development on Github can be summed up in this snippet of code.)

RSpec.describe Ticket, type: :model do

  it { should validate_presence_of :issue }
  it { should validate_presence_of :pseudo_code }
  it { should be_designated_a(Priority) }
  it { should be_assigned_to_a(Coder) }
  it { should have_a(:branch_name).that_matches(/${ISSUE_NUMBER}_${name_with_underscores}/) }
 
end

Open a new ticket.

  1. Navigate to your project's Github page and click Issues then New Issue.
  2. Name the ticket using something. Try to use the same name you'd use for an RSpec test.
  3. The ticket will automatically be labeled Proposal and move under "Proposals" on the Project Page.
Bad Good
Logout feature Authenticated user can logout by clicking the logout button in the nav bar

Checkout a new branch using the feature name.

  1. Pull the master branch.
  2. Spin off a new branch using the ticket name and references the issue number (from the previous step). git checkout -b <ISSUE_NUMBER>_<TITLE>
  3. Commit your branch git commit -m 'initial commit'
Bad Good
git checkout -b logout_shit git checkout -b 049_ability_for_user_to_logout

Review

1. Set a priority for the ticket.

2. Assign the ticket.

  • **Ask your colleague to 'Thumbs Up' the proposal on github.

Translate your tests into tasks.

For each test you made in your spec, add a checkbox to your Issue using the exact same phrase (for consistency).

This:

it 'can log a user out' do
  # ...
end

Becomes this:

  • can log a user out

Kick off continuous integration testing to run your tests.

  • Navigate to your project's Pull Requests and create a New Pull Request.
  • Choose the branch you created, i.e: 049_ability_for_user_to_logout.

Paste the RSpec template into spec/features/your_spec.rb

  1. Navigate to spec/features/ in your IDE.
  2. Create a new directory for this category (if it doesn't already exist). For example, if you're working on authentication, spec/features/authentication.
  3. Paste the RSpec template from the Issue Page into spec/features/authentication/user_can_logout_spec.rb

ISSUE_TEMPLATE.md:

RSpec.feature 'Ability for a user to log themselves out', type: :feature do

  context 'User is already logged in' do
  
    include_context 'default'

    before(:each) do
      # pretend_to_log_the_user_in
    end

    it 'can log a user out' do
      pending
      
      click 'Logout'
      expect(page).to have_content 'You have successfully been logged out.'
    end

  end

end

Replace the code with your own code

Using pseudo-code (or Capybara) write the RSpec using long function names, nothing fancy. Write valid code, but don't write anything that requires Rails to run.

BAD (actual code):

require 'some_cool_coding_library_that_should_never_be_here'

SomeModel.find(...) # Requires rails to run 

GOOD (pseudo-code)

context 'the user is already logged in' do
  scenario 'user can logout' do
    # Put this here, now we EXPECT the test to fail so we write "conversationally"
    pending 
    
    expect_that_the_user_would_click_on_logout
    expect_the_user_is_prompted_are_you_sure
    expect_the_user_confirms_logout
    expect_the_user_is_redirected_to_the_logout_page
    
    # Here we can use some real code because it reads naturally
    expect(page).to have_content('You have been successfully logged out')
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment