(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
- Navigate to your project's Github page and click Issues then New Issue.
- Name the ticket using something. Try to use the same name you'd use for an RSpec test.
- 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 |
- Pull the
master
branch. - Spin off a new branch using the ticket name and references the issue number (from the previous step).
git checkout -b <ISSUE_NUMBER>_<TITLE>
- Commit your branch
git commit -m 'initial commit'
Bad | Good |
---|---|
git checkout -b logout_shit |
git checkout -b 049_ability_for_user_to_logout |
- **Ask your colleague to 'Thumbs Up' the proposal on github.
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
- 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
.
- Navigate to
spec/features/
in your IDE. - Create a new directory for this category (if it doesn't already exist). For example, if you're working on authentication,
spec/features/authentication
. - 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
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